-
Notifications
You must be signed in to change notification settings - Fork 1
Add PR title and labels workflows #60
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
Show all changes
19 commits
Select commit
Hold shift + click to select a range
10ffb4c
Update ci.yml
graycampbell b79ef7c
Create PR Labels workflow
graycampbell f0ed7f2
Update pr-labels.yml
graycampbell f87838f
Update pr-labels.yml
graycampbell 45c54d9
Update pr-labels.yml
graycampbell bdd4606
Update pr-labels.yml
graycampbell 600b596
Update pr-labels.yml
graycampbell c90d442
Create pr-title.yml
graycampbell 3d7bf09
Update pr-labels.yml
graycampbell ce67ed5
Create validate-pr-title.js
graycampbell 4af855e
Update pr-title.yml
graycampbell 628e28d
Update validate-pr-title.js
graycampbell 4e0f7f5
Update validate-pr-title.js
graycampbell 8a45b22
Update validate-pr-title.js
graycampbell 6a32512
Update validate-pr-title.js
graycampbell 622b48a
Update pr-labels.yml
graycampbell 87acd9f
Update pr-title.yml
graycampbell 6effb32
Update pr-labels.yml
graycampbell 94d70cb
Update pr-title.yml
graycampbell 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,66 @@ | ||
| const nlp = require('compromise') | ||
| const title = process.env.PR_TITLE || '' | ||
|
|
||
| let isValidTitle = true | ||
|
|
||
| function logSuccess(message) { | ||
| console.log(`✅ ${message}`) | ||
| } | ||
|
|
||
| function logFailure(message) { | ||
| isValidTitle = false | ||
| console.error(`❌ ${message}`) | ||
| } | ||
|
|
||
| function capitalized(string) { | ||
| if (!string) return ''; | ||
| return string[0].toUpperCase() + string.substring(1); | ||
| } | ||
|
|
||
| // Rule 1: PR title must not be empty | ||
| if (title) { | ||
| logSuccess(`PR title is not empty`) | ||
| } else { | ||
| logFailure(`PR title must not be empty`) | ||
| } | ||
|
|
||
| // Rule 2: PR title must be 72 characters or less | ||
| if (title.length <= 72) { | ||
| logSuccess(`PR title is ${title.length} characters`) | ||
| } else { | ||
| logFailure(`PR title must be 72 characters or less (currently ${title.length} characters)`) | ||
| } | ||
|
|
||
| // Rule 3: PR title must begin with a capital letter | ||
| if (/^[A-Z]/.test(title)) { | ||
| logSuccess(`PR title begins with a capital letter`) | ||
| } else { | ||
| logFailure('PR title must begin with a capital letter') | ||
| } | ||
|
|
||
| // Rule 4: PR title must end with a letter or number | ||
| if (/[A-Za-z0-9]$/.test(title)) { | ||
| logSuccess(`PR title ends with a letter or number`) | ||
| } else { | ||
| logFailure('PR title must end with a letter or number') | ||
| } | ||
|
|
||
| // Rule 5: PR title must be written in the imperative | ||
| const firstWord = title.split(' ')[0] | ||
| const firstWordLowercased = firstWord.toLowerCase() | ||
| const firstWordCapitalized = capitalized(firstWord) | ||
| const firstWordAsImperativeVerb = nlp(firstWord).verbs().toInfinitive().out('text') | ||
| const firstWordAsImperativeVerbLowercased = firstWordAsImperativeVerb.toLowerCase() | ||
| const firstWordAsImperativeVerbCapitalized = capitalized(firstWordAsImperativeVerb) | ||
|
|
||
| if (firstWordLowercased === firstWordAsImperativeVerbLowercased) { | ||
| logSuccess(`PR title is written in the imperative`) | ||
| } else if (firstWordAsImperativeVerb) { | ||
| logFailure(`PR title must be written in the imperative ("${firstWordAsImperativeVerbCapitalized}" instead of "${firstWordCapitalized}")`) | ||
| } else { | ||
| logFailure(`PR title must begin with a verb and be written in the imperative`) | ||
| } | ||
|
|
||
| if (!isValidTitle) { | ||
| process.exit(1) | ||
| } |
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 |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ on: | |
| branches: | ||
| - main | ||
| pull_request: | ||
| types: [opened, reopened, synchronize] | ||
| branches: | ||
| - '*' | ||
|
|
||
|
|
||
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,44 @@ | ||
| name: PR Labels | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, labeled, unlabeled, reopened, synchronize] | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: read | ||
|
|
||
| jobs: | ||
| check-for-required-labels: | ||
| name: Check For Required Labels | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout source code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Validate PR has required labels | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| PR_NUMBER=${{ github.event.pull_request.number }} | ||
| REPO=${{ github.repository }} | ||
|
|
||
| REQUIRED_LABELS=("bug" "ci/cd" "documentation" "enhancement" "formatting" "refactoring" "testing") | ||
| LABELS=$(gh pr view "$PR_NUMBER" --repo "$REPO" --json labels --jq '.labels[].name') | ||
|
|
||
| echo "PR labels:" | ||
| echo "$LABELS" | ||
|
|
||
| for required in "${REQUIRED_LABELS[@]}"; do | ||
| if echo "$LABELS" | grep -q "^$required$"; then | ||
| echo "✅ Found required label: $required" | ||
| exit 0 | ||
| fi | ||
| done | ||
|
|
||
| echo "❌ PR is missing a required label." | ||
| echo "At least one of the following labels is required:" | ||
| printf '%s\n' "${REQUIRED_LABELS[@]}" | ||
| exit 1 | ||
| 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 |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| name: PR Title | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, edited, reopened, synchronize] | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: read | ||
|
|
||
| jobs: | ||
| validate-pr-title: | ||
| name: Validate PR Title | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout source code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: latest | ||
|
|
||
| - name: Install dependencies | ||
| run: npm install compromise | ||
|
|
||
| - name: Validate PR title | ||
| run: node .github/scripts/validate-pr-title.js | ||
| env: | ||
| PR_TITLE: ${{ github.event.pull_request.title }} |
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.
Uh oh!
There was an error while loading. Please reload this page.