-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6411 from fturizo/master
Revamped monitoring abandoned issues GA workflow
- Loading branch information
Showing
4 changed files
with
112 additions
and
114 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
}); | ||
} | ||
} | ||
} |