Skip to content

Commit 410f95e

Browse files
Copilotaegilops
andcommitted
Fix latestCommitDate to use actual commit date from API
Co-authored-by: aegilops <[email protected]>
1 parent 15bd0e9 commit 410f95e

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
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/sbomCollector.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ export class SbomCollector {
315315
console.error(chalk.red(`Force submission failed for ${fullName} branch ${b.name}: ${(subErr as Error).message}`));
316316
}
317317
}
318-
const diff = await this.fetchDependencyReviewDiff(org, repo.name, base, b.name);
318+
const diff = await this.fetchDependencyReviewDiff(org, repo.name, base, b.name, latestCommit);
319319
branchDiffs.set(b.name, diff);
320320
}
321321
if (branchDiffs.size) sbom.branchDiffs = branchDiffs;
@@ -483,7 +483,7 @@ export class SbomCollector {
483483
return branches;
484484
}
485485

486-
private async fetchDependencyReviewDiff(org: string, repo: string, base: string, head: string): Promise<BranchDependencyDiff> {
486+
private async fetchDependencyReviewDiff(org: string, repo: string, base: string, head: string, latestCommit?: { sha?: string; commitDate?: string }): Promise<BranchDependencyDiff> {
487487
if (!this.octokit) throw new Error("No Octokit instance");
488488
try {
489489
const basehead = `${base}...${head}`;
@@ -506,7 +506,7 @@ export class SbomCollector {
506506
};
507507
changes.push(change);
508508
}
509-
return { latestCommitDate: new Date().toISOString(), base, head, retrievedAt: new Date().toISOString(), changes };
509+
return { latestCommitDate: latestCommit?.commitDate || new Date().toISOString(), base, head, retrievedAt: new Date().toISOString(), changes };
510510
} catch (e) {
511511
const status = (e as { status?: number })?.status;
512512
let reason = e instanceof Error ? e.message : String(e);
@@ -520,15 +520,15 @@ export class SbomCollector {
520520
if (ok) {
521521
console.log(chalk.blue(`Snapshot submission attempted; waiting 3 seconds before retrying dependency review diff for ${org}/${repo} ${base}...${head}...`));
522522
await new Promise(r => setTimeout(r, 3000));
523-
return await this.fetchDependencyReviewDiff(org, repo, base, head);
523+
return await this.fetchDependencyReviewDiff(org, repo, base, head, latestCommit);
524524
}
525525
} catch (subErr) {
526526
console.error(chalk.red(`Snapshot submission failed for ${org}/${repo} branch ${head}: ${(subErr as Error).message}`));
527527
reason += ` (submission attempt failed: ${(subErr as Error).message})`;
528528
}
529529
}
530530
}
531-
return { latestCommitDate: new Date().toISOString(), base, head, retrievedAt: new Date().toISOString(), changes: [], error: reason };
531+
return { latestCommitDate: latestCommit?.commitDate || new Date().toISOString(), base, head, retrievedAt: new Date().toISOString(), changes: [], error: reason };
532532
}
533533
}
534534

0 commit comments

Comments
 (0)