Skip to content
Merged
Show file tree
Hide file tree
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
75 changes: 75 additions & 0 deletions src/class/issuesClose.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import Context from "../index";

/**
* @class
* @default
* @exports
*/
export default class IssuesClose {

/**
* @private
* @type Context<"issues.closed">
*/
private context: Context<"issues.closed">;

/**
* @constructor
* @param {Context<"issues.closed">} context
*/
constructor(context: Context<"issues.closed">) {
this.context = context;
}

/**
* @public
* @async
* @returns {Promise<void>}
*/
public async closed(): Promise<void> {
const issueClosed = this.context.issue({
body: `Issue closed by @${this.context.payload.sender.login}.`
});
console.log("Issues closed");
await this.context.octokit.issues.addLabels(
this.context.issue({
labels: ["Closed"]
})
);
await this.context.octokit.issues.createComment(issueClosed);
await this.context.octokit.issues.removeLabel(
this.context.issue({
name: "Pending"
})
);
}

/**
* @public
* @async
* @returns {Promise<void>}
*/
public async invalid(): Promise<void> {
const issueClosed = this.context.issue({
body: `Issue closed as invalid by @${this.context.payload.sender.login}.`
});
console.log("Issues closed");
await this.context.octokit.issues.addLabels(
this.context.issue({
labels: ["Closed", "Invalid"]
})
);
await this.context.octokit.issues.createComment(issueClosed);
await this.context.octokit.issues.removeLabel(
this.context.issue({
name: "Pending"
})
);
await this.context.octokit.issues.lock({
owner: this.context.payload.repository.owner.login,
repo: this.context.payload.repository.name,
issue_number: this.context.payload.issue.number,
lock_reason: "spam"
});
}
}
192 changes: 192 additions & 0 deletions src/class/issuesComment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
import Context from "../index";

