Skip to content

Commit

Permalink
Make real api calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Feyd-Rauth committed Mar 5, 2023
1 parent 9923ece commit 04ac148
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
4 changes: 1 addition & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ async function run(): Promise<void> {

// get issue context
const issue = getIssue()
console.log('Issue content: ', issue.content)

// Api is down
const isSecurity = await Requirement.isSecurity(issue.content)
Expand All @@ -30,14 +29,13 @@ async function run(): Promise<void> {
// 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)
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export interface Stig {
id: string
url: string
platform: string
text: string
}

export interface Test extends Stig {
Expand Down
12 changes: 6 additions & 6 deletions src/requirement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,16 @@ namespace Requirement {
export async function getStigs(requirement: string, platform: string): Promise<Stig[]> {
// array for STIGs to the particular requirement
let stigs: Array<Stig> = []

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`)
}
Expand All @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions src/rqcode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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:`
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 04ac148

Please sign in to comment.