Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/github/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ interface PageInfo {
export interface MergedEvent {
__typename: string;
id: string;
actor: Actor;
actor: Actor | null;
createdAt: string;
mergeRef: {
name: string;
};
} | null;
mergeRefName: string;
Comment thread
alexr00 marked this conversation as resolved.
commit: {
oid: string;
commitUrl: string;
Expand Down Expand Up @@ -194,12 +195,12 @@ export interface Commit {
id: string;
commit: {
author: {
user: Account;
};
user: Account | null;
} | null;
committer: {
avatarUrl: string;
name: string;
};
} | null;
oid: string;
message: string;
committedDate: Date;
Expand Down
1 change: 1 addition & 0 deletions src/github/queriesShared.gql
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ fragment Merged on MergedEvent {
mergeRef {
name
}
mergeRefName
commit {
oid
commitUrl
Expand Down
6 changes: 3 additions & 3 deletions src/github/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1307,9 +1307,9 @@ export async function parseCombinedTimelineEvents(
id: commitEv.id,
event: type,
sha: commitEv.commit.oid,
author: commitEv.commit.author.user
author: commitEv.commit.author?.user
? parseAccount(commitEv.commit.author.user, githubRepository)
: { login: commitEv.commit.committer.name },
: { login: commitEv.commit.committer?.name ?? '' },
Comment thread
alexr00 marked this conversation as resolved.
htmlUrl: commitEv.url,
message: commitEv.commit.message,
committedDate: new Date(commitEv.commit.committedDate),
Expand Down Expand Up @@ -1337,7 +1337,7 @@ export async function parseCombinedTimelineEvents(
event: type,
user: parseActor(mergeEv.actor, githubRepository),
createdAt: mergeEv.createdAt,
mergeRef: mergeEv.mergeRef.name,
mergeRef: mergeEv.mergeRef?.name ?? mergeEv.mergeRefName,
sha: mergeEv.commit.oid,
commitUrl: mergeEv.commit.commitUrl,
url: mergeEv.url,
Expand Down
49 changes: 48 additions & 1 deletion src/test/github/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

import { default as assert } from 'assert';
import { AccountType } from '../../github/interface';
import { getPRFetchQuery, insertNewCommitsSinceReview, sanitizeIssueTitle, variableSubstitution } from '../../github/utils';
import { getPRFetchQuery, insertNewCommitsSinceReview, parseCombinedTimelineEvents, sanitizeIssueTitle, variableSubstitution } from '../../github/utils';
import { IssueModel } from '../../github/issueModel';
import { GitHubRef } from '../../common/githubRef';
import { CommitEvent, EventType, ReviewEvent, TimelineEvent } from '../../common/timelineEvent';
import * as GraphQL from '../../github/graphql';
import { GitHubRepository } from '../../github/githubRepository';

describe('utils', () => {

Expand Down Expand Up @@ -80,6 +82,51 @@ describe('utils', () => {
});
});

describe('parseCombinedTimelineEvents', () => {
it('handles commits without an author or committer', async () => {
const commit = {
__typename: 'PullRequestCommit',
id: 'commit-id',
commit: {
author: null,
committer: null,
oid: 'sha',
message: 'Commit message',
committedDate: new Date('2024-01-01T12:00:00Z'),
},
url: 'https://github.com/octocat/repo/commit/sha',
} satisfies GraphQL.Commit;

const events = await parseCombinedTimelineEvents([commit], [], {} as GitHubRepository);
Comment thread
alexr00 marked this conversation as resolved.

assert.strictEqual(events.length, 1);
assert.strictEqual(events[0].event, EventType.Committed);
assert.strictEqual((events[0] as CommitEvent).author.login, '');
});

it('handles merged events whose merge ref was deleted', async () => {
const mergedEvent = {
__typename: 'MergedEvent',
id: 'merged-event-id',
actor: null,
createdAt: '2024-01-01T12:00:00Z',
mergeRef: null,
mergeRefName: 'main',
commit: {
oid: 'sha',
commitUrl: 'https://github.com/octocat/repo/commit/sha',
},
url: 'https://github.com/octocat/repo/pull/1',
} satisfies GraphQL.MergedEvent;

const events = await parseCombinedTimelineEvents([mergedEvent], [], {} as GitHubRepository);
Comment thread
alexr00 marked this conversation as resolved.

assert.strictEqual(events.length, 1);
assert.strictEqual(events[0].event, EventType.Merged);
assert.strictEqual(events[0].mergeRef, 'main');
});
});

describe('insertNewCommitsSinceReview', () => {
const CURRENT_USER = 'octocat';
const LATEST_REVIEW_SHA = 'shaA';
Expand Down
Loading