-
Notifications
You must be signed in to change notification settings - Fork 527
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6ffb172
commit 342e76d
Showing
2 changed files
with
71 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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 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,68 @@ | ||
name: Verify Project Assignment | ||
|
||
on: | ||
issues: | ||
types: [labeled] | ||
|
||
permissions: | ||
issues: write | ||
|
||
jobs: | ||
verify-project-assignment: | ||
runs-on: ubuntu-latest | ||
if: github.event.sender.login != 'github-actions' | ||
steps: | ||
- name: Check if Label is an Impact Label | ||
id: check-impact-label | ||
run: | | ||
if [[ "${{ github.event.label.name }}" == "Impact: High" ]] || \ | ||
[[ "${{ github.event.label.name }}" == "Impact: Medium" ]] || \ | ||
[[ "${{ github.event.label.name }}" == "Impact: Low" ]]; then | ||
echo "impact_label=true" >> $GITHUB_ENV | ||
else | ||
echo "impact_label=false" >> $GITHUB_ENV | ||
fi | ||
- name: Verify Project Assignment | ||
if: env.impact_label == 'true' | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
const issueNumber = context.issue.number; | ||
// Fetch all open projects in the repository | ||
const projects = await github.rest.projects.listForRepo({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
}); | ||
// Filter to get only open projects | ||
const assignedProjects = projects.data.filter(project => project.state === 'open'); | ||
if (assignedProjects.length !== 1) { | ||
console.warn(`Issue must be assigned to exactly one open project. Found: ${assignedProjects.length}`); | ||
// Add a comment to notify about incorrect project assignment | ||
const existingComments = await github.rest.issues.listComments({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: issueNumber, | ||
}); | ||
const commentAlreadyExists = existingComments.data.some(comment => | ||
comment.body.includes('Gentle Reminder: This issue must be assigned to exactly one open project') | ||
); | ||
if (!commentAlreadyExists) { | ||
await github.rest.issues.createComment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: issueNumber, | ||
body: `Gentle Reminder: This issue must be assigned to exactly one open project. Currently, ${assignedProjects.length} projects are assigned. Thanks.`, | ||
}); | ||
} | ||
} else { | ||
console.log(`Valid project assignment: ${assignedProjects[0].name}`); | ||
} | ||