Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
DonnieBLT committed Feb 15, 2024
1 parent db2427d commit 1d0460b
Showing 1 changed file with 91 additions and 96 deletions.
187 changes: 91 additions & 96 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,110 +39,105 @@ const run = async () => {
}



if (issue && proceedWithIssueProcessing) {
console.log('processing issue');
const assigneeLogin = comment.user.login;
const assignees = assigneeLogin.split(',').map(assigneeName => assigneeName.trim());
var addAssignee = true;
var issuesWithoutPR = [];

// Retrieve all open issues assigned to the user
const assignedIssues = await octokit.paginate(octokit.issues.listForRepo, {
owner,
repo,
state: 'open',
assignee: assigneeLogin
if (issue && proceedWithIssueProcessing) {
console.log('processing issue');
const assigneeLogin = comment.user.login;
const assignees = assigneeLogin.split(',').map(assigneeName => assigneeName.trim());
var addAssignee = true;
var issuesWithoutPR = [];

// Retrieve all open issues assigned to the user
const assignedIssues = await octokit.paginate(octokit.issues.listForRepo, {
owner,
repo,
state: 'open',
assignee: assigneeLogin
});
for (const assignedIssue of assignedIssues) {
// Skip if it's the same issue
if (assignedIssue.number === issue.number) {
continue;
}

// Construct a search query to find pull requests that mention the assigned issue
const query = `type:pr state:open repo:${owner}/${repo} ${assignedIssue.number} in:body`;
const pullRequests = await octokit.search.issuesAndPullRequests({
q: query
});
for (const assignedIssue of assignedIssues) {
// Skip if it's the same issue
if (assignedIssue.number === issue.number) {
continue;
}

// Construct a search query to find pull requests that mention the assigned issue
const query = `type:pr state:open repo:${owner}/${repo} ${assignedIssue.number} in:body`;
const pullRequests = await octokit.search.issuesAndPullRequests({
q: query
});

// If there are no pull requests mentioning the issue number in their body, add it to the list
if (pullRequests.data.total_count === 0) {
console.log(`Issue #${assignedIssue.number} does not have an open pull request`);
issuesWithoutPR.push(assignedIssue.number);
break;
}
}
if (issuesWithoutPR.length > 0) {
addAssignee = false;
const issueList = issuesWithoutPR.join(', #');
await octokit.issues.createComment({
owner,
repo,
issue_number: issue.number,
body: `You cannot be assigned to this issue because you are already assigned to the following issues without an open pull request: #${issueList}. Please submit a pull request for these issues before getting assigned to a new one.`
});
} else if (addAssignee) {
await octokit.issues.addAssignees({
owner,
repo,
issue_number: issue.number,
assignees
});
// If there are no pull requests mentioning the issue number in their body, add it to the list
if (pullRequests.data.total_count === 0) {
console.log(`Issue #${assignedIssue.number} does not have an open pull request`);
issuesWithoutPR.push(assignedIssue.number);
break;
}
} else {
console.log('removing assignees greater than 5 days');
var last_event = new Object()
last_event.issue = new Object()
last_event.issue.number = "";
var present_date = new Date();

await octokit.paginate(octokit.issues.listEventsForRepo, {
}
if (issuesWithoutPR.length > 0) {
addAssignee = false;
const issueList = issuesWithoutPR.join(', #');
await octokit.issues.createComment({
owner,
repo,
per_page: 100,
}, response => response.data.filter(r => r.event == "assigned")
).then((data) => {
for (const event of data) {

if (event.issue.assignee && event.issue.state == "open") {

var Difference_In_Time = present_date.getTime() - Date.parse(event.created_at);

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

console.log(
event.created_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)) > 5) {
console.log('unassigning ' + event.issue.assignee.login + " from " + event.issue.number);

const assignees = event.issue.assignee.login.split(',').map((assigneeName) => assigneeName.trim());

var issue_number = event.issue.number;

octokit.issues.removeAssignees({
owner,
repo,
issue_number,
assignees,
})
}
issue_number: issue.number,
body: `You cannot be assigned to this issue because you are already assigned to the following issues without an open pull request: #${issueList}. Please submit a pull request for these issues before getting assigned to a new one.`
});
} else if (addAssignee) {
await octokit.issues.addAssignees({
owner,
repo,
issue_number: issue.number,
assignees
});
}
} else {
console.log('removing assignees greater than 5 days');
var last_event = new Object()
last_event.issue = new Object()
last_event.issue.number = "";
var present_date = new Date();

await octokit.paginate(octokit.issues.listEventsForRepo, {
owner,
repo,
per_page: 100,
}, response => response.data.filter(r => r.event == "assigned")
).then((data) => {
for (const event of data) {

if (event.issue.assignee && event.issue.state == "open") {

var Difference_In_Time = present_date.getTime() - Date.parse(event.created_at);

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

console.log(
event.created_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)) > 5) {
console.log('unassigning ' + event.issue.assignee.login + " from " + event.issue.number);

const assignees = event.issue.assignee.login.split(',').map((assigneeName) => assigneeName.trim());

var issue_number = event.issue.number;

octokit.issues.removeAssignees({
owner,
repo,
issue_number,
assignees,
})
}
}
last_event = event;
}
});
}
}
else {
console.log('No matching keywords found or not an issue comment event. Skipping further processing.');
last_event = event;
}
});
}
}

Expand Down

0 comments on commit 1d0460b

Please sign in to comment.