From 342e76d4226fafa676c61ba9339ed57c8f01f549 Mon Sep 17 00:00:00 2001 From: Mayank77maruti <125661248+Mayank77maruti@users.noreply.github.com> Date: Fri, 13 Dec 2024 19:10:25 +0530 Subject: [PATCH] Project assigned verifier workflow --- .github/workflows/issue_triage.yml | 23 +------ .github/workflows/project_assigned_verify.yml | 68 +++++++++++++++++++ 2 files changed, 71 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/project_assigned_verify.yml diff --git a/.github/workflows/issue_triage.yml b/.github/workflows/issue_triage.yml index addd536b65e..f2cc394a19d 100644 --- a/.github/workflows/issue_triage.yml +++ b/.github/workflows/issue_triage.yml @@ -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 @@ -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 @@ -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}`); - } - \ No newline at end of file diff --git a/.github/workflows/project_assigned_verify.yml b/.github/workflows/project_assigned_verify.yml new file mode 100644 index 00000000000..a095d63e872 --- /dev/null +++ b/.github/workflows/project_assigned_verify.yml @@ -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}`); + } + + \ No newline at end of file