From 194e330244c05299b0c22ea11b1570a8e7f4efe7 Mon Sep 17 00:00:00 2001 From: Lakshmi Pavananjali <154777864+Anjaliavv51@users.noreply.github.com> Date: Fri, 20 Dec 2024 21:37:03 +0530 Subject: [PATCH] Update close all issues --- .github/workflows/close all issues | 98 +++++++++++------------------- 1 file changed, 36 insertions(+), 62 deletions(-) diff --git a/.github/workflows/close all issues b/.github/workflows/close all issues index c234b92..4dbf53f 100644 --- a/.github/workflows/close all issues +++ b/.github/workflows/close all issues @@ -1,67 +1,41 @@ -name: Close Issues +name: Close All Open Issues + on: - workflow_dispatch: + workflow_dispatch: # Allows manual triggering of this workflow + +permissions: + issues: write # Grants write permission to manage issues jobs: - close-issues: + close_issues: runs-on: ubuntu-latest - steps: - - name: Close Issue #839 - uses: peter-evans/repository-dispatch@v1 - with: - event-type: close_issue - client-payload: '{"issue_number": 839}' - - - name: Close Pull Request #625 - uses: peter-evans/repository-dispatch@v1 - with: - event-type: close_pull_request - client-payload: '{"pull_number": 625}' - - - name: Close Pull Request #615 - uses: peter-evans/repository-dispatch@v1 - with: - event-type: close_pull_request - client-payload: '{"pull_number": 615}' - - - name: Close Issue #838 - uses: peter-evans/repository-dispatch@v1 - with: - event-type: close_issue - client-payload: '{"issue_number": 838}' - - - name: Close Pull Request #670 - uses: peter-evans/repository-dispatch@v1 - with: - event-type: close_pull_request - client-payload: '{"pull_number": 670}' - - - name: Close Pull Request #810 - uses: peter-evans/repository-dispatch@v1 - with: - event-type: close_pull_request - client-payload: '{"pull_number": 810}' - - name: Close Pull Request #626 - uses: peter-evans/repository-dispatch@v1 - with: - event-type: close_pull_request - client-payload: '{"pull_number": 626}' - - - name: Close Pull Request #805 - uses: peter-evans/repository-dispatch@v1 - with: - event-type: close_pull_request - client-payload: '{"pull_number": 805}' - - - name: Close Issue #836 - uses: peter-evans/repository-dispatch@v1 - with: - event-type: close_issue - client-payload: '{"issue_number": 836}' - - - name: Close Pull Request #695 - uses: peter-evans/repository-dispatch@v1 - with: - event-type: close_pull_request - client-payload: '{"pull_number": 695}' + steps: + - name: Close all open issues + uses: actions/github-script@v6 + with: + script: | + const issues = await github.paginate(github.rest.issues.listForRepo, { + owner: context.repo.owner, + repo: context.repo.repo, + state: 'open', // Fetch only open issues + }); + + if (issues.length === 0) { + console.log("No open issues found."); + } else { + console.log(`Found ${issues.length} open issues.`); + for (const issue of issues) { + if (!issue.pull_request) { // Skip pull requests + await github.rest.issues.update({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issue.number, + state: 'closed', + }); + console.log(`Closed issue #${issue.number}: ${issue.title}`); + } else { + console.log(`Skipped pull request #${issue.number}`); + } + } + }