Skip to content

Commit

Permalink
fix: always set commit PR from associated PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Nov 26, 2023
1 parent 0aed8cf commit c7ed88c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 18 deletions.
20 changes: 20 additions & 0 deletions __snapshots__/github.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 28 additions & 18 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,21 +487,24 @@ export class GitHub {
sha: graphCommit.sha,
message: graphCommit.message,
};
const pullRequest = graphCommit.associatedPullRequests.nodes.find(pr => {
return (
// Only match the pull request with a merge commit if there is a
// single merged commit in the PR. This means merge commits and squash
// merges will be matched, but rebase merged PRs will only be matched
// if they contain a single commit. This is so PRs that are rebased
// and merged will have files backfilled from each commit instead of
// the whole PR.
pr.mergeCommit &&
pr.mergeCommit.oid === graphCommit.sha &&
mergeCommitCount[pr.mergeCommit.oid] === 1
);
});
const mergePullRequest = graphCommit.associatedPullRequests.nodes.find(
pr => {
return (
// Only match the pull request with a merge commit if there is a
// single merged commit in the PR. This means merge commits and squash
// merges will be matched, but rebase merged PRs will only be matched
// if they contain a single commit. This is so PRs that are rebased
// and merged will have ßSfiles backfilled from each commit instead of
// the whole PR.
pr.mergeCommit &&
pr.mergeCommit.oid === graphCommit.sha &&
mergeCommitCount[pr.mergeCommit.oid] === 1
);
}
);
const pullRequest =
mergePullRequest || graphCommit.associatedPullRequests.nodes[0];
if (pullRequest) {
const files = (pullRequest.files?.nodes || []).map(node => node.path);
commit.pullRequest = {
sha: commit.sha,
number: pullRequest.number,
Expand All @@ -510,17 +513,24 @@ export class GitHub {
title: pullRequest.title,
body: pullRequest.body,
labels: pullRequest.labels.nodes.map(node => node.name),
files,
files: (pullRequest.files?.nodes || []).map(node => node.path),
};
if (pullRequest.files?.pageInfo?.hasNextPage && options.backfillFiles) {
}
if (mergePullRequest) {
if (
mergePullRequest.files?.pageInfo?.hasNextPage &&
options.backfillFiles
) {
this.logger.info(
`PR #${pullRequest.number} has many files, backfilling`
`PR #${mergePullRequest.number} has many files, backfilling`
);
commit.files = await this.getCommitFiles(graphCommit.sha);
} else {
// We cannot directly fetch files on commits via graphql, only provide file
// information for commits with associated pull requests
commit.files = files;
commit.files = (mergePullRequest.files?.nodes || []).map(
node => node.path
);
}
} else if (options.backfillFiles) {
// In this case, there is no squashed merge commit. This could be a simple
Expand Down

0 comments on commit c7ed88c

Please sign in to comment.