Skip to content
Merged
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
230 changes: 116 additions & 114 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fetch from "node-fetch";
import fetch, { Response } from "node-fetch";
import { Probot } from "probot";
import { Octokit } from "octokit";
import { createAppAuth } from "@octokit/auth-app";
Expand Down Expand Up @@ -32,7 +32,7 @@ module.exports = (app: Probot) => {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + token
}
}).then((res) => {
}).then((res: Response) => {
return res.json();
}).then((res: [getEvent]) => {
let i: number;
Expand Down Expand Up @@ -842,7 +842,7 @@ module.exports = (app: Probot) => {
issue_number: context.payload.pull_request.number
}).then(async (res) => {
if (res.data.find(a => a.name == "Requested Changes")) {
context.octokit.issues.removeLabel(
await context.octokit.issues.removeLabel(
context.issue({
name: 'Requested Changes'
})
Expand Down Expand Up @@ -940,7 +940,7 @@ module.exports = (app: Probot) => {
case "User":
// Merge pull request
if (context.payload.comment.body.toLowerCase() == "ready to merge") {
context.octokit.pulls.get({
await context.octokit.pulls.get({
repo: context.payload.repository.name,
owner: context.payload.repository.owner.login,
pull_number: context.payload.issue.number
Expand Down Expand Up @@ -1105,123 +1105,125 @@ module.exports = (app: Probot) => {
});

// Stale PRs
setInterval(async () => {
octokit.rest.repos.listForUser({
username: "Muunatic",
type: "owner"
}).then(async (res) => {
for (let i = 0; i < res.data.length; i++) {
if (res.data[i].fork === false) {
octokit.rest.pulls.list({
owner: res.data[i].owner.login,
repo: res.data[i].name
}).then(async (res) => {
for (let i = 0; i < res.data.length; i++) {
const currentRepo = res.data[i].base.repo.name;
const currentOwner = res.data[i].base.repo.owner.login;
const currentPRs = res.data[i].number;
if (res.data[i].state.toLowerCase() == "open" && res.data[i].draft == false) {
if (res.data[i].user?.type.toLowerCase() == "user") {
octokit.rest.pulls.listCommits({
owner: currentOwner,
repo: currentRepo,
pull_number: currentPRs
}).then((res) => {
const currentDate = new Date();
const createdAt = new Date(res.data[res.data.length - 1].commit.author?.date as string);
const staleDate = new Date(createdAt.getTime() + 7 * 24 * 60 * 60 * 1000);
const closeDate = new Date(createdAt.getTime() + 30 * 24 * 60 * 60 * 1000);
if (currentDate > staleDate) {
if (currentDate > closeDate) {
octokit.rest.pulls.update({
owner: currentOwner,
repo: currentRepo,
pull_number: currentPRs,
state: "closed"
}).then(async (res) => {
if (res.data.labels.find((a) => a.name == "Stale")) {
await octokit.rest.issues.addLabels({
owner: res.data.base.repo.owner.login,
repo: res.data.base.repo.name,
issue_number: res.data.number,
labels: ["Closed"]
});
await octokit.rest.issues.removeLabel({
owner: res.data.base.repo.owner.login,
repo: res.data.base.repo.name,
issue_number: res.data.number,
name: "Pending"
});
await octokit.rest.issues.createComment({
owner: res.data.base.repo.owner.login,
repo: res.data.base.repo.name,
issue_number: res.data.number,
body: `Hello @${res.data.user?.login}! We've observed that your pull requests have remained inactive for the last 30 days. Due to this prolonged inactivity, we've had to close these PRs. If you still intend to pursue these changes, please feel free to create new PRs.`
});
octokit.rest.issues.lock({
owner: currentOwner,
repo: currentRepo,
issue_number: currentPRs,
lock_reason: "resolved"
});
} else {
return;
}
});
} else {
octokit.rest.pulls.get({
owner: currentOwner,
repo: currentRepo,
pull_number: currentPRs
}).then(async (res) => {
if (res.data.labels.find((a) => a.name == "Stale")) {
return;
} else {
const prsReviewers: string[] = [];
octokit.rest.pulls.listReviewComments({
owner: res.data.base.repo.owner.login,
repo: res.data.base.repo.name,
pull_number: res.data.number
}).then(async (res) => {
if (res.data.length !== 0) {
for (let i = 0; i < res.data.length; i++) {
prsReviewers.push("@" + res.data[i].user?.login);
setInterval(() => {
(async () => {
await octokit.rest.repos.listForUser({
username: "Muunatic",
type: "owner"
}).then(async (res) => {
for (let i = 0; i < res.data.length; i++) {
if (res.data[i].fork === false) {
await octokit.rest.pulls.list({
owner: res.data[i].owner.login,
repo: res.data[i].name
}).then(async (res) => {
for (let i = 0; i < res.data.length; i++) {
const currentRepo = res.data[i].base.repo.name;
const currentOwner = res.data[i].base.repo.owner.login;
const currentPRs = res.data[i].number;
if (res.data[i].state.toLowerCase() == "open" && res.data[i].draft == false) {
if (res.data[i].user?.type.toLowerCase() == "user") {
await octokit.rest.pulls.listCommits({
owner: currentOwner,
repo: currentRepo,
pull_number: currentPRs
}).then(async (res) => {
const currentDate = new Date();
const createdAt = new Date(res.data[res.data.length - 1].commit.author?.date as string);
const staleDate = new Date(createdAt.getTime() + 7 * 24 * 60 * 60 * 1000);
const closeDate = new Date(createdAt.getTime() + 30 * 24 * 60 * 60 * 1000);
if (currentDate > staleDate) {
if (currentDate > closeDate) {
await octokit.rest.pulls.update({
owner: currentOwner,
repo: currentRepo,
pull_number: currentPRs,
state: "closed"
}).then(async (res) => {
if (res.data.labels.find((a) => a.name == "Stale")) {
await octokit.rest.issues.addLabels({
owner: res.data.base.repo.owner.login,
repo: res.data.base.repo.name,
issue_number: res.data.number,
labels: ["Closed"]
});
await octokit.rest.issues.removeLabel({
owner: res.data.base.repo.owner.login,
repo: res.data.base.repo.name,
issue_number: res.data.number,
name: "Pending"
});
await octokit.rest.issues.createComment({
owner: res.data.base.repo.owner.login,
repo: res.data.base.repo.name,
issue_number: res.data.number,
body: `Hello @${res.data.user?.login}! We've observed that your pull requests have remained inactive for the last 30 days. Due to this prolonged inactivity, we've had to close these PRs. If you still intend to pursue these changes, please feel free to create new PRs.`
});
await octokit.rest.issues.lock({
owner: currentOwner,
repo: currentRepo,
issue_number: currentPRs,
lock_reason: "resolved"
});
} else {
return;
}
});
} else {
await octokit.rest.pulls.get({
owner: currentOwner,
repo: currentRepo,
pull_number: currentPRs
}).then(async (res) => {
if (res.data.labels.find((a) => a.name == "Stale")) {
return;
} else {
const prsReviewers: string[] = [];
await octokit.rest.pulls.listReviewComments({
owner: res.data.base.repo.owner.login,
repo: res.data.base.repo.name,
pull_number: res.data.number
}).then((res) => {
if (res.data.length !== 0) {
for (let i = 0; i < res.data.length; i++) {
prsReviewers.push("@" + res.data[i].user?.login);
}
} else {
prsReviewers.push("@Muunatic");
}
} else {
prsReviewers.push("@Muunatic");
}
});
await octokit.rest.issues.addLabels({
owner: res.data.base.repo.owner.login,
repo: res.data.base.repo.name,
issue_number: res.data.number,
labels: ["Stale"]
});
await octokit.rest.issues.createComment({
owner: res.data.base.repo.owner.login,
repo: res.data.base.repo.name,
issue_number: res.data.number,
body: `Hello @${res.data.user?.login}! We noticed that your pull request has been inactive for the past 7 days. If you've already received a response from the maintainer, please ensure that you review and address the feedback provided. If not, please reach out to the maintainer to seek clarification or assistance if needed.\n\n Additionally, we'd appreciate it if ${prsReviewers.join(", ")} could also take a moment to review the pull request and provide feedback.`
});
}
});
});
await octokit.rest.issues.addLabels({
owner: res.data.base.repo.owner.login,
repo: res.data.base.repo.name,
issue_number: res.data.number,
labels: ["Stale"]
});
await octokit.rest.issues.createComment({
owner: res.data.base.repo.owner.login,
repo: res.data.base.repo.name,
issue_number: res.data.number,
body: `Hello @${res.data.user?.login}! We noticed that your pull request has been inactive for the past 7 days. If you've already received a response from the maintainer, please ensure that you review and address the feedback provided. If not, please reach out to the maintainer to seek clarification or assistance if needed.\n\n Additionally, we'd appreciate it if ${prsReviewers.join(", ")} could also take a moment to review the pull request and provide feedback.`
});
}
});
}
} else {
return;
}
} else {
return;
}
});
});
} else {
continue;
}
} else {
continue;
}
} else {
continue;
}
}
});
} else {
continue;
});
} else {
continue;
}
}
}
});
});
}, 3600000);

Expand Down