Skip to content

Commit

Permalink
Revamped monitoring abandoned issues GA workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
fturizo committed Sep 21, 2023
1 parent 4ce3279 commit d1200ac
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 114 deletions.
62 changes: 0 additions & 62 deletions .github/workflows/close-abandoned-issues.yaml

This file was deleted.

83 changes: 31 additions & 52 deletions .github/workflows/monitor-abandoned-issues.yaml
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});
41 changes: 41 additions & 0 deletions .github/workflows/scripts/checkAbandonedIssues.js
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
});
}
}
}
40 changes: 40 additions & 0 deletions .github/workflows/scripts/closeAbandonedIssues.js
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"
});
}
}
}

0 comments on commit d1200ac

Please sign in to comment.