/**
* @class
* @default
* @exports
*/
export default class IssuesComment {

/**
* @private
* @type Context<"issue_comment.created">
*/
private context: Context<"issue_comment.created">;

/**
* @constructor
* @param {Context<"issue_comment.created">} context
*/
constructor(context: Context<"issue_comment.created">) {
this.context = context;
}

/**
* @public
* @async
* @returns {Promise<void>}
*/
public async userPRsComment(): Promise<void> {
if (this.context.payload.comment.body.toLowerCase() == "ready to merge") {
await this.context.octokit.pulls.get({
repo: this.context.payload.repository.name,
owner: this.context.payload.repository.owner.login,
pull_number: this.context.payload.issue.number
}).then(async (res) => {
if (res.data.mergeable_state.toLowerCase() == "clean" || res.data.mergeable == true) {
if (this.context.payload.issue.user.login == this.context.payload.comment.user.login) {
let i: number;
for (i = 0; i < this.context.payload.issue.labels.length; i++) {
if (this.context.payload.issue.labels[i].name == "Approved") {
console.log("Merging");
await this.context.octokit.pulls.merge({
repo: this.context.payload.repository.name,
owner: this.context.payload.repository.owner.login,
pull_number: this.context.payload.issue.number,
commit_title: `Merge PR #${this.context.payload.issue.number} ${this.context.payload.issue.title}`,
commit_message: this.context.payload.issue.title
});
console.log("Merged!");
await this.context.octokit.issues.createComment(
this.context.issue({
body: `Merged by ${this.context.payload.comment.user.login}!`
})
);
break;
} else if (this.context.payload.issue.labels[i].name == "Requested Changes") {
console.log("PRs Blocked");
await this.context.octokit.issues.createComment(
this.context.issue({
body: `Merging blocked because PRs has requested changes! @${this.context.payload.comment.user.login}`
})
);
break;
} else {
continue;
}
}
} else {
return;
}
} else if (res.data.mergeable_state.toLowerCase() == "dirty" || res.data.mergeable == false) {
await this.context.octokit.issues.createComment(
this.context.issue({
body: `Merging blocked because PRs has merge conflict! @${this.context.payload.comment.user.login}`
})
);
} else {
await this.context.octokit.issues.createComment(
this.context.issue({
body: "We apologize for the inconvenience, but it seems that Automaton processes are currently unable to proceed with merging your commit. Please wait for a moment and try merging it again."
})
);
}
});
}

if (this.context.payload.comment.body.toLowerCase() == "merge") {
if (this.context.payload.sender.login == this.context.payload.repository.owner.login) {
await this.context.octokit.pulls.merge({
repo: this.context.payload.repository.name,
owner: this.context.payload.repository.owner.login,
pull_number: this.context.payload.issue.number,
commit_title: `Merge PR #${this.context.payload.issue.number} ${this.context.payload.issue.title}`,
commit_message: this.context.payload.issue.title
});
console.log("Merged!");
await this.context.octokit.issues.removeLabel(
this.context.issue({
name: "Pending"
})
);
await this.context.octokit.issues.createComment(
this.context.issue({
body: `Merged by \`[OWNER]\`${this.context.payload.comment.user.login}!`
})
);
await this.context.octokit.issues.addLabels(
this.context.issue({
labels: ["Owner Merge"]
})
);
} else if (this.context.payload.issue.author_association === "MEMBER" || this.context.payload.issue.author_association === "COLLABORATOR") {
await this.context.octokit.pulls.merge({
repo: this.context.payload.repository.name,
owner: this.context.payload.repository.owner.login,
pull_number: this.context.payload.issue.number,
commit_title: `Merge PR #${this.context.payload.issue.number} ${this.context.payload.issue.title}`,
commit_message: this.context.payload.issue.title
});
console.log("Merged!");
await this.context.octokit.issues.removeLabel(
this.context.issue({
name: "Pending"
})
);
await this.context.octokit.issues.createComment(
this.context.issue({
body: `Merged by \`[MAINTAINER]\`${this.context.payload.comment.user.login}!`
})
);
} else {
return;
}
}
}

/**
* @public
* @async
* @returns {Promise<void>}
*/
public async botPRsComment(): Promise<void> {
if (this.context.payload.comment.body.toLowerCase() == "merge") {
if (this.context.payload.sender.login == this.context.payload.repository.owner.login) {
await this.context.octokit.pulls.merge({
repo: this.context.payload.repository.name,
owner: this.context.payload.repository.owner.login,
pull_number: this.context.payload.issue.number,
commit_title: `Merge PR #${this.context.payload.issue.number} ${this.context.payload.issue.title}`,
commit_message: this.context.payload.issue.title
});
console.log("Merged!");
await this.context.octokit.issues.removeLabel(
this.context.issue({
name: "Pending"
})
);
await this.context.octokit.issues.createComment(
this.context.issue({
body: `Merged by \`[OWNER]\`${this.context.payload.comment.user.login}!`
})
);
await this.context.octokit.issues.addLabels(
this.context.issue({
labels: ["Owner Merge"]
})
);
} else if (this.context.payload.issue.author_association === "MEMBER" || this.context.payload.issue.author_association === "COLLABORATOR") {
await this.context.octokit.pulls.merge({
repo: this.context.payload.repository.name,
owner: this.context.payload.repository.owner.login,
pull_number: this.context.payload.issue.number,
commit_title: `Merge PR #${this.context.payload.issue.number} ${this.context.payload.issue.title}`,
commit_message: this.context.payload.issue.title
});
console.log("Merged!");
await this.context.octokit.issues.removeLabel(
this.context.issue({
name: "Pending"
})
);
await this.context.octokit.issues.createComment(
this.context.issue({
body: `Merged by \`[MAINTAINER]\`${this.context.payload.comment.user.login}!`
})
);
} else {
return;
}
}
}
}
42 changes: 42 additions & 0 deletions src/class/issuesOpen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import Context from "../index";

/**
* @class
* @default
* @exports
*/
export default class IssuesOpen {

/**
* @private
* @type Context<"issues.opened">
*/
private context: Context<"issues.opened">;

/**
* @constructor
* @param {Context<"issues.opened">} context
*/
constructor(context: Context<"issues.opened">) {
this.context = context;
}

/**
* @public
* @async
* @returns {Promise<void>}
*/
public async open(): Promise<void> {
if (this.context.payload.sender.login === "Muunatic") return;
const issueComment = this.context.issue({
body: `Hello @${this.context.payload.sender.login} Thank you for submitting Issue, please wait for next notification after we review your Issue.`
});
console.log("Issues created");
await this.context.octokit.issues.addLabels(
this.context.issue({
labels: ["Pending"]
})
);
await this.context.octokit.issues.createComment(issueComment);
}
}
Loading