Skip to content

Commit

Permalink
Project assigned verifier workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Mayank77maruti committed Dec 13, 2024
1 parent 6ffb172 commit 342e76d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 20 deletions.
23 changes: 3 additions & 20 deletions .github/workflows/issue_triage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ jobs:
runs-on: ubuntu-latest
if: github.event.sender.login != 'github-actions'
steps:
- name: Reply to Issue (Only on Opened)
- name: Reply to Issue
if: ${{ github.event.action == 'opened' }}
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.issue.number }}
body: |
Thanks for filing the issue! We’ll review it shortly and route it to the correct team.
- name: Check Labels for Proper Triaging
id: check-labels
uses: actions/github-script@v6
Expand All @@ -35,13 +35,11 @@ jobs:
types: ['bug', 'enhancement', 'good first issue'],
impacts: ['Impact: High', 'Impact: Medium', 'Impact: Low'],
work: ['Work: High', 'Work: Medium', 'Work: Low'],
priorities: ['Priority: Essential', 'Priority: Important', 'Priority: Nice-to-have']
};
const hasTypeLabel = labels.some(label => requiredLabels.types.includes(label));
const hasImpactLabel = labels.some(label => requiredLabels.impacts.includes(label));
const hasWorkLabel = labels.some(label => requiredLabels.work.includes(label));
const hasPriorityLabel = labels.some(label => requiredLabels.priorities.includes(label));
const needsTriage = !(hasTypeLabel && hasImpactLabel && hasWorkLabel && hasPriorityLabel);
const needsTriage = !(hasTypeLabel && hasImpactLabel && hasWorkLabel);
core.setOutput('needs-triage', needsTriage);
- name: Manage Needs Triage Label
Expand Down Expand Up @@ -71,18 +69,3 @@ jobs:
}
}
- name: Verify Project Assignment
uses: actions/github-script@v6
with:
script: |
const projects = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo
});
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}`);
} else {
console.log(`Valid project assignment: ${assignedProjects[0].name}`);
}
68 changes: 68 additions & 0 deletions .github/workflows/project_assigned_verify.yml
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}`);
}

0 comments on commit 342e76d

Please sign in to comment.