-
Notifications
You must be signed in to change notification settings - Fork 54
chore: enforce planning label rules for issues #421
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
google-oss-prow
merged 1 commit into
kubeflow:main
from
andyatmiami:chore/planning-labels-gha
Jul 24, 2025
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,126 @@ | ||
name: Validate Planning Issue | ||
|
||
on: | ||
issues: | ||
types: [opened, labeled] | ||
|
||
env: | ||
AUTHORIZED_USERS: '["thesuperzapper", "ederign", "andyatmiami", "paulovmr", "jenny_s51", "harshad16", "thaorell", "kimwnasptd"]' | ||
|
||
permissions: | ||
issues: write | ||
|
||
jobs: | ||
validate-issue: | ||
if: | | ||
(github.event.action == 'labeled' && (github.event.label.name == 'kind/plan-epic' || github.event.label.name == 'kind/plan-feature' || github.event.label.name == 'kind/plan-task')) || | ||
(github.event.action == 'opened' && (contains(github.event.issue.labels.*.name, 'kind/plan-epic') || contains(github.event.issue.labels.*.name, 'kind/plan-feature') || contains(github.event.issue.labels.*.name, 'kind/plan-task'))) | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Log trigger | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
console.log(`Action triggered by: ${context.eventName} event with action: ${context.payload.action}`); | ||
if (context.payload.action === 'labeled') { | ||
console.log(`Label added: ${context.payload.label.name}`); | ||
} else if (context.payload.action === 'opened') { | ||
console.log(`Issue opened with labels: ${context.payload.issue.labels.map(l => l.name).join(', ')}`); | ||
} | ||
|
||
- name: Handle labeled action | ||
if: github.event.action == 'labeled' | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const AUTHORIZED_USERS = JSON.parse(process.env.AUTHORIZED_USERS); | ||
const actor = context.actor; | ||
const issueNumber = context.issue.number; | ||
const addedLabel = context.payload.label.name; | ||
|
||
// First check user authorization | ||
if (!AUTHORIZED_USERS.includes(actor)) { | ||
// Remove the planning label | ||
await github.rest.issues.removeLabel({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: issueNumber, | ||
name: addedLabel | ||
}); | ||
|
||
// Add a comment explaining why the label was removed | ||
await github.rest.issues.createComment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: issueNumber, | ||
body: `@${actor} You are not authorized to add planning labels. Only authorized users can add planning labels to issues.` | ||
}); | ||
|
||
core.setFailed(`User ${actor} is not authorized to add planning labels`); | ||
} | ||
|
||
console.log(`User ${actor} is authorized to add planning labels`); | ||
|
||
// Then check planning label requirements | ||
const { data: issue } = await github.rest.issues.get({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: issueNumber | ||
}); | ||
|
||
const currentLabels = issue.labels.map(label => label.name); | ||
const planningLabels = ['kind/plan-epic', 'kind/plan-feature', 'kind/plan-task']; | ||
const presentPlanningLabels = currentLabels.filter(label => planningLabels.includes(label)); | ||
|
||
if (presentPlanningLabels.length !== 1) { | ||
// Remove the planning label | ||
await github.rest.issues.removeLabel({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: issueNumber, | ||
name: addedLabel | ||
}); | ||
|
||
// Add a comment explaining why the label was removed | ||
await github.rest.issues.createComment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: issueNumber, | ||
body: `@${actor} Planning labels require exactly one planning label to be present: ${planningLabels.join(', ')}. Please ensure only one planning label is applied.` | ||
}); | ||
|
||
core.setFailed(`Planning labels require exactly one of: ${planningLabels.join(', ')}`); | ||
} | ||
|
||
console.log(`Issue has valid planning label: ${presentPlanningLabels[0]}`); | ||
|
||
- name: Handle opened action | ||
if: github.event.action == 'opened' | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const AUTHORIZED_USERS = JSON.parse(process.env.AUTHORIZED_USERS); | ||
const actor = context.actor; | ||
const issueNumber = context.issue.number; | ||
|
||
if (!AUTHORIZED_USERS.includes(actor)) { | ||
// Add a comment explaining why the issue will be closed | ||
await github.rest.issues.createComment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: issueNumber, | ||
body: `@${actor} You are not authorized to create planning issues. Only authorized users can create planning issues.` | ||
}); | ||
|
||
// Close the issue | ||
await github.rest.issues.update({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: issueNumber, | ||
state: 'closed' | ||
}); | ||
|
||
core.setFailed(`User ${actor} is not authorized to create planning issues`); | ||
} | ||
|
||
console.log(`User ${actor} is authorized to create planning issues`); |
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.
Uh oh!
There was an error while loading. Please reload this page.