|
1 | | -"""Labels PRs and process based on bot comment checkboxes.""" |
| 1 | +"""Labels PRs based on bot comment checkboxes.""" |
2 | 2 |
|
3 | 3 | import json |
4 | 4 | import os |
5 | 5 | import sys |
6 | 6 |
|
| 7 | +from _commons import label_options |
7 | 8 | from github import Github |
8 | 9 |
|
9 | 10 | context_dict = json.loads(os.getenv("CONTEXT_GITHUB")) |
|
17 | 18 | comment_user = context_dict["event"]["comment"]["user"]["login"] |
18 | 19 | labels = [label.name for label in issue.get_labels()] |
19 | 20 |
|
| 21 | + |
20 | 22 | if ( |
21 | | - issue.pull_request is None |
| 23 | + "[bot]" in context_dict["event"]["sender"]["login"] |
| 24 | + or issue.pull_request is None |
22 | 25 | or comment_user != "aeon-actions-bot[bot]" |
23 | 26 | or "## Thank you for contributing to `aeon`" not in comment_body |
24 | 27 | ): |
25 | 28 | with open(os.environ["GITHUB_OUTPUT"], "a") as fh: |
| 29 | + print("expected_results=false", file=fh) # noqa: T201 |
26 | 30 | print("empty_commit=false", file=fh) # noqa: T201 |
27 | 31 | sys.exit(0) |
28 | | -pr = issue.as_pull_request() |
29 | | - |
30 | | - |
31 | | -def check_label_option(label, option): |
32 | | - """Add or remove a label based on a checkbox in a comment.""" |
33 | | - if f"- [x] {option}" in comment_body: |
34 | | - if label not in labels: |
35 | | - pr.add_to_labels(label) |
36 | | - elif f"- [ ] {option}" in comment_body: |
37 | | - if label in labels: |
38 | | - pr.remove_from_labels(label) |
39 | | - |
40 | 32 |
|
41 | | -label_options = [ |
42 | | - ("full pre-commit", "Run `pre-commit` checks for all files"), |
43 | | - ("run typecheck test", "Run `mypy` typecheck tests"), |
44 | | - ("full pytest actions", "Run all `pytest` tests and configurations"), |
45 | | - ("full examples run", "Run all notebook example tests"), |
46 | | - ("codecov actions", "Run numba-disabled `codecov` tests"), |
47 | | - ( |
48 | | - "stop pre-commit fixes", |
49 | | - "Stop automatic `pre-commit` fixes (always disabled for drafts)", |
50 | | - ), |
51 | | - ("no numba cache", "Disable numba cache loading"), |
52 | | -] |
| 33 | +pr = issue.as_pull_request() |
| 34 | +comment = pr.get_issue_comment(context_dict["event"]["comment"]["id"]) |
53 | 35 |
|
54 | 36 | for option in label_options: |
55 | | - check_label_option(option[0], option[1]) |
| 37 | + if f"- [x] {option[1]}" in comment_body and option[0] not in labels: |
| 38 | + pr.add_to_labels(option[0]) |
| 39 | + elif f"- [ ] {option[1]}" in comment_body and option[0] in labels: |
| 40 | + pr.remove_from_labels(option[0]) |
56 | 41 |
|
57 | 42 | repo_name = pr.head.repo.full_name |
58 | 43 | branch_name = pr.head.ref |
59 | 44 | with open(os.environ["GITHUB_OUTPUT"], "a") as fh: |
60 | 45 | print(f"repo={repo_name}", file=fh) # noqa: T201 |
61 | 46 | print(f"branch={branch_name}", file=fh) # noqa: T201 |
62 | 47 |
|
| 48 | +if "- [x] Regenerate expected results for testing" in comment_body: |
| 49 | + with open(os.environ["GITHUB_OUTPUT"], "a") as fh: |
| 50 | + print("expected_results=true", file=fh) # noqa: T201 |
| 51 | +else: |
| 52 | + with open(os.environ["GITHUB_OUTPUT"], "a") as fh: |
| 53 | + print("expected_results=false", file=fh) # noqa: T201 |
| 54 | + |
63 | 55 | if "- [x] Push an empty commit to re-run CI checks" in comment_body: |
64 | | - for comment in pr.get_comments(): |
65 | | - if ( |
66 | | - comment.user.login == comment_user |
67 | | - and "## Thank you for contributing to `aeon`" in comment.body |
68 | | - ): |
69 | | - comment.edit( |
70 | | - comment_body.replace( |
71 | | - "- [x] Push an empty commit to re-run CI checks", |
72 | | - "- [ ] Push an empty commit to re-run CI checks", |
73 | | - ) |
74 | | - ) |
75 | | - break |
76 | 56 | with open(os.environ["GITHUB_OUTPUT"], "a") as fh: |
77 | 57 | print("empty_commit=true", file=fh) # noqa: T201 |
78 | 58 | else: |
|
0 commit comments