Skip to content

Commit

Permalink
refactor project
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanbokvad committed Oct 2, 2023
1 parent 838acc4 commit 51b633c
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/branchprotection/BranchProtectionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,30 @@ 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,
repo: repo,
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);
}
}

0 comments on commit 51b633c

Please sign in to comment.