Skip to content

Commit

Permalink
added branchprotection task
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanbokvad committed Sep 7, 2023
1 parent bf57b06 commit 03a43f3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
30 changes: 30 additions & 0 deletions src/branchprotection/BranchProtectionService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as core from '@actions/core';
import * as github from '@actions/github';
export class BranchProtectionService{

public static async getStateOfBranchProtection(): Promise<void> {
console.log('Custom task is working!');
const token = core.getInput('repo-token');
console.log("Got the token");

const octokit = github.getOctokit(token);
console.log("octoKit authenticated");

const { owner, repo } = github.context.repo;
console.log(`Owner: ${owner}`);
console.log(`Repo: ${repo}`);

console.log("Going to get branch protection");
await octokit.rest.repos.getBranchProtection({
owner: owner,
repo: repo,
branch: 'main',
}).then((response) => {
console.log("Got the branch protection");
console.log(response.data);
}).catch((error) => {
core.warning("Error getting branch protection!");
core.warning("Error: ", error.message);
});
}
}
31 changes: 3 additions & 28 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,16 @@
import * as core from '@actions/core';
import * as github from '@actions/github';
import { BranchProtectionService } from './branchprotection/BranchProtectionService';
/**
* The main function for the action.
* @returns {Promise<void>} Resolves when the action is complete.
*/
export async function run(): Promise<void> {
try {
console.log('Custom task is working!');
const token = core.getInput('repo-token');
console.log("Got the token");
const octokit = github.getOctokit(token);
console.log("octoKit authenticated");
console.log("Going to get branch protection");
const { owner, repo } = github.context.repo;
console.log(`Owner: ${owner}`);
console.log(`Repo: ${repo}`);

const branchProtection = await octokit.rest.repos.getBranchProtection({
owner: owner,
repo: repo,
branch: 'main',
}).then((response) => {
console.log("Got the branch protection");
console.log(response.data);
}).catch((error) => {
core.warning("Error getting branch protection");
core.warning(error.message);
});

// if(!branchProtection){
// console.log("Branch protection not found");
// }
// else{
// console.log("Logging branch protection");
// console.log(branchProtection.data);
// }
await BranchProtectionService.getStateOfBranchProtection();


} catch (error) {
// Fail the workflow run if an error occurs
if (error instanceof Error) core.setFailed(error.message);
Expand Down

0 comments on commit 03a43f3

Please sign in to comment.