From 60d963796f5560f22a3132225098573cabae40ed Mon Sep 17 00:00:00 2001 From: Mayank77maruti <125661248+Mayank77maruti@users.noreply.github.com> Date: Thu, 5 Dec 2024 23:30:49 +0530 Subject: [PATCH 1/7] issue triaging github action added --- .github/workflows/issue_triage.yml | 91 ++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 .github/workflows/issue_triage.yml diff --git a/.github/workflows/issue_triage.yml b/.github/workflows/issue_triage.yml new file mode 100644 index 00000000000..5ad263d2cfa --- /dev/null +++ b/.github/workflows/issue_triage.yml @@ -0,0 +1,91 @@ +name: Issue Triage and Management + +on: + issues: + types: [opened, labeled, assigned] + +permissions: + issues: write + +jobs: + triage-on-issue-open: + runs-on: ubuntu-latest + if: github.event.sender.login != 'github-actions' + steps: + - name: Reply to Issue + uses: peter-evans/issues-comment-action@v2 + with: + issue-number: ${{ github.event.issue.number }} + comment: > + 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 + with: + script: | + const issue = await github.rest.issues.get({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number + }); + + const labels = issue.data.labels.map(label => label.name); + const requiredLabels = { + 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); + + core.setOutput('needs-triage', needsTriage); + + - name: Manage Needs Triage Label + uses: actions/github-script@v6 + with: + script: | + const needsTriage = '${{ steps.check-labels.outputs.needs-triage }}' === 'true'; + if (needsTriage) { + await github.rest.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + labels: ['needs-triage'] + }); + } else { + try { + await github.rest.issues.removeLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + name: 'needs-triage' + }); + } catch (error) { + if (error.status !== 404) { + throw error; + } + } + } + + - 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, + issue_number: context.issue.number + }); + + const openProjects = projects.data.filter(project => project.state === 'open'); + if (openProjects.length !== 1) { + throw new Error(Issue must be assigned to exactly one open project. Found: ${openProjects.length}); + } + console.log(Valid project assignment: ${openProjects[0].name}); \ No newline at end of file From 25260c6f0f826071870e435d7e80cc2a205db72b Mon Sep 17 00:00:00 2001 From: Mayank77maruti <125661248+Mayank77maruti@users.noreply.github.com> Date: Tue, 10 Dec 2024 23:46:40 +0530 Subject: [PATCH 2/7] requested changes done --- .github/workflows/issue_triage.yml | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/.github/workflows/issue_triage.yml b/.github/workflows/issue_triage.yml index 5ad263d2cfa..d0d2c705dcc 100644 --- a/.github/workflows/issue_triage.yml +++ b/.github/workflows/issue_triage.yml @@ -13,7 +13,7 @@ jobs: if: github.event.sender.login != 'github-actions' steps: - name: Reply to Issue - uses: peter-evans/issues-comment-action@v2 + uses: peter-evans/create-or-update-comment@v4 with: issue-number: ${{ github.event.issue.number }} comment: > @@ -29,7 +29,6 @@ jobs: repo: context.repo.repo, issue_number: context.issue.number }); - const labels = issue.data.labels.map(label => label.name); const requiredLabels = { types: ['bug', 'enhancement', 'good first issue'], @@ -37,14 +36,11 @@ jobs: 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); - core.setOutput('needs-triage', needsTriage); - name: Manage Needs Triage Label @@ -78,14 +74,13 @@ jobs: uses: actions/github-script@v6 with: script: | - const projects = await github.rest.issues.listForRepo({ + const projects = await github.rest.projects.listForRepo({ owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number + repo: context.repo.repo }); - - const openProjects = projects.data.filter(project => project.state === 'open'); - if (openProjects.length !== 1) { - throw new Error(Issue must be assigned to exactly one open project. Found: ${openProjects.length}); + 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}`); } - console.log(Valid project assignment: ${openProjects[0].name}); \ No newline at end of file From 140dc54b14be6b8d00669a283d588debe0dbd0d8 Mon Sep 17 00:00:00 2001 From: Mayank77maruti <125661248+Mayank77maruti@users.noreply.github.com> Date: Tue, 10 Dec 2024 23:54:52 +0530 Subject: [PATCH 3/7] requested changes done --- .github/workflows/issue_triage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/issue_triage.yml b/.github/workflows/issue_triage.yml index d0d2c705dcc..191d3d14cf4 100644 --- a/.github/workflows/issue_triage.yml +++ b/.github/workflows/issue_triage.yml @@ -74,7 +74,7 @@ jobs: uses: actions/github-script@v6 with: script: | - const projects = await github.rest.projects.listForRepo({ + const projects = await github.rest.issues.listForRepo({ owner: context.repo.owner, repo: context.repo.repo }); From 6ffb172c743c2d7ed2e6b8c95370299b1892e293 Mon Sep 17 00:00:00 2001 From: Mayank77maruti <125661248+Mayank77maruti@users.noreply.github.com> Date: Wed, 11 Dec 2024 01:25:34 +0530 Subject: [PATCH 4/7] changes done after testing --- .github/workflows/issue_triage.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/issue_triage.yml b/.github/workflows/issue_triage.yml index 191d3d14cf4..addd536b65e 100644 --- a/.github/workflows/issue_triage.yml +++ b/.github/workflows/issue_triage.yml @@ -12,13 +12,14 @@ jobs: runs-on: ubuntu-latest if: github.event.sender.login != 'github-actions' steps: - - name: Reply to Issue + - name: Reply to Issue (Only on Opened) + if: ${{ github.event.action == 'opened' }} uses: peter-evans/create-or-update-comment@v4 with: issue-number: ${{ github.event.issue.number }} - comment: > + 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 @@ -84,3 +85,4 @@ jobs: } else { console.log(`Valid project assignment: ${assignedProjects[0].name}`); } + \ No newline at end of file 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 5/7] 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 From 8037973c53cdfdcc03d59a084b88c0b9ea65c1c3 Mon Sep 17 00:00:00 2001 From: Mayank Mohapatra <125661248+Mayank77maruti@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:54:00 +0530 Subject: [PATCH 6/7] Update project_assigned_verify.yml --- .github/workflows/project_assigned_verify.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/project_assigned_verify.yml b/.github/workflows/project_assigned_verify.yml index a095d63e872..fe6ab8fe9e0 100644 --- a/.github/workflows/project_assigned_verify.yml +++ b/.github/workflows/project_assigned_verify.yml @@ -30,19 +30,19 @@ jobs: script: | const issueNumber = context.issue.number; - // Fetch all open projects in the repository + # 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 + # 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 + # Add a comment to notify about incorrect project assignment const existingComments = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, @@ -64,5 +64,3 @@ jobs: } else { console.log(`Valid project assignment: ${assignedProjects[0].name}`); } - - \ No newline at end of file From 3ae348d149cbd93b566af09af435a5c62f5c51b5 Mon Sep 17 00:00:00 2001 From: Mayank Mohapatra <125661248+Mayank77maruti@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:56:26 +0530 Subject: [PATCH 7/7] Update project_assigned_verify.yml --- .github/workflows/project_assigned_verify.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/project_assigned_verify.yml b/.github/workflows/project_assigned_verify.yml index fe6ab8fe9e0..3d86d07093d 100644 --- a/.github/workflows/project_assigned_verify.yml +++ b/.github/workflows/project_assigned_verify.yml @@ -64,3 +64,4 @@ jobs: } else { console.log(`Valid project assignment: ${assignedProjects[0].name}`); } +