From 838acc40bb7c23749d3ea8e48db3e81efaa68c29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Bokvad=20Engar=C3=A5s?= Date: Mon, 2 Oct 2023 15:08:39 +0200 Subject: [PATCH 1/4] refactor project --- src/branchprotection/BranchProtectionService.ts | 1 + src/cydigconfig.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/branchprotection/BranchProtectionService.ts b/src/branchprotection/BranchProtectionService.ts index ffe9edc4..8ef632c9 100644 --- a/src/branchprotection/BranchProtectionService.ts +++ b/src/branchprotection/BranchProtectionService.ts @@ -16,6 +16,7 @@ export class BranchProtectionService { branch: 'main', }) .then((response: any) => { + console.log('Response', response); console.log( 'Branch protection is enabled, number of reviewers are:', response.data.required_pull_request_reviews?.['required_approving_review_count'] diff --git a/src/cydigconfig.json b/src/cydigconfig.json index d72acfc4..c51ed598 100644 --- a/src/cydigconfig.json +++ b/src/cydigconfig.json @@ -1,5 +1,5 @@ { - "teamName": "name-of-your-team", + "teamName": "Test-GitHub", "usingAzure": true, "threatModeling": { "date": "date-of-threat-modeling", From 51b633c50330816680da8d7223e36f75a3a7f2a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Bokvad=20Engar=C3=A5s?= Date: Mon, 2 Oct 2023 15:38:35 +0200 Subject: [PATCH 2/4] refactor project --- .../BranchProtectionService.ts | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/branchprotection/BranchProtectionService.ts b/src/branchprotection/BranchProtectionService.ts index 8ef632c9..f43376c2 100644 --- a/src/branchprotection/BranchProtectionService.ts +++ b/src/branchprotection/BranchProtectionService.ts @@ -7,8 +7,9 @@ export class BranchProtectionService { const { owner, repo }: { owner: string; repo: string } = github.context.repo; const token: string = core.getInput('PAT-token'); - const octokit: any = github.getOctokit(token); - + // eslint-disable-next-line @typescript-eslint/typedef + const octokit = github.getOctokit(token); + let numberOfReviewers: number = 0; await octokit.rest.repos .getBranchProtection({ owner: owner, @@ -16,19 +17,20 @@ export class BranchProtectionService { branch: 'main', }) .then((response: any) => { - console.log('Response', response); - console.log( - 'Branch protection is enabled, number of reviewers are:', - response.data.required_pull_request_reviews?.['required_approving_review_count'] - ); - core.exportVariable( - 'numberOfReviewers', - response.data.required_pull_request_reviews?.['required_approving_review_count'] - ); + console.log('Response', response.data); + if (!response.data.enforce_admins?.enabled) { + console.log('Branch protection can be overridden by admins, and is therefore counted as not enabled'); + return; + } + if (response.data.required_pull_request_reviews?.['required_approving_review_count'] >= 1) { + numberOfReviewers = response.data.required_pull_request_reviews?.['required_approving_review_count']; + console.log('Branch protection is enabled, number of reviewers are:', numberOfReviewers); + } }) .catch((error: any) => { - console.log('Branch protections is not enabled for repository: ' + repo); console.log('Error:', error?.message); }); + if (numberOfReviewers <= 0) console.log('Branch protections is not enabled for repository: ' + repo); + core.exportVariable('numberOfReviewers', numberOfReviewers); } } From 066f0ecb6aaec8f121c86f61ca9e1fe10f6d28bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Bokvad=20Engar=C3=A5s?= Date: Mon, 2 Oct 2023 16:02:58 +0200 Subject: [PATCH 3/4] refactor project --- package-lock.json | 241 +++++++++++++++++- package.json | 1 + .../BranchProtectionService.ts | 54 ++-- 3 files changed, 267 insertions(+), 29 deletions(-) diff --git a/package-lock.json b/package-lock.json index 583a2c7a..8ef2d227 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "@actions/core": "^1.10.0", "@actions/github": "^5.1.1", + "@octokit/rest": "^20.0.2", "@vercel/ncc": "^0.36.1", "joi": "^17.10.1" }, @@ -217,6 +218,19 @@ "@octokit/types": "^6.0.3" } }, + "node_modules/@octokit/auth-token/node_modules/@octokit/openapi-types": { + "version": "12.11.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-12.11.0.tgz", + "integrity": "sha512-VsXyi8peyRq9PqIz/tpqiL2w3w80OgVMwBHltTml3LmVvXiphgeqmY9mvBw9Wu7e0QWk/fqD37ux8yP5uVekyQ==" + }, + "node_modules/@octokit/auth-token/node_modules/@octokit/types": { + "version": "6.41.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-6.41.0.tgz", + "integrity": "sha512-eJ2jbzjdijiL3B4PrSQaSjuF2sPEQPVCPzBvTHJD9Nz+9dw2SGH4K4xeQJ77YfTq5bRQ+bD8wT11JbeDPmxmGg==", + "dependencies": { + "@octokit/openapi-types": "^12.11.0" + } + }, "node_modules/@octokit/core": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/@octokit/core/-/core-3.6.0.tgz", @@ -231,6 +245,19 @@ "universal-user-agent": "^6.0.0" } }, + "node_modules/@octokit/core/node_modules/@octokit/openapi-types": { + "version": "12.11.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-12.11.0.tgz", + "integrity": "sha512-VsXyi8peyRq9PqIz/tpqiL2w3w80OgVMwBHltTml3LmVvXiphgeqmY9mvBw9Wu7e0QWk/fqD37ux8yP5uVekyQ==" + }, + "node_modules/@octokit/core/node_modules/@octokit/types": { + "version": "6.41.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-6.41.0.tgz", + "integrity": "sha512-eJ2jbzjdijiL3B4PrSQaSjuF2sPEQPVCPzBvTHJD9Nz+9dw2SGH4K4xeQJ77YfTq5bRQ+bD8wT11JbeDPmxmGg==", + "dependencies": { + "@octokit/openapi-types": "^12.11.0" + } + }, "node_modules/@octokit/endpoint": { "version": "6.0.12", "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-6.0.12.tgz", @@ -241,6 +268,19 @@ "universal-user-agent": "^6.0.0" } }, + "node_modules/@octokit/endpoint/node_modules/@octokit/openapi-types": { + "version": "12.11.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-12.11.0.tgz", + "integrity": "sha512-VsXyi8peyRq9PqIz/tpqiL2w3w80OgVMwBHltTml3LmVvXiphgeqmY9mvBw9Wu7e0QWk/fqD37ux8yP5uVekyQ==" + }, + "node_modules/@octokit/endpoint/node_modules/@octokit/types": { + "version": "6.41.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-6.41.0.tgz", + "integrity": "sha512-eJ2jbzjdijiL3B4PrSQaSjuF2sPEQPVCPzBvTHJD9Nz+9dw2SGH4K4xeQJ77YfTq5bRQ+bD8wT11JbeDPmxmGg==", + "dependencies": { + "@octokit/openapi-types": "^12.11.0" + } + }, "node_modules/@octokit/graphql": { "version": "4.8.0", "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-4.8.0.tgz", @@ -251,11 +291,24 @@ "universal-user-agent": "^6.0.0" } }, - "node_modules/@octokit/openapi-types": { + "node_modules/@octokit/graphql/node_modules/@octokit/openapi-types": { "version": "12.11.0", "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-12.11.0.tgz", "integrity": "sha512-VsXyi8peyRq9PqIz/tpqiL2w3w80OgVMwBHltTml3LmVvXiphgeqmY9mvBw9Wu7e0QWk/fqD37ux8yP5uVekyQ==" }, + "node_modules/@octokit/graphql/node_modules/@octokit/types": { + "version": "6.41.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-6.41.0.tgz", + "integrity": "sha512-eJ2jbzjdijiL3B4PrSQaSjuF2sPEQPVCPzBvTHJD9Nz+9dw2SGH4K4xeQJ77YfTq5bRQ+bD8wT11JbeDPmxmGg==", + "dependencies": { + "@octokit/openapi-types": "^12.11.0" + } + }, + "node_modules/@octokit/openapi-types": { + "version": "19.0.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-19.0.0.tgz", + "integrity": "sha512-PclQ6JGMTE9iUStpzMkwLCISFn/wDeRjkZFIKALpvJQNBGwDoYYi2fFvuHwssoQ1rXI5mfh6jgTgWuddeUzfWw==" + }, "node_modules/@octokit/plugin-paginate-rest": { "version": "2.21.3", "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-2.21.3.tgz", @@ -267,6 +320,19 @@ "@octokit/core": ">=2" } }, + "node_modules/@octokit/plugin-paginate-rest/node_modules/@octokit/openapi-types": { + "version": "12.11.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-12.11.0.tgz", + "integrity": "sha512-VsXyi8peyRq9PqIz/tpqiL2w3w80OgVMwBHltTml3LmVvXiphgeqmY9mvBw9Wu7e0QWk/fqD37ux8yP5uVekyQ==" + }, + "node_modules/@octokit/plugin-paginate-rest/node_modules/@octokit/types": { + "version": "6.41.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-6.41.0.tgz", + "integrity": "sha512-eJ2jbzjdijiL3B4PrSQaSjuF2sPEQPVCPzBvTHJD9Nz+9dw2SGH4K4xeQJ77YfTq5bRQ+bD8wT11JbeDPmxmGg==", + "dependencies": { + "@octokit/openapi-types": "^12.11.0" + } + }, "node_modules/@octokit/plugin-rest-endpoint-methods": { "version": "5.16.2", "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-5.16.2.tgz", @@ -279,6 +345,19 @@ "@octokit/core": ">=3" } }, + "node_modules/@octokit/plugin-rest-endpoint-methods/node_modules/@octokit/openapi-types": { + "version": "12.11.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-12.11.0.tgz", + "integrity": "sha512-VsXyi8peyRq9PqIz/tpqiL2w3w80OgVMwBHltTml3LmVvXiphgeqmY9mvBw9Wu7e0QWk/fqD37ux8yP5uVekyQ==" + }, + "node_modules/@octokit/plugin-rest-endpoint-methods/node_modules/@octokit/types": { + "version": "6.41.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-6.41.0.tgz", + "integrity": "sha512-eJ2jbzjdijiL3B4PrSQaSjuF2sPEQPVCPzBvTHJD9Nz+9dw2SGH4K4xeQJ77YfTq5bRQ+bD8wT11JbeDPmxmGg==", + "dependencies": { + "@octokit/openapi-types": "^12.11.0" + } + }, "node_modules/@octokit/request": { "version": "5.6.3", "resolved": "https://registry.npmjs.org/@octokit/request/-/request-5.6.3.tgz", @@ -302,7 +381,12 @@ "once": "^1.4.0" } }, - "node_modules/@octokit/types": { + "node_modules/@octokit/request-error/node_modules/@octokit/openapi-types": { + "version": "12.11.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-12.11.0.tgz", + "integrity": "sha512-VsXyi8peyRq9PqIz/tpqiL2w3w80OgVMwBHltTml3LmVvXiphgeqmY9mvBw9Wu7e0QWk/fqD37ux8yP5uVekyQ==" + }, + "node_modules/@octokit/request-error/node_modules/@octokit/types": { "version": "6.41.0", "resolved": "https://registry.npmjs.org/@octokit/types/-/types-6.41.0.tgz", "integrity": "sha512-eJ2jbzjdijiL3B4PrSQaSjuF2sPEQPVCPzBvTHJD9Nz+9dw2SGH4K4xeQJ77YfTq5bRQ+bD8wT11JbeDPmxmGg==", @@ -310,6 +394,159 @@ "@octokit/openapi-types": "^12.11.0" } }, + "node_modules/@octokit/request/node_modules/@octokit/openapi-types": { + "version": "12.11.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-12.11.0.tgz", + "integrity": "sha512-VsXyi8peyRq9PqIz/tpqiL2w3w80OgVMwBHltTml3LmVvXiphgeqmY9mvBw9Wu7e0QWk/fqD37ux8yP5uVekyQ==" + }, + "node_modules/@octokit/request/node_modules/@octokit/types": { + "version": "6.41.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-6.41.0.tgz", + "integrity": "sha512-eJ2jbzjdijiL3B4PrSQaSjuF2sPEQPVCPzBvTHJD9Nz+9dw2SGH4K4xeQJ77YfTq5bRQ+bD8wT11JbeDPmxmGg==", + "dependencies": { + "@octokit/openapi-types": "^12.11.0" + } + }, + "node_modules/@octokit/rest": { + "version": "20.0.2", + "resolved": "https://registry.npmjs.org/@octokit/rest/-/rest-20.0.2.tgz", + "integrity": "sha512-Ux8NDgEraQ/DMAU1PlAohyfBBXDwhnX2j33Z1nJNziqAfHi70PuxkFYIcIt8aIAxtRE7KVuKp8lSR8pA0J5iOQ==", + "dependencies": { + "@octokit/core": "^5.0.0", + "@octokit/plugin-paginate-rest": "^9.0.0", + "@octokit/plugin-request-log": "^4.0.0", + "@octokit/plugin-rest-endpoint-methods": "^10.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/rest/node_modules/@octokit/auth-token": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-4.0.0.tgz", + "integrity": "sha512-tY/msAuJo6ARbK6SPIxZrPBms3xPbfwBrulZe0Wtr/DIY9lje2HeV1uoebShn6mx7SjCHif6EjMvoREj+gZ+SA==", + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/rest/node_modules/@octokit/core": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/@octokit/core/-/core-5.0.1.tgz", + "integrity": "sha512-lyeeeZyESFo+ffI801SaBKmCfsvarO+dgV8/0gD8u1d87clbEdWsP5yC+dSj3zLhb2eIf5SJrn6vDz9AheETHw==", + "dependencies": { + "@octokit/auth-token": "^4.0.0", + "@octokit/graphql": "^7.0.0", + "@octokit/request": "^8.0.2", + "@octokit/request-error": "^5.0.0", + "@octokit/types": "^12.0.0", + "before-after-hook": "^2.2.0", + "universal-user-agent": "^6.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/rest/node_modules/@octokit/endpoint": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-9.0.1.tgz", + "integrity": "sha512-hRlOKAovtINHQPYHZlfyFwaM8OyetxeoC81lAkBy34uLb8exrZB50SQdeW3EROqiY9G9yxQTpp5OHTV54QD+vA==", + "dependencies": { + "@octokit/types": "^12.0.0", + "is-plain-object": "^5.0.0", + "universal-user-agent": "^6.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/rest/node_modules/@octokit/graphql": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-7.0.2.tgz", + "integrity": "sha512-OJ2iGMtj5Tg3s6RaXH22cJcxXRi7Y3EBqbHTBRq+PQAqfaS8f/236fUrWhfSn8P4jovyzqucxme7/vWSSZBX2Q==", + "dependencies": { + "@octokit/request": "^8.0.1", + "@octokit/types": "^12.0.0", + "universal-user-agent": "^6.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/rest/node_modules/@octokit/plugin-paginate-rest": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-9.0.0.tgz", + "integrity": "sha512-oIJzCpttmBTlEhBmRvb+b9rlnGpmFgDtZ0bB6nq39qIod6A5DP+7RkVLMOixIgRCYSHDTeayWqmiJ2SZ6xgfdw==", + "dependencies": { + "@octokit/types": "^12.0.0" + }, + "engines": { + "node": ">= 18" + }, + "peerDependencies": { + "@octokit/core": ">=5" + } + }, + "node_modules/@octokit/rest/node_modules/@octokit/plugin-request-log": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@octokit/plugin-request-log/-/plugin-request-log-4.0.0.tgz", + "integrity": "sha512-2uJI1COtYCq8Z4yNSnM231TgH50bRkheQ9+aH8TnZanB6QilOnx8RMD2qsnamSOXtDj0ilxvevf5fGsBhBBzKA==", + "engines": { + "node": ">= 18" + }, + "peerDependencies": { + "@octokit/core": ">=5" + } + }, + "node_modules/@octokit/rest/node_modules/@octokit/plugin-rest-endpoint-methods": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-10.0.0.tgz", + "integrity": "sha512-16VkwE2v6rXU+/gBsYC62M8lKWOphY5Lg4wpjYnVE9Zbu0J6IwiT5kILoj1YOB53XLmcJR+Nqp8DmifOPY4H3g==", + "dependencies": { + "@octokit/types": "^12.0.0" + }, + "engines": { + "node": ">= 18" + }, + "peerDependencies": { + "@octokit/core": ">=5" + } + }, + "node_modules/@octokit/rest/node_modules/@octokit/request": { + "version": "8.1.2", + "resolved": "https://registry.npmjs.org/@octokit/request/-/request-8.1.2.tgz", + "integrity": "sha512-A0RJJfzjlZQwb+39eDm5UM23dkxbp28WEG4p2ueH+Q2yY4p349aRK/vcUlEuIB//ggcrHJceoYYkBP/LYCoXEg==", + "dependencies": { + "@octokit/endpoint": "^9.0.0", + "@octokit/request-error": "^5.0.0", + "@octokit/types": "^12.0.0", + "is-plain-object": "^5.0.0", + "universal-user-agent": "^6.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/rest/node_modules/@octokit/request-error": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-5.0.1.tgz", + "integrity": "sha512-X7pnyTMV7MgtGmiXBwmO6M5kIPrntOXdyKZLigNfQWSEQzVxR4a4vo49vJjTWX70mPndj8KhfT4Dx+2Ng3vnBQ==", + "dependencies": { + "@octokit/types": "^12.0.0", + "deprecation": "^2.0.0", + "once": "^1.4.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/types": { + "version": "12.0.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-12.0.0.tgz", + "integrity": "sha512-EzD434aHTFifGudYAygnFlS1Tl6KhbTynEWELQXIbTY8Msvb5nEqTZIm7sbPEt4mQYLZwu3zPKVdeIrw0g7ovg==", + "dependencies": { + "@octokit/openapi-types": "^19.0.0" + } + }, "node_modules/@sideway/address": { "version": "4.1.4", "resolved": "https://registry.npmjs.org/@sideway/address/-/address-4.1.4.tgz", diff --git a/package.json b/package.json index 034942d4..a03927f7 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "dependencies": { "@actions/core": "^1.10.0", "@actions/github": "^5.1.1", + "@octokit/rest": "^20.0.2", "@vercel/ncc": "^0.36.1", "joi": "^17.10.1" }, diff --git a/src/branchprotection/BranchProtectionService.ts b/src/branchprotection/BranchProtectionService.ts index f43376c2..9952e659 100644 --- a/src/branchprotection/BranchProtectionService.ts +++ b/src/branchprotection/BranchProtectionService.ts @@ -1,36 +1,36 @@ +/* eslint-disable @typescript-eslint/typedef */ /* eslint-disable @typescript-eslint/no-explicit-any */ import * as core from '@actions/core'; import * as github from '@actions/github'; export class BranchProtectionService { public static async getStateOfBranchProtection(): Promise { - console.log('\n Running branch protection control'); - - const { owner, repo }: { owner: string; repo: string } = github.context.repo; - const token: string = core.getInput('PAT-token'); - // eslint-disable-next-line @typescript-eslint/typedef - const octokit = github.getOctokit(token); - let numberOfReviewers: number = 0; - await octokit.rest.repos - .getBranchProtection({ - owner: owner, - repo: repo, + try { + console.log('\n Running branch protection control'); + const { owner, repo }: { owner: string; repo: string } = github.context.repo; + const token: string = core.getInput('PAT-token'); + const octokit = github.getOctokit(token); + const response = await octokit.rest.repos.getBranchProtection({ + owner, + repo, branch: 'main', - }) - .then((response: any) => { - console.log('Response', response.data); - if (!response.data.enforce_admins?.enabled) { - console.log('Branch protection can be overridden by admins, and is therefore counted as not enabled'); - return; - } - if (response.data.required_pull_request_reviews?.['required_approving_review_count'] >= 1) { - numberOfReviewers = response.data.required_pull_request_reviews?.['required_approving_review_count']; - console.log('Branch protection is enabled, number of reviewers are:', numberOfReviewers); - } - }) - .catch((error: any) => { - console.log('Error:', error?.message); }); - if (numberOfReviewers <= 0) console.log('Branch protections is not enabled for repository: ' + repo); - core.exportVariable('numberOfReviewers', numberOfReviewers); + const numberOfReviewers: number = + response.data.required_pull_request_reviews?.required_approving_review_count || 0; + console.log('Response', response.data); + + if (response.data.enforce_admins?.enabled === false) { + console.log('Branch protection can be overridden by admins and is therefore counted as not enabled'); + } + + if (numberOfReviewers >= 1 && response.data.enforce_admins?.enabled === true) { + console.log('Branch protection is enabled, number of reviewers:', numberOfReviewers); + } else { + console.log('Branch protection is not enabled for repository:', repo); + } + + core.exportVariable('numberOfReviewers', numberOfReviewers); + } catch (error) { + console.log('Error:', error.message); + } } } From dfca0a51d6921ae4e7626a87a38a480e26ae86d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Bokvad=20Engar=C3=A5s?= Date: Mon, 2 Oct 2023 16:09:58 +0200 Subject: [PATCH 4/4] refactor project --- src/branchprotection/BranchProtectionService.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/branchprotection/BranchProtectionService.ts b/src/branchprotection/BranchProtectionService.ts index 9952e659..7836ce17 100644 --- a/src/branchprotection/BranchProtectionService.ts +++ b/src/branchprotection/BranchProtectionService.ts @@ -14,14 +14,14 @@ export class BranchProtectionService { repo, branch: 'main', }); - const numberOfReviewers: number = - response.data.required_pull_request_reviews?.required_approving_review_count || 0; console.log('Response', response.data); - if (response.data.enforce_admins?.enabled === false) { console.log('Branch protection can be overridden by admins and is therefore counted as not enabled'); } + const numberOfReviewers: number = + response.data.required_pull_request_reviews?.required_approving_review_count || 0; + if (numberOfReviewers >= 1 && response.data.enforce_admins?.enabled === true) { console.log('Branch protection is enabled, number of reviewers:', numberOfReviewers); } else {