Skip to content

Commit

Permalink
refactor project
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanbokvad committed Sep 26, 2023
1 parent 96e677b commit 5b310c6
Show file tree
Hide file tree
Showing 3 changed files with 231 additions and 7 deletions.
200 changes: 200 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
"dependencies": {
"@actions/core": "^1.10.0",
"@actions/github": "^5.1.1",
"joi": "^17.10.1",
"@vercel/ncc": "^0.36.1"
"@octokit/action": "^6.0.6",
"@vercel/ncc": "^0.36.1",
"joi": "^17.10.1"
},
"devDependencies": {
"@types/node": "^20.5.7",
"@types/chai": "^4.3.6",
"@types/mocha": "^10.0.1",
"@types/node": "^20.5.7",
"@types/sinon": "^10.0.16",
"@types/sinon-chai": "^3.2.9",
"@typescript-eslint/eslint-plugin": "^5.62.0",
Expand Down
31 changes: 27 additions & 4 deletions src/branchprotection/BranchProtectionService.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,48 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import * as core from '@actions/core';
import * as github from '@actions/github';
import { Octokit } from '@octokit/action';
export class BranchProtectionService {
public static async getStateOfBranchProtection(): Promise<void> {
console.log('\n Running branch protection control');

const octokit: Octokit = new Octokit();
const { owner, repo }: { owner: string; repo: string } = github.context.repo;
octokit.repos
.getBranchProtection({
owner: owner,
repo: repo,
branch: 'main',
})
.then((response: any) => {
console.log(
'Branch protection is enabled, and reviewers needed are:',
response.data.required_approving_review_count
);
console.log(response.data);
})
.catch((error: any) => {
console.log('Branch protections is not enabled for repository: ' + repo);
console.log('Error:', error?.message);
});

//numberOfReviewers > 0, if state of branch protection changes
const numberOfReviewers: number = 0;

const token: string = core.getInput('github-token');
const octokit: any = github.getOctokit(token);
// const token: string = core.getInput('github-token');
// const octokit: any = github.getOctokit(token);

const { owner, repo }: { owner: string; repo: string } = github.context.repo;
await octokit.rest.repos
.getBranchProtection({
owner: owner,
repo: repo,
branch: 'main',
})
.then((response: any) => {
console.log(response.data);
console.log(
'Branch protection is enabled, and reviewers needed are:',
response.data.required_approving_review_count
);
})
.catch((error: any) => {
console.log('Branch protections is not enabled for repository: ' + repo);
Expand Down

0 comments on commit 5b310c6

Please sign in to comment.