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

Recorrected redundant github actions #52

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all 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
74 changes: 40 additions & 34 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const run = async () => {

let last_event = { issue: { number: "" } };
let present_date = new Date();
const processedActions = new Set();

await octokit.paginate(octokit.issues.listEventsForRepo, {
owner,
Expand All @@ -127,44 +128,49 @@ const run = async () => {

if (last_event.issue.number != event.issue.number) {

console.log(
event.issue.updated_at + " " +
event.issue.number + " " +
event.assignee.login + " " +
event.issue.assignee.login + " " +
event.issue.state + " " +
(Difference_In_Time / (1000 * 3600 * 24)).toString() + " days",
);

if ((Difference_In_Time / (1000 * 3600 * 24)) > 1) {
// Check if the issue has any labels
const issueDetails = await octokit.issues.get({
owner,
repo,
issue_number: event.issue.number
});


if (issueDetails.data.labels.length === 0) {
console.log('unassigning ' + event.issue.assignee.login + " from " + event.issue.number);

await octokit.issues.removeAssignees({
const actionId = `${event.issue.number}-${event.assignee.login}`;
if (!processedActions.has(actionId)) {
console.log(
event.issue.updated_at + " " +
event.issue.number + " " +
event.assignee.login + " " +
event.issue.assignee.login + " " +
event.issue.state + " " +
(Difference_In_Time / (1000 * 3600 * 24)).toString() + " days",
);

processedActions.add(actionId);

if ((Difference_In_Time / (1000 * 3600 * 24)) > 1) {
// Check if the issue has any labels
const issueDetails = await octokit.issues.get({
owner,
repo,
issue_number: event.issue.number,
assignees: [event.issue.assignee.login],
issue_number: event.issue.number
});

// Add a comment about unassignment
await octokit.issues.createComment({
owner,
repo,
issue_number: event.issue.number,
body: `⏰ This issue has been automatically unassigned due to 24 hours of inactivity.
The issue is now available for anyone to work on again.`
});
} else {
console.log(`Issue #${event.issue.number} has labels, skipping unassign.`);

if (issueDetails.data.labels.length === 0) {
console.log('unassigning ' + event.issue.assignee.login + " from " + event.issue.number);

await octokit.issues.removeAssignees({
owner,
repo,
issue_number: event.issue.number,
assignees: [event.issue.assignee.login],
});

// Add a comment about unassignment
await octokit.issues.createComment({
owner,
repo,
issue_number: event.issue.number,
body: `⏰ This issue has been automatically unassigned due to 24 hours of inactivity.
The issue is now available for anyone to work on again.`
});
} else {
console.log(`Issue #${event.issue.number} has labels, skipping unassign.`);
}
}
}
}
Expand Down
Loading