-
Notifications
You must be signed in to change notification settings - Fork 2
GH-127: Add PR label check #222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| name: "Setup Python" | ||
| description: "Setup the correct version of python" | ||
|
|
||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: 3.13 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| name: PR Label Check | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, labeled, unlabeled] | ||
|
|
||
| jobs: | ||
| validate-labels: | ||
| name: Validate release label | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: ./.github/actions/setup-python | ||
| - name: Check PR has exactly one release label | ||
| run: | | ||
| python scripts/pr_label_check.py "$GITHUB_EVENT_PATH" | ||
| shell: bash |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,9 +65,6 @@ Lastly, edit this config file to your liking: | |
| * Check your [core.hooksPath](https://git-scm.com/docs/githooks) - this setting can be `--global` or by repository. Check this first. | ||
| * #### The hook is having a runtime error | ||
| * Please submit an issue with the terminal output you received [here](https://github.com/unthreaded/git-hooks/issues) with as much detail as possible. | ||
|
|
||
| ## Development details | ||
| For Mac, you must install some dependencies via brew. Simply run [`os_specific_requirements.py`](scripts/os_specific_requirements.py) and you'll be good to go! | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A couple weeks ago I was reading this: https://pyinstaller.org/en/stable/usage.html#using-upx Turns out PyInstaller no longer references this |
||
|
|
||
| ## Contributing | ||
| [How to contribute](./CONTRIBUTING.md) | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| """ | ||
| Ensure a pull request has exactly one version label | ||
| """ | ||
| import os | ||
| import sys | ||
| import json | ||
|
|
||
| VALID_LABELS = {'Patch', 'Minor', 'Major', "no-release"} | ||
|
|
||
| def extract_labels_from_event(event_file: str) -> set[str]: | ||
| """Extract label names from a GitHub event JSON file. | ||
|
|
||
| Args: | ||
| event_file: Path to the JSON event file produced by GitHub Actions. | ||
|
|
||
| Returns: | ||
| A set of label names (strings) found on the pull request. | ||
| """ | ||
| with open(event_file, 'r', encoding='utf-8') as f: | ||
| payload = json.load(f) | ||
| labels = payload.get('pull_request', {}).get('labels', []) | ||
| return {str(lbl.get('name', '')).strip() for lbl in labels} | ||
|
|
||
|
|
||
| def are_labels_valid(labels_on_pr: set[str]) -> bool: | ||
| """Check whether the PR has exactly one allowed version label. | ||
|
|
||
| Args: | ||
| labels_on_pr: Set of label names present on the pull request. | ||
|
|
||
| Returns: | ||
| True if exactly one label from VALID_LABELS is present; otherwise False. | ||
| """ | ||
| print(f"Found labels on pull request: {labels_on_pr}") | ||
| overlap = VALID_LABELS.intersection(labels_on_pr) | ||
| return len(overlap) == 1 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| print("Checking pull request labels") | ||
| event_path = sys.argv[1] | ||
| success: bool = False | ||
| if event_path and os.path.isfile(event_path): | ||
| all_labels = extract_labels_from_event(event_path) | ||
| success = are_labels_valid(all_labels) | ||
| else: | ||
| print("No labels found") | ||
|
|
||
| if not success: | ||
| print(f"Did not find exactly one of the following labels: {VALID_LABELS}") | ||
|
|
||
| sys.exit(0 if success else 1) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we'd need this if we were calling
./scripts/lint.pyrather thanpython scripts/lint.ptOne less thing to read in this file