Skip to content

Commit a253663

Browse files
Merge pull request #16 from product-os/log-commit-author-and-committer
Log commit current author & committer details
2 parents 276b8a3 + 17935e8 commit a253663

File tree

2 files changed

+172
-28
lines changed

2 files changed

+172
-28
lines changed

src/github.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,30 @@ export const areCommitsVerified = async (
4040
});
4141

4242
// Split commits into verified and unverified
43-
const verifiedCommits: typeof commits = [];
44-
const unverifiedCommits: typeof commits = [];
45-
for (const commit of commits) {
43+
const verifiedCommits = [];
44+
const unverifiedCommits = [];
45+
for (const { sha, commit } of commits) {
46+
// Log each commit's current author and committer
47+
logger.info(
48+
`Processing commit: ${JSON.stringify({
49+
sha,
50+
author: commit.author,
51+
committer: commit.committer,
52+
})}`,
53+
);
4654
if (
47-
commit.commit.verification?.verified &&
48-
commit.commit.verification?.reason === 'valid'
55+
commit.verification?.verified &&
56+
commit.verification?.reason === 'valid'
4957
) {
50-
verifiedCommits.push(commit);
58+
verifiedCommits.push({ sha, commit });
5159
} else {
52-
unverifiedCommits.push(commit);
60+
logger.warn(
61+
`Commit ${sha} is unverified with reason "${commit.verification?.reason}"`,
62+
);
63+
unverifiedCommits.push({ sha, commit });
5364
}
5465
}
5566

56-
// For each unverified commit, log the reason
57-
for (const { sha, commit } of unverifiedCommits) {
58-
logger.warn(
59-
`Commit ${sha} is unverified with reason "${commit.verification?.reason}"`,
60-
);
61-
}
62-
6367
// Only return true if there are no unverified commits
6468
return unverifiedCommits.length === 0;
6569
} catch (error) {

test/index.test.ts

Lines changed: 154 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,17 @@ describe('basejump', () => {
177177
.reply(200, [
178178
{
179179
sha: 'head-sha',
180-
commit: { verification: { verified: true, reason: 'valid' } },
180+
commit: {
181+
verification: { verified: true, reason: 'valid' },
182+
author: {
183+
name: 'Basejump Test Bot',
184+
185+
},
186+
committer: {
187+
name: 'Basejump Test Bot',
188+
189+
},
190+
},
181191
},
182192
])
183193
// This is where the rebase takes place, but it's mocked here so there are no network calls
@@ -248,7 +258,17 @@ describe('basejump', () => {
248258
.reply(200, [
249259
{
250260
sha: 'head-sha',
251-
commit: { verification: { verified: true, reason: 'valid' } },
261+
commit: {
262+
verification: { verified: true, reason: 'valid' },
263+
author: {
264+
name: 'Basejump Test Bot',
265+
266+
},
267+
committer: {
268+
name: 'Basejump Test Bot',
269+
270+
},
271+
},
252272
},
253273
])
254274
// This is where the rebase takes place, but it's mocked here so there are no network calls
@@ -322,7 +342,17 @@ describe('basejump', () => {
322342
.reply(200, [
323343
{
324344
sha: 'head-sha',
325-
commit: { verification: { verified: true, reason: 'valid' } },
345+
commit: {
346+
verification: { verified: true, reason: 'valid' },
347+
author: {
348+
name: 'Basejump Test Bot',
349+
350+
},
351+
committer: {
352+
name: 'Basejump Test Bot',
353+
354+
},
355+
},
326356
},
327357
])
328358
// This is where the rebase takes place, but it's mocked here so there are no network calls
@@ -398,7 +428,17 @@ describe('basejump', () => {
398428
.reply(200, [
399429
{
400430
sha: 'head-sha',
401-
commit: { verification: { verified: true, reason: 'valid' } },
431+
commit: {
432+
verification: { verified: true, reason: 'valid' },
433+
author: {
434+
name: 'Basejump Test Bot',
435+
436+
},
437+
committer: {
438+
name: 'Basejump Test Bot',
439+
440+
},
441+
},
402442
},
403443
])
404444
// This is where the rebase takes place, but it's mocked here so there are no network calls
@@ -523,15 +563,45 @@ describe('basejump', () => {
523563
.reply(200, [
524564
{
525565
sha: 'head-sha-1',
526-
commit: { verification: { verified: true, reason: 'valid' } },
566+
commit: {
567+
verification: { verified: true, reason: 'valid' },
568+
author: {
569+
name: 'Basejump Test Bot',
570+
571+
},
572+
committer: {
573+
name: 'Basejump Test Bot',
574+
575+
},
576+
},
527577
},
528578
{
529579
sha: 'head-sha-2',
530-
commit: { verification: { verified: true, reason: 'valid' } },
580+
commit: {
581+
verification: { verified: true, reason: 'valid' },
582+
author: {
583+
name: 'Basejump Test Bot',
584+
585+
},
586+
committer: {
587+
name: 'Basejump Test Bot',
588+
589+
},
590+
},
531591
},
532592
{
533593
sha: 'head-sha-3',
534-
commit: { verification: { verified: true, reason: 'valid' } },
594+
commit: {
595+
verification: { verified: true, reason: 'valid' },
596+
author: {
597+
name: 'Basejump Test Bot',
598+
599+
},
600+
committer: {
601+
name: 'Basejump Test Bot 2',
602+
603+
},
604+
},
535605
},
536606
])
537607
// This is where the rebase takes place, but it's mocked here so there are no network calls
@@ -603,15 +673,45 @@ describe('basejump', () => {
603673
.reply(200, [
604674
{
605675
sha: 'head-sha-1',
606-
commit: { verification: { verified: false, reason: 'invalid' } },
676+
commit: {
677+
verification: { verified: false, reason: 'invalid' },
678+
author: {
679+
name: 'Untrusted Author',
680+
681+
},
682+
committer: {
683+
name: 'Untrusted Committer',
684+
685+
},
686+
},
607687
},
608688
{
609689
sha: 'head-sha-2',
610-
commit: { verification: { verified: false, reason: 'unsigned' } },
690+
commit: {
691+
verification: { verified: false, reason: 'unsigned' },
692+
author: {
693+
name: 'Unsigned Author',
694+
695+
},
696+
committer: {
697+
name: 'Unsigned Committer',
698+
699+
},
700+
},
611701
},
612702
{
613703
sha: 'head-sha-3',
614-
commit: { verification: { verified: false, reason: 'unknown_key' } },
704+
commit: {
705+
verification: { verified: false, reason: 'unknown_key' },
706+
author: {
707+
name: 'Unknown Key Author',
708+
709+
},
710+
committer: {
711+
name: 'Unknown Key Committer',
712+
713+
},
714+
},
615715
},
616716
])
617717
// This is where the rebase takes place, but it's mocked here so there are no network calls
@@ -689,19 +789,59 @@ describe('basejump', () => {
689789
.reply(200, [
690790
{
691791
sha: 'head-sha-1',
692-
commit: { verification: { verified: true, reason: 'valid' } },
792+
commit: {
793+
verification: { verified: true, reason: 'valid' },
794+
author: {
795+
name: 'Basejump Test Bot',
796+
797+
},
798+
committer: {
799+
name: 'Basejump Test Bot',
800+
801+
},
802+
},
693803
},
694804
{
695805
sha: 'head-sha-2',
696-
commit: { verification: { verified: false, reason: 'unsigned' } },
806+
commit: {
807+
verification: { verified: false, reason: 'unsigned' },
808+
author: {
809+
name: 'Unsigned Author',
810+
811+
},
812+
committer: {
813+
name: 'Unsigned Committer',
814+
815+
},
816+
},
697817
},
698818
{
699819
sha: 'head-sha-3',
700-
commit: { verification: { verified: true, reason: 'valid' } },
820+
commit: {
821+
verification: { verified: true, reason: 'valid' },
822+
author: {
823+
name: 'Basejump Test Bot',
824+
825+
},
826+
committer: {
827+
name: 'Basejump Test Bot',
828+
829+
},
830+
},
701831
},
702832
{
703833
sha: 'head-sha-4',
704-
commit: { verification: { verified: false, reason: 'unknown_key' } },
834+
commit: {
835+
verification: { verified: false, reason: 'unknown_key' },
836+
author: {
837+
name: 'Unknown Key Author',
838+
839+
},
840+
committer: {
841+
name: 'Unknown Key Committer',
842+
843+
},
844+
},
705845
},
706846
])
707847
// This is where the rebase takes place, but it's mocked here so there are no network calls

0 commit comments

Comments
 (0)