Skip to content

Commit

Permalink
Handle null pointer when merge commit is missing (#498)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv authored Apr 4, 2024
1 parent 24dc0f8 commit bea96d0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/lib/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export function getChoicesForCommitPrompt(
name = `${position}${message} ${pullStatus}`;
}

const short = c.sourcePullRequest
const short = c.sourcePullRequest?.mergeCommit
? `#${c.sourcePullRequest.number} (${getShortSha(
c.sourcePullRequest.mergeCommit.sha,
)})`
Expand Down
10 changes: 6 additions & 4 deletions src/lib/sourceCommit/getPullRequestStates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@ export function getPullRequestStates({
state: 'MERGED' as const,
url: sourcePullRequest.url,
number: sourcePullRequest.number,
mergeCommit: {
message: sourcePullRequest.mergeCommit.message,
sha: sourcePullRequest.mergeCommit.sha,
},
mergeCommit: sourcePullRequest.mergeCommit
? {
message: sourcePullRequest.mergeCommit.message,
sha: sourcePullRequest.mergeCommit.sha,
}
: undefined,
};
}

Expand Down
17 changes: 10 additions & 7 deletions src/lib/sourceCommit/parseSourceCommit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface Commit {
labels: string[];
number: number;
url: string;
mergeCommit: {
mergeCommit?: {
message: string;
sha: string;
};
Expand All @@ -45,7 +45,7 @@ export interface SourcePullRequestNode {
name: string;
}[];
};
mergeCommit: {
mergeCommit?: {
remoteConfigHistory: RemoteConfigHistory['remoteConfigHistory'];
sha: string;
message: string;
Expand Down Expand Up @@ -171,10 +171,12 @@ export function parseSourceCommit({
title: sourcePullRequest.title,
number: sourcePullRequest.number,
url: sourcePullRequest.url,
mergeCommit: {
message: sourcePullRequest.mergeCommit.message,
sha: sourcePullRequest.mergeCommit.sha,
},
mergeCommit: sourcePullRequest.mergeCommit
? {
message: sourcePullRequest.mergeCommit.message,
sha: sourcePullRequest.mergeCommit.sha,
}
: undefined,
}
: undefined,
sourceBranch: sourcePullRequest?.baseRefName ?? options.sourceBranch,
Expand Down Expand Up @@ -278,7 +280,8 @@ function getSourceCommitBranchLabelMapping(
const sourcePullRequest = getSourcePullRequest(sourceCommit);

const remoteConfig =
sourcePullRequest?.mergeCommit.remoteConfigHistory.edges?.[0]?.remoteConfig;
sourcePullRequest?.mergeCommit?.remoteConfigHistory.edges?.[0]
?.remoteConfig;

if (remoteConfig) {
return parseRemoteConfigFile(remoteConfig)?.branchLabelMapping;
Expand Down

0 comments on commit bea96d0

Please sign in to comment.