Skip to content

Commit fa38c73

Browse files
Handle Merge Queues
1 parent 59e8544 commit fa38c73

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,44 @@ jobs:
215215
GITHUB_TOKEN: ${{ github.token }}
216216
```
217217
218+
### Using with merge queues
219+
220+
If you are using merge queues, you will need to add the `merge_group` event to your workflow's `on:` clause. This will ensure that the action is triggered when a pull request is added to the merge queue.
221+
222+
For instance
223+
224+
```yaml
225+
# .github/workflows/ci.yml
226+
name: CI
227+
228+
on:
229+
pull_request:
230+
merge_group:
231+
232+
jobs:
233+
test:
234+
name: Run tests & display coverage
235+
runs-on: ubuntu-latest
236+
permissions:
237+
# Gives the action the necessary permissions for publishing new
238+
# comments in pull requests.
239+
pull-requests: write
240+
# Gives the action the necessary permissions for pushing data to the
241+
# python-coverage-comment-action branch, and for editing existing
242+
# comments (to avoid publishing multiple comments in the same PR)
243+
contents: write
244+
steps:
245+
- uses: actions/checkout@v4
246+
247+
- name: Install everything, run the tests, produce the .coverage file
248+
run: make test # This is the part where you put your own test command
249+
250+
- name: Coverage comment
251+
uses: py-cov-action/python-coverage-comment-action@v3
252+
with:
253+
GITHUB_TOKEN: ${{ github.token }}
254+
```
255+
218256
### Merging multiple coverage reports
219257

220258
In case you have a job matrix and you want the report to be on the global

coverage_comment/activity.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ def find_activity(
2727
(event_name == "push" and is_default_branch)
2828
or event_name == "schedule"
2929
or (event_name == "pull_request" and event_type == "closed")
30+
or event_name == "merge_group"
3031
):
3132
if event_name == "pull_request" and event_type == "closed" and not is_pr_merged:
3233
raise ActivityNotFound
3334
return "save_coverage_data_files"
3435

35-
if event_name not in {"pull_request", "push"}:
36+
if event_name not in {"pull_request", "push", "merge_group"}:
3637
raise ActivityNotFound
3738

3839
return "process_pr"

coverage_comment/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def action(
8383
except activity_module.ActivityNotFound:
8484
log.error(
8585
'This action has only been designed to work for "pull_request", "push", '
86-
f'"workflow_run" or "schedule" actions, not "{event_name}". Because there '
86+
f'"workflow_run", "schedule" or "merge_group" actions, not "{event_name}". Because there '
8787
"are security implications. If you have a different usecase, please open an issue, "
8888
"we'll be glad to add compatibility."
8989
)

tests/unit/test_activity.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
("pull_request", True, None, False, "process_pr"),
1616
("pull_request", False, None, False, "process_pr"),
1717
("schedule", False, None, False, "save_coverage_data_files"),
18+
("merge_group", False, None, False, "save_coverage_data_files"),
1819
],
1920
)
2021
def test_find_activity(

0 commit comments

Comments
 (0)