Skip to content

Commit

Permalink
Merge pull request #33 from Contrast-Security-Inc/NODE-1972
Browse files Browse the repository at this point in the history
[NODE-1972] NODE_MODULE to NODE_MODULE_INIT
  • Loading branch information
Yavorss authored Jan 14, 2022
2 parents d06b9c9 + 0d8a15d commit 8b1195e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 36 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,8 @@
"dependencies": {
"@octokit/rest": "^18.3.5",
"xml-js": "^1.6.11"
},
"engines": {
"node": ">=10.0.0"
}
}
81 changes: 47 additions & 34 deletions scripts/download-artifact.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,59 @@
const fs = require('fs');
const https = require('https');
const { Octokit } = require("@octokit/rest");
const octokit = new Octokit({auth: process.env.AUTH_TOKEN});
const repo = {
owner: 'Contrast-Security-Inc',
repo: 'node-fn-inspect'
}
const { Octokit } = require('@octokit/rest');
const octokit = new Octokit({ auth: process.env.AUTH_TOKEN });
const repo = {
owner: 'Contrast-Security-Inc',
repo: 'node-fn-inspect'
};

const getLatestRunID = async function(args) {
const workflowsRuns = (await octokit.actions.listWorkflowRunsForRepo({
...args,
branch: 'main',
conclusion: 'success'
})).data.workflow_runs;
const latestRun = workflowsRuns.reduce((max, run) => max.run_number > run.run_number ? max : run);
return latestRun.id;
}
const workflowsRuns = (
await octokit.actions.listWorkflowRunsForRepo({
...args,
branch: 'main',
conclusion: 'success'
})
).data.workflow_runs;
const latestRun = workflowsRuns.reduce((max, run) =>
max.run_number > run.run_number ? max : run
);
return latestRun.id;
};

const getLatestArtifactID = async function(args) {
const latestArtifacts = (await octokit.actions.listWorkflowRunArtifacts({
...args,
run_id: await getLatestRunID(args)
})).data.artifacts;
const funcinfoTar = latestArtifacts.find(artifact => artifact.name === 'funcinfo.tgz');
return funcinfoTar.id;
}
const latestArtifacts = (
await octokit.actions.listWorkflowRunArtifacts({
...args,
run_id: await getLatestRunID(args)
})
).data.artifacts;
const funcinfoTar = latestArtifacts.find(
(artifact) => artifact.name === 'funcinfo.tgz'
);
return funcinfoTar.id;
};

const downloadLatestArtifact = async function(args) {
const latestArtifactURL = (await octokit.actions.downloadArtifact({
...args,
artifact_id: await getLatestArtifactID(args),
archive_format: 'zip'
})).url;
const artifactFile = fs.createWriteStream("funcinfo.tgz.zip");
https.get(latestArtifactURL, function(res) {
res.pipe(artifactFile);
});
}
const latestArtifactURL = (
await octokit.actions.downloadArtifact({
...args,
artifact_id: await getLatestArtifactID(args),
archive_format: 'zip'
})
).url;
const artifactFile = fs.createWriteStream('funcinfo.tgz.zip');
https.get(latestArtifactURL, function(res) {
res.pipe(artifactFile);
});
};

downloadLatestArtifact(repo).then(() => {
downloadLatestArtifact(repo)
.then(() => {
console.log('Successfully downloaded latest artifact');
}).catch((err) => {
})
.catch((err) => {
console.log(`Failed to download latest artifact\n${err.stack}`);
// eslint-disable-next-line no-process-exit
process.exit(-1);
})
});
4 changes: 3 additions & 1 deletion src/code-events.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ void Initialize(Local<Object> exports) {
NODE_SET_METHOD(exports, "getNext", GetNext);
}

NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)
NODE_MODULE_INIT() {
Initialize(exports);
}

} // namespace codeevents
4 changes: 3 additions & 1 deletion src/funcinfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ void Initialize(Local<Object> exports) {
NODE_SET_METHOD(exports, "funcinfo", Method);
}

NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)
NODE_MODULE_INIT() {
Initialize(exports);
}

}

0 comments on commit 8b1195e

Please sign in to comment.