Skip to content

Commit

Permalink
Merge pull request #8 from Omegapoint/feature/NewTesterTest3
Browse files Browse the repository at this point in the history
Feature/new tester test3
  • Loading branch information
jonathanbokvad authored Sep 28, 2023
2 parents 7e19536 + d7d8659 commit cbcf180
Show file tree
Hide file tree
Showing 4 changed files with 236 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ permissions:
contents: write
pages: write
id-token: write
repository-projects: write

on: [push, workflow_dispatch]
jobs:
Expand All @@ -23,6 +24,8 @@ jobs:
run: npm run build
- name: 'Run Compliance State'
uses: ./
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
cydigConfigPath: ${{ github.workspace }}/src/cydigconfig.json
github-token: ${{ secrets.GITHUB_TOKEN}}
github-token: ${{ secrets.MY_GITHUB_PAT}}
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
33 changes: 28 additions & 5 deletions src/branchprotection/BranchProtectionService.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,52 @@
/* 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);
console.log('Error: ', error?.message);
console.log('Error:', error?.message);
});
core.exportVariable('numberOfReviewers', numberOfReviewers);
}
Expand Down

0 comments on commit cbcf180

Please sign in to comment.