From b71be3d8d6d53c3c7525bf60bc27e31bb86ba22f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Bokvad=20Engar=C3=A5s?= Date: Fri, 8 Sep 2023 09:07:58 +0200 Subject: [PATCH] Added logging --- src/Pentest/PentestService.ts | 107 +++++++++++++++++++--------------- 1 file changed, 60 insertions(+), 47 deletions(-) diff --git a/src/Pentest/PentestService.ts b/src/Pentest/PentestService.ts index 03e592f8..3ee2b0b1 100644 --- a/src/Pentest/PentestService.ts +++ b/src/Pentest/PentestService.ts @@ -2,57 +2,70 @@ import * as core from '@actions/core'; import * as github from '@actions/github'; export class PentestService { - public static async getStateOfPentest(pentestDate: { - date: string; - boardsTag: string; - }): Promise { - console.log('Running Pentest Controls'); - - if(!pentestDate.date || pentestDate.date === "date-of-pentest"){ - core.warning("Pentest Date is not set!"); - return; - } - core.setOutput("pentestDate", pentestDate.date); - - console.log("Pentest Date is set", pentestDate.date); + public static async getStateOfPentest(pentestDate: { date: string; boardsTag: string }): Promise { + console.log('Running Pentest Controls'); - // const token = core.getInput('repo-token'); - // console.log("Got the token"); + if (!pentestDate.date || pentestDate.date === 'date-of-pentest') { + core.warning('Pentest Date is not set!'); + return; + } + core.setOutput('pentestDate', pentestDate.date); - // const octokit = github.getOctokit(token); - // console.log("octoKit authenticated"); + console.log('Pentest Date is set', pentestDate.date); - // const { owner, repo } = github.context.repo; - // console.log(`Owner: ${owner}`); - // console.log(`Repo: ${repo}`); + const token = core.getInput('repo-token'); + console.log('Got the token'); - // console.log("Going to get branch protection"); - // await octokit.rest.projects.listCards({ - // owner: owner, - // repo: repo, - // column_id: 123456789, + const octokit = github.getOctokit(token); + console.log('octoKit authenticated'); - // }).then((response) => { - // console.log("Got the cards"); - // const projectCards = response.data; - // const customLabelCards = projectCards.filter((card) => { - // return card.note?.includes(pentestDate.boardsTag); - // }); - + const { owner, repo } = github.context.repo; + console.log(`Owner: ${owner}`); + console.log(`Repo: ${repo}`); - // }).catch((error) => { - // core.warning("Error getting cards!"); - // core.warning("Error: ", error.message); + console.log('Going to get branch protection'); + await octokit.rest.projects + .listCards({ + owner: owner, + repo: repo, + column_id: 123456789, + }) + .then(async (response) => { + console.log('Got the cards'); + const projectCards = response.data; + // const customLabelCards = projectCards.filter((card) => { + // return card.note?.includes(pentestDate.boardsTag); // }); - // 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); - // }); - } -} \ No newline at end of file + + const customLabelCards = []; + console.log('projectCards', projectCards); + for (const card of projectCards) { + // Get the associated issue or pull request for the card + console.log('card', card); + const contentResponse = await octokit.request(card.content_url); + console.log('contentResponse', contentResponse); + if (contentResponse.data.labels.some((label: any) => label.name === pentestDate.boardsTag)) { + customLabelCards.push(card); + } + } + + console.log('customLabelCards', customLabelCards); + return customLabelCards; + }) + .catch((error) => { + core.warning('Error getting cards!'); + core.warning('Error: ', error.message); + }); + + // 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); + // }); + } +}