diff --git a/src/index.ts b/src/index.ts index 8294b40..21bafb6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -20,7 +20,6 @@ async function run(): Promise { // get issue context const issue = getIssue() - console.log('Issue content: ', issue.content) // Api is down const isSecurity = await Requirement.isSecurity(issue.content) @@ -30,14 +29,13 @@ async function run(): Promise { // 1. User specified input STIGs as true // 2. ARQAN Classification Service encounters issue as security requirement if (stigs === 'true' && isSecurity) { - // Api is down const recommendedStigs = await Requirement.getStigs(issue.content, platform) if (recommendedStigs) { await Requirement.commentRecommendedStigs(recommendedStigs, repo, issue.number, token) // INTERACTION with RQCODE repository goes here await Rqcode.cloneRepo() - const tests = await Rqcode.findTests(recommendedStigs, platform) + const tests = await Rqcode.findTests(recommendedStigs) await Rqcode.commentFoundTests(tests.found, repo, issue.number, token) const openedIssues = await Rqcode.openIssues(tests.missing, rqcodeToken) await Rqcode.commentMissingTests(openedIssues, repo, issue.number, token) diff --git a/src/interfaces.ts b/src/interfaces.ts index e739f4b..9bd313b 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -1,6 +1,8 @@ export interface Stig { id: string url: string + platform: string + text: string } export interface Test extends Stig { diff --git a/src/requirement.ts b/src/requirement.ts index d0fa5f0..4290546 100644 --- a/src/requirement.ts +++ b/src/requirement.ts @@ -43,17 +43,16 @@ namespace Requirement { export async function getStigs(requirement: string, platform: string): Promise { // array for STIGs to the particular requirement let stigs: Array = [] - - let stig_urls = await ApiService.getRecommendedStigs(requirement, platform) - if (Object.keys(stig_urls).length === 0) { + let response_json = await ApiService.getRecommendedStigs(requirement, platform) + if (Object.keys(response_json).length === 0) { return stigs } - for (let key in stig_urls) { + for (let stig_text in response_json) { // get STIG ID from the url - let url = stig_urls[key] + let [stig_platform, url] = response_json[stig_text][0] let stig_id = url.split('/').pop() if (stig_id) { - stigs.push({ id: stig_id, url: url }) + stigs.push({ id: stig_id, url: url, text: stig_text, platform: stig_platform}) } else { throw new Error(`Couldn't get STIG ID from the url: ${url} returned by ARQAN`) } @@ -71,6 +70,7 @@ namespace Requirement { let comment = 'Recommended STIG:' for (let stig of stigs) { comment += `\r\n- [${stig.id}](${stig.url})` + comment += `\r\n - ${stig.text}` } const octokit = getOctokit(token) diff --git a/src/rqcode.ts b/src/rqcode.ts index 9219a42..29ea6fe 100644 --- a/src/rqcode.ts +++ b/src/rqcode.ts @@ -13,18 +13,20 @@ namespace Rqcode { await executeCommand(`git clone ${rqcodeRepo.url}`, exec) } - export async function findTests(stigs: Stig[], platform: string): Promise<{ found: Test[]; missing: Stig[] }> { + export async function findTests(stigs: Stig[]): Promise<{ found: Test[]; missing: Stig[] }> { let found: Test[] = [] let missing: Stig[] = [] const { exec } = require('child_process') for (let stig of stigs) { const stigDir = stig.id.replace(/-/g, '_') - await executeCommand(`find ${rqcodeRepo.repo}/src/main/java/rqcode/stigs/${platform} -type d -name "${stigDir}"`, exec) + await executeCommand(`find ${rqcodeRepo.repo}/src/main/java/rqcode/stigs/${stig.platform} -type d -name "${stigDir}"`, exec) .then((data) => { if (data) { found.push({ id: stig.id, url: stig.url, + platform: stig.platform, + text: stig.text, rqcode: `${rqcodeRepo.url.slice(0, 36)}/tree/master${data.slice(6)}` }) } else { @@ -50,6 +52,7 @@ namespace Rqcode { if (tests.length) { for (let test of tests) { comment += `\r\n- [${test.id}](${test.rqcode})` + comment += `\r\n ${test.text}` } } else { comment = `[RQCODE](${rqcodeRepo.url}) doesn't have implemented tests for recommended STIGs currently :pensive:` @@ -79,7 +82,7 @@ namespace Rqcode { body: `${stig.url}` }) console.log('Created issue') - issuesUrls.push({ id: stig.id, url: stig.url, issueUrl: html_url }) + issuesUrls.push({ id: stig.id, url: stig.url, platform: stig.platform, text: stig.text, issueUrl: html_url }) } return issuesUrls