Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional PR: Move optional params to object (WIP) #22

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions packages/scans/src/action-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const readline = require('readline');
const AdmZip = require('adm-zip');
const request = require('request');
const artifact = require('@actions/artifact');
const { DEFAULT_OPTIONS } = require('./constants');

function createReadStreamSafe(filename, options) {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -183,7 +184,7 @@ let actionHelper = {
}),


readPreviousReport: (async (octokit, owner, repo, workSpace, runnerID) => {
readPreviousReport: (async (octokit, owner, repo, workSpace, runnerID, { artifactName } = DEFAULT_OPTIONS) => {
let previousReport;
try{
let artifactList = await octokit.actions.listWorkflowRunArtifacts({
Expand All @@ -196,7 +197,7 @@ let actionHelper = {
let artifactID;
if (artifacts.length !== 0) {
artifacts.forEach((a => {
if (a['name'] === 'zap_scan') {
if (a['name'] === artifactName) {
artifactID = a['id']
}
}));
Expand All @@ -212,12 +213,12 @@ let actionHelper = {

await new Promise(resolve =>
request(download.url)
.pipe(fs.createWriteStream(`${workSpace}/zap_scan.zip`))
.pipe(fs.createWriteStream(`${workSpace}/${artifactName}.zip`))
.on('finish', () => {
resolve();
}));

let zip = new AdmZip(`${workSpace}/zap_scan.zip`);
let zip = new AdmZip(`${workSpace}/${artifactName}.zip`);
let zipEntries = zip.getEntries();

await zipEntries.forEach(function (zipEntry) {
Expand All @@ -232,7 +233,7 @@ let actionHelper = {
return previousReport;
}),

uploadArtifacts: (async (rootDir, mdReport, jsonReport, htmlReport, artifactName = 'zap_scan') => {
uploadArtifacts: (async (rootDir, mdReport, jsonReport, htmlReport, { artifactName } = DEFAULT_OPTIONS) => {
const artifactClient = artifact.create();
const files = [
`${rootDir}/${mdReport}`,
Expand Down
6 changes: 6 additions & 0 deletions packages/scans/src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
DEFAULT_OPTIONS: {
allowIssueWriting: true,
artifactName: 'zap_scan',
}
}
7 changes: 4 additions & 3 deletions packages/scans/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ const fs = require('fs');
const github = require('@actions/github');
const _ = require('lodash');
const actionHelper = require('./action-helper');
const { DEFAULT_OPTIONS } = require('./constants');

let actionCommon = {
processReport: (async (token, workSpace, plugins, currentRunnerID, issueTitle, repoName, allowIssueWriting = true, artifactName = 'zap_scan') => {
processReport: (async (token, workSpace, plugins, currentRunnerID, issueTitle, repoName, { allowIssueWriting, artifactName } = DEFAULT_OPTIONS) => {
let jsonReportName = 'report_json.json';
let mdReportName = 'report_md.md';
let htmlReportName = 'report_html.html';
Expand Down Expand Up @@ -92,7 +93,7 @@ let actionCommon = {
}

if (previousRunnerID !== null) {
previousReport = await actionHelper.readPreviousReport(octokit, owner, repo, workSpace, previousRunnerID);
previousReport = await actionHelper.readPreviousReport(octokit, owner, repo, workSpace, previousRunnerID, { artifactName });
if (previousReport === undefined) {
create_new_issue = true;
}
Expand Down Expand Up @@ -182,7 +183,7 @@ let actionCommon = {
}
}

actionHelper.uploadArtifacts(workSpace, mdReportName, jsonReportName, htmlReportName, artifactName);
actionHelper.uploadArtifacts(workSpace, mdReportName, jsonReportName, htmlReportName, { artifactName });

})
};
Expand Down