diff --git a/src/index.mts b/src/index.mts index 600f242..c238780 100644 --- a/src/index.mts +++ b/src/index.mts @@ -143,6 +143,31 @@ async function extractTarGz(filePath: string): Promise { return newName; } +/** + * Get the arguments to pass to the Scorecard binary. + * @returns {string[]} The arguments to pass to the Scorecard binary. + */ +function getArguments(): string[] { + const args: string[] = []; + + const repository = process.env["BUILD_REPOSITORY_URI"]; + if (repository) { + args.push("--repo", repository); + } + + const resultsFile = process.env["INPUT_RESULTSFILE"]; + if (resultsFile) { + args.push("--output", resultsFile); + } + + const resultsFormat = process.env["INPUT_RESULTSFORMAT"]; + if (resultsFormat) { + args.push("--format", resultsFormat); + } + + return args; +} + /** * Run the Scorecard binary. * @async @@ -150,8 +175,20 @@ async function extractTarGz(filePath: string): Promise { * @returns {Promise} A promise that resolves when the command is executed. */ async function runScorecard(binary: string): Promise { - const child = spawn(binary, ["--repo", "https://github.com/ossf/scorecard"], { - env: { SCORECARD_EXPERIMENTAL: "true" }, + // const child = spawn(binary, getArguments(), { + // env: { + // AZURE_DEVOPS_AUTH_TOKEN: + // process.env["INPUT_REPOTOKEN"] ?? + // process.env["AZURE_DEVOPS_AUTH_TOKEN"], + // SCORECARD_EXPERIMENTAL: "true", + // }, + // }); + + const child = spawn(binary, ["--repo", "github.com/ossf/scorecard"], { + env: { + GITHUB_AUTH_TOKEN: process.env["INPUT_REPOTOKEN"], + SCORECARD_EXPERIMENTAL: "true", + }, }); child.stdout.on("data", (data) => { console.log(data.toString()); diff --git a/src/task.json b/src/task.json index 3f8b110..03107a0 100644 --- a/src/task.json +++ b/src/task.json @@ -18,7 +18,7 @@ "name": "resultsFile", "label": "Results File", "type": "filePath", - "required": true, + "required": false, "helpMarkDown": "OUTPUT: Path to file where the results will be saved." }, { @@ -30,6 +30,13 @@ "sarif": "SARIF", "json": "JSON" } + }, + { + "name": "repoToken", + "label": "Azure DevOps PAT", + "type": "string", + "required": false, + "helpMarkDown": "INPUT: Azure DevOps PAT with read access to the repository." } ], "execution": {