Skip to content

Commit

Permalink
added proper console logs to pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
Johanna Ahlskog committed Sep 14, 2023
1 parent 6fb4bdf commit 2c329cc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
6 changes: 2 additions & 4 deletions src/Pentest/PentestService.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import * as core from '@actions/core';
import * as github from '@actions/github';
//import * as github from '@actions/github';

export class PentestService {
public static async getStateOfPentest(pentestDate: { date: string; boardsTag: string }): Promise<void> {
console.log('Running Pentest Controls');

if (!pentestDate.date || pentestDate.date === 'date-of-pentest') {
core.warning('Pentest Date is not set!');
return;
}
core.exportVariable('pentestDate', pentestDate.date);

console.log('Pentest Date is set', pentestDate.date);
//console.log('Pentest Date is set', pentestDate.date);

// const token = core.getInput('repo-token');
// console.log('Got the token');
Expand Down
19 changes: 10 additions & 9 deletions src/branchprotection/BranchProtectionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,32 @@ 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!');
console.log('\n Running branch protection control');
const token = core.getInput('repo-token');
console.log('Got the token');
//console.log('Got the token');

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

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

console.log('Going to get branch protection');
//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('Got the branch protection');
console.log(response.data);
})
.catch((error) => {
core.warning('Error getting branch protection!');
console.log('Error: ', error.message);
console.log('Branch protections is not enabled for repository:' + repo)
//core.warning('Error getting branch protection!');
//console.log('Error: ', error.message);
});
}
}
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ import * as github from '@actions/github';
import { BranchProtectionService } from './branchprotection/BranchProtectionService';
import { CyDigConfig } from './types/CyDigConfig';
import { getContentOfFile } from './helpfunctions/JsonService';
import { PentestService } from './Pentest/PentestService';
import { PentestService } from './pentest/PentestService';
import { ThreatModelingService } from './threatmodeling/ThreatModelingService';
/**
* The main function for the action.
* @returns {Promise<void>} Resolves when the action is complete.
*/
export async function run(): Promise<void> {
try {
console.log('\n Running controls on your repository')
const cydigConfig: CyDigConfig = getContentOfFile(core.getInput('cydigConfigPath'));
await BranchProtectionService.getStateOfBranchProtection();

console.log('\n Running controls on your boards');
await PentestService.getStateOfPentest(cydigConfig.pentest);
await ThreatModelingService.getStateOfThreatModeling(cydigConfig.threatModeling);
} catch (error) {
Expand Down

0 comments on commit 2c329cc

Please sign in to comment.