From d1200ac1527276eb3f15e39210ba0bc719e777b7 Mon Sep 17 00:00:00 2001 From: Fabio Turizo Date: Thu, 21 Sep 2023 14:45:14 -0500 Subject: [PATCH] Revamped monitoring abandoned issues GA workflow --- .github/workflows/close-abandoned-issues.yaml | 62 -------------- .../workflows/monitor-abandoned-issues.yaml | 83 +++++++------------ .../workflows/scripts/checkAbandonedIssues.js | 41 +++++++++ .../workflows/scripts/closeAbandonedIssues.js | 40 +++++++++ 4 files changed, 112 insertions(+), 114 deletions(-) delete mode 100644 .github/workflows/close-abandoned-issues.yaml create mode 100644 .github/workflows/scripts/checkAbandonedIssues.js create mode 100644 .github/workflows/scripts/closeAbandonedIssues.js diff --git a/.github/workflows/close-abandoned-issues.yaml b/.github/workflows/close-abandoned-issues.yaml deleted file mode 100644 index d8e44da629b..00000000000 --- a/.github/workflows/close-abandoned-issues.yaml +++ /dev/null @@ -1,62 +0,0 @@ -name: Close Abandoned Issues - -on: - schedule: - - cron: "0 */24 * * *" - -jobs: - close-labeler: - runs-on: ubuntu-latest - permissions: - issues: write - steps: - - name: Close the abandoned issue - uses: actions/github-script@v6 - env: - daysInterval: ${{ vars.MONITORING_INTERVAL_DAYS }} - with: - script: | - const { owner, repo } = context.repo; - const abandonedLabel = "Status: Abandoned"; - - const parsedDays = parseFloat("${{ env.daysInterval }}"); - const timeThreshold = parsedDays * 24 * 60 * 60 * 1000; - - const issuesResponse = await github.rest.issues.listForRepo({ - owner, - repo, - labels: abandonedLabel, - state: "open", - }); - - for (const issue of issuesResponse.data) { - const updatedAt = new Date(issue.updated_at).getTime(); - const currentTime = new Date().getTime(); - const updateMessage = `Greetings, - It's been more than ${parsedDays} days since this issue was identified as abandoned. - We have closed this issue due to inactivity, please feel free to re-open it if you have more information to share.`; - - if (currentTime - updatedAt > timeThreshold) { - - await github.rest.issues.removeLabel({ - owner, - repo, - issue_number: issue.number, - name: abandonedLabel, - }); - - await github.rest.issues.createComment({ - owner, - repo, - issue_number: issue.number, - body: updateMessage, - }); - - await github.rest.issues.update({ - owner, - repo, - issue_number: issue.number, - state: "closed", - }); - } - } diff --git a/.github/workflows/monitor-abandoned-issues.yaml b/.github/workflows/monitor-abandoned-issues.yaml index cdd8de540e5..8b04f464915 100644 --- a/.github/workflows/monitor-abandoned-issues.yaml +++ b/.github/workflows/monitor-abandoned-issues.yaml @@ -1,63 +1,42 @@ name: Monitor Abandoned Issues - +#Runs at minute 0 past every 48th hour on: schedule: - - cron: "0 */24 * * *" - + - cron: "0 */48 * * *" +env: + daysInterval: ${{ vars.MONITORING_INTERVAL_DAYS }} jobs: - abandoned-labeler: + check-environment: + runs-on: ubuntu-latest + steps: + - run: | + if [ -z $daysInterval ]; then + echo "::error::'MONITORING_INTERVAL_DAYS' environment variable is not set" + exit 1 + fi + check-abandoned-issues: + needs: check-environment + runs-on: ubuntu-latest + permissions: + issues: write + steps: + - uses: actions/checkout@v3 + - name: Monitor abandoned issues + uses: actions/github-script@v6 + with: + script: | + const script = require('./.github/workflows/scripts/checkAbandonedIssues.js'); + await script({github, context, core}); + close-abandoned-issues: + needs: check-environment runs-on: ubuntu-latest permissions: issues: write steps: - - name: Check for abandoned issues + - uses: actions/checkout@v3 + - name: Close abandoned issues uses: actions/github-script@v6 - env: - daysInterval: ${{ vars.MONITORING_INTERVAL_DAYS }} with: script: | - const { owner, repo } = context.repo; - const pendingLabel = "Status: Pending"; - const abandonedLabel = "Status: Abandoned"; - - const parsedDays = parseFloat("${{ env.daysInterval }}"); - const timeThreshold = parsedDays * 24 * 60 * 60 * 1000; - - // Query all GH issues that are pending and not closed - const issuesResponse = await github.rest.issues.listForRepo({ - owner, - repo, - labels: pendingLabel, - state: "open", - }); - - for (const issue of issuesResponse.data) { - const updatedAt = new Date(issue.updated_at).getTime(); - const currentTime = new Date().getTime(); - const updateMessage = `Greetings, - It's been more than ${parsedDays} days since we requested more information or an update from you on the details of this issue. Could you provide an update soon, please? - We're afraid that if we do not receive an update, we'll have to close this issue due to inactivity.`; - - if (currentTime - updatedAt > timeThreshold) { - await github.rest.issues.addLabels({ - owner, - repo, - issue_number: issue.number, - labels: [abandonedLabel], - }); - - await github.rest.issues.removeLabel({ - owner, - repo, - issue_number: issue.number, - name: pendingLabel, - }); - - await github.rest.issues.createComment({ - owner, - repo, - issue_number: issue.number, - body: updateMessage, - }); - } - } + const script = require('./.github/workflows/scripts/closeAbandonedIssues.js'); + await script({github, context, core}); diff --git a/.github/workflows/scripts/checkAbandonedIssues.js b/.github/workflows/scripts/checkAbandonedIssues.js new file mode 100644 index 00000000000..173b9a19ff2 --- /dev/null +++ b/.github/workflows/scripts/checkAbandonedIssues.js @@ -0,0 +1,41 @@ +module.exports = async ({github, context, core}) => { + const { owner, repo } = context.repo; + const pendingLabel = "Status: Pending"; + const abandonedLabel = "Status: Abandoned"; + + const parsedDays = parseFloat(process.env.daysInterval); + const timeThreshold = parsedDays * 24 * 60 * 60 * 1000; + core.debug(`Abandoned interval days is set to ${parsedDays}`); + + // Query all GH issues that are pending and not closed + const issuesResponse = await github.rest.issues.listForRepo({ + owner, + repo, + labels: pendingLabel, + state: "open", + }); + + for (let issue of issuesResponse.data) { + const updatedAt = new Date(issue.updated_at).getTime(); + const currentTime = new Date().getTime(); + const updateMessage = `Greetings, + It's been more than ${parsedDays} days since we requested more information or an update from you on the details of this issue. Could you provide an update soon, please? + We're afraid that if we do not receive an update, we'll have to close this issue due to inactivity.`; + + if (currentTime - updatedAt > timeThreshold) { + await github.rest.issues.update({ + owner, + repo, + issue_number: issue.number, + labels: [abandonedLabel] + }); + + await github.rest.issues.createComment({ + owner, + repo, + issue_number: issue.number, + body: updateMessage + }); + } + } +} diff --git a/.github/workflows/scripts/closeAbandonedIssues.js b/.github/workflows/scripts/closeAbandonedIssues.js new file mode 100644 index 00000000000..87af5458f0b --- /dev/null +++ b/.github/workflows/scripts/closeAbandonedIssues.js @@ -0,0 +1,40 @@ +module.exports = async ({github, context, core}) => { + const { owner, repo } = context.repo; + const abandonedLabel = "Status: Abandoned"; + + const parsedDays = parseFloat(process.env.daysInterval); + core.debug(`Abandoned interval days is set to ${parsedDays}`); + + const timeThreshold = parsedDays * 24 * 60 * 60 * 1000; + const response = await github.rest.issues.listForRepo({ + owner, + repo, + labels: abandonedLabel, + state: "open", + }); + + for (let issue of response.data) { + const updatedAt = new Date(issue.updated_at).getTime(); + const currentTime = new Date().getTime(); + const updateMessage = `Greetings, + It's been more than ${parsedDays} days since this issue was identified as abandoned. + We have closed this issue due to inactivity, please feel free to re-open it if you have more information to share.`; + + if (currentTime - updatedAt > timeThreshold) { + await github.rest.issues.createComment({ + owner, + repo, + issue_number: issue.number, + body: updateMessage + }); + + await github.rest.issues.update({ + owner, + repo, + issue_number: issue.number, + labels: [], + state: "closed" + }); + } + } +}