Skip to content

Commit 3e26ab6

Browse files
authored
fix(filter-paths): support merge queue refs (#689)
1 parent e2be656 commit 3e26ab6

File tree

4 files changed

+42
-15
lines changed

4 files changed

+42
-15
lines changed

dist/654.index.js

Lines changed: 11 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/654.index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/helpers/filter-paths.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,22 @@ export class FilterPaths extends HelperInputs {
2424
}
2525

2626
export const filterPaths = async ({ paths, globs, sha }: FilterPaths) => {
27-
const prNumberFromSha = sha
28-
? (
29-
await octokit.repos.listPullRequestsAssociatedWithCommit({
30-
commit_sha: sha,
31-
...context.repo
32-
})
33-
).data.find(Boolean)?.number
34-
: undefined;
27+
const prNumberFromSha =
28+
context.eventName === 'merge_group'
29+
? Number(
30+
context.ref
31+
.split('/')
32+
.find(part => part.includes('pr-'))
33+
?.match(/\d+/)?.[0]
34+
)
35+
: sha
36+
? (
37+
await octokit.repos.listPullRequestsAssociatedWithCommit({
38+
commit_sha: sha,
39+
...context.repo
40+
})
41+
).data.find(Boolean)?.number
42+
: undefined;
3543
const pull_number = prNumberFromSha ?? context.issue.number;
3644

3745
const { data } = await octokit.pulls.listFiles({

test/helpers/filter-paths.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,18 @@ describe('filterPaths', () => {
208208

209209
expect(octokit.repos.listPullRequestsAssociatedWithCommit).not.toHaveBeenCalled();
210210
});
211+
212+
it('should not call listPullRequestsAssociatedWithCommit if sha is omitted', async () => {
213+
context.eventName = 'merge_group';
214+
context.ref = 'refs/heads/gh-readonly-queue/branch-name/pr-12345-f0d9a4cb862b13cdaab6522f72d6dc17e4336b7f';
215+
await filterPaths({
216+
paths
217+
});
218+
219+
expect(octokit.pulls.listFiles).toHaveBeenCalledWith({
220+
per_page: 100,
221+
pull_number: 12345,
222+
...context.repo
223+
});
224+
});
211225
});

0 commit comments

Comments
 (0)