Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Github action to automate additional Community Supporting Processes #6376

Merged
merged 7 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions .github/workflows/CheckMostVoted.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Test Most Voted Enhancement
fturizo marked this conversation as resolved.
Show resolved Hide resolved

on:
schedule:
- cron: "0 10 1 * *"

jobs:
voting-labeler-test:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Check for most voted enhancement
id: vote-issues
uses: actions/github-script@v6
with:
script: |
// - github: A pre-authenticated octokit/rest.js client
const { owner, repo } = context.repo;
const openLabel = "Status: Open";
const votingLabel = "Status: Voting";

// Query all GH issues for Voting
// is:issue is:open label:"Status: Voting" reactions:+1>0 sort:reactions-+1-desc
const issuesResponse = await github.rest.issues.listForRepo({
owner,
repo,
labels: votingLabel,
state: 'open',
sort: 'reactions-+1',
fturizo marked this conversation as resolved.
Show resolved Hide resolved
direction: 'desc',
});

//issuesResponse has all the issues labeled with Voting.
if (issuesResponse.data.length === 0) {
core.info('No issues labelled with Voting found to process. Exiting.');
return;
}
//filter issues with atleast one vote. Change it later to >1
issuesResponse.data = issuesResponse.data.filter((i) => i.reactions['+1'] > 1)

if (issuesResponse.data.length === 0) {
core.info('No issues labelled with Voting has votes. Exiting.');
fturizo marked this conversation as resolved.
Show resolved Hide resolved
return;
}

//if there are more than 1 issues for voting, then sort by reactions.
if (issuesResponse.data.length > 1) {
Total = issuesResponse.data.length
issuesResponse.data.sort.reactions-+1;
}
MostVotes = 0

for (const issue of issuesResponse.data) {
if (MostVotes == 0) { // Saving the number of votes for the first issue
MostVotes = issue.reactions['+1'];
core.info(`Highest votes is ${MostVotes}`);
}
core.info(`Processing issue #${issue.number}`);
core.info(`Number of +1 reactions ${issue.reactions['+1']}`);
core.info(`Issue was created ${issue.created_at}`);
}

//filter out the issues with MostVotes number. This is to cover the case with more than 1 isues with the same number of votes
issuesResponse.data = issuesResponse.data.filter((i) => i.reactions['+1'] == MostVotes)

//Sort by created by
issuesResponse.data.sort.created_at;
OldestIssue = 0;
OldestDate = new Date(null).getTime();
for (const issue of issuesResponse.data) {
issueDate = new Date(issue.created_at).getTime();
if (OldestDate == 0) {
OldestDate = new Date(issue.created_at).getTime();
OldestIssue = issue;
}
if(issueDate < OldestDate) {
OldestDate = issueDate;
OldestIssue = issue;
}
}
fturizo marked this conversation as resolved.
Show resolved Hide resolved
core.info(`Final issue selected for enhancement is #${OldestIssue.number} created on ${OldestIssue.created_at}`);
fturizo marked this conversation as resolved.
Show resolved Hide resolved
68 changes: 68 additions & 0 deletions .github/workflows/CloseOldVotingIssues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Close Old Voted issues
fturizo marked this conversation as resolved.
Show resolved Hide resolved

on:
schedule:
- cron: "0 10 1 * *"

jobs:
oldvoting-labeler-test:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Check for old voted issues
id: old-vote-issues
uses: actions/github-script@v6
with:
script: |
// - github: A pre-authenticated octokit/rest.js client
const { owner, repo } = context.repo;
const votingLabel = "Status: Voting";

// Query all GH issues for Voting
// is:issue is:open label:"Status: Voting"
const issuesResponse = await github.rest.issues.listForRepo({
owner,
repo,
labels: votingLabel,
state: 'open',
});

//issuesResponse has all the issues labeled with Voting.
if (issuesResponse.data.length === 0) {
core.info('No issues labelled with Voting found to process. Exiting.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message could say "Current issues in the Voting stage do not have enough votes to qualify for selection. Exiting"

return;
}
const now = new Date().getTime();

for (const issue of issuesResponse.data) {
core.info(`Processing issue #${issue.number}`);
core.info(`Issue was created ${issue.created_at}`);
const issueDate = new Date(issue.created_at).getTime();
const daysSinceCreated = (now - issueDate) / 1000 / 60 / 60 / 24;
if (daysSinceCreated > 180) { // 180 days
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The threshold for days (180 days = 6 months) should be taken from an environment variable so it can be changed and easily tested.

//core.info(`Closing #${issue.number} because it has not got enough votes in the last ${daysSinceCreated} days`);
fturizo marked this conversation as resolved.
Show resolved Hide resolved
const message = `Greetings, closing the issue because it has not got enough votes in the last 6 months.`;
fturizo marked this conversation as resolved.
Show resolved Hide resolved
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
name: votingLabel,
});

await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: message,
});


await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: 'closed',
fturizo marked this conversation as resolved.
Show resolved Hide resolved
});
}
}
48 changes: 48 additions & 0 deletions .github/workflows/monitor-inactive-openissues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Monitor Inactive Open Issues

on:
schedule:
- cron: "0 10 * * 1-5"

jobs:
inactive-labeler:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Check for inactive open issues
uses: actions/github-script@v6
env:
daysInterval: ${{ vars.MONITORING_INACTIVE_INTERVAL_DAYS }}
with:
script: |
// - github: A pre-authenticated octokit/rest.js client
const { owner, repo } = context.repo;
const openLabel = "Status: Open";

//const parsedDays = parseFloat("${{ env.daysInterval }}");
const parsedDays = 14;
const timeThreshold = parsedDays * 24 * 60 * 60 * 1000;

// Query all GH issues that are open
const issuesResponse = await github.rest.issues.listForRepo({
owner,
repo,
labels: openLabel,
state: "open",
});

for (const issue of issuesResponse.data) {
const updatedAt = new Date(issue.updated_at).getTime();
const currentTime = new Date().getTime();
const updateMessage = `Please update the issue #${issue.number}.`;

if (currentTime - updatedAt > timeThreshold) {
await github.rest.issues.createComment({
owner,
repo,
issue_number: issue.number,
body: updateMessage,
RamyaBill marked this conversation as resolved.
Show resolved Hide resolved
});
}
}