Skip to content

Commit dccef0c

Browse files
authored
Merge pull request #24 from advanced-security/copilot/sub-pr-21-another-one
Fix submitSnapshot to return boolean indicating success/failure
2 parents 8e6e341 + 72477cf commit dccef0c

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

package-lock.json

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/componentSubmission.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ export async function submitSnapshotIfPossible(opts: SubmitOpts): Promise<boolea
8181
if (!opts.quiet) console.error(chalk.red(`Failed to determine SHA for ${opts.owner}/${opts.repo} on branch ${opts.branch}`));
8282
return false;
8383
}
84-
await run(opts.octokit, tmp, opts.owner, opts.repo, sha, opts.branch, opts.componentDetectionBinPath);
85-
return true;
84+
return await run(opts.octokit, tmp, opts.owner, opts.repo, sha, opts.branch, opts.componentDetectionBinPath);
85+
8686
} catch (e) {
8787
if (!opts.quiet) console.error(chalk.red(`Component Detection failed: ${(e as Error).message}`));
8888
return false;
@@ -150,7 +150,7 @@ async function execGit(args: string[], opts: { cwd: string, quiet?: boolean }):
150150
});
151151
}
152152

153-
export async function run(octokit: Octokit, tmpDir: string, owner: string, repo: string, sha: string, ref: string, componentDetectionBinPath?: string) {
153+
export async function run(octokit: Octokit, tmpDir: string, owner: string, repo: string, sha: string, ref: string, componentDetectionBinPath?: string): Promise<boolean> {
154154

155155
const componentDetection = new ComponentDetection(octokit, '', componentDetectionBinPath);
156156

@@ -183,20 +183,22 @@ export async function run(octokit: Octokit, tmpDir: string, owner: string, repo:
183183
snapshot.addManifest(manifest);
184184
});
185185

186-
await submitSnapshot(octokit, snapshot, { owner, repo });
186+
return await submitSnapshot(octokit, snapshot, { owner, repo });
187187
}
188188

189189
/**
190190
* submitSnapshot submits a snapshot to the Dependency Submission API - vendored in from @github/dependency-submission-toolkit, to make it work at the CLI, vs in Actions.
191191
*
192-
* @param {Snapshot} snapshot
193-
* @param {Repo} repo
192+
* @param {Octokit} octokit - The Octokit instance for GitHub API requests
193+
* @param {Snapshot} snapshot - The dependency snapshot to submit
194+
* @param {Repo} repo - The repository owner and name
195+
* @returns {Promise<boolean>} true if submission was successful, false otherwise
194196
*/
195197
export async function submitSnapshot(
196198
octokit: Octokit,
197199
snapshot: Snapshot,
198200
repo: { owner: string; repo: string }
199-
) {
201+
): Promise<boolean> {
200202
console.debug('Submitting snapshot...')
201203
console.debug(snapshot.prettyJSON())
202204

@@ -218,10 +220,12 @@ export async function submitSnapshot(
218220
`Snapshot successfully created at ${response.data.created_at.toString()}` +
219221
` with id ${response.data.id}`
220222
)
223+
return true
221224
} else {
222225
console.error(
223226
`Snapshot creation failed with result: "${result}: ${response.data.message}"`
224227
)
228+
return false
225229
}
226230
} catch (error) {
227231
if (error instanceof RequestError) {
@@ -238,6 +242,6 @@ export async function submitSnapshot(
238242
console.error(error.message)
239243
if (error.stack) console.error(error.stack)
240244
}
241-
throw new Error(`Failed to submit snapshot: ${error}`)
245+
return false
242246
}
243247
}

0 commit comments

Comments
 (0)