feat: add welcome (#19)

* feat: add welcome

* add

* fix

* add

* add

* add

* fix

* add doc

* update
This commit is contained in:
xrkffgg
2020-12-28 14:03:32 +08:00
committed by GitHub
parent c5b5ee5c35
commit bbb5bbb425
12 changed files with 398 additions and 84 deletions

View File

@@ -1,7 +1,10 @@
require('dotenv').config();
const core = require("@actions/core");
const github = require("@actions/github");
const { Octokit } = require('@octokit/rest');
const { doQueryIssues } = require('./advanced.js');
const ALLREACTIONS = [
"+1",
"-1",
@@ -19,6 +22,7 @@ const token = core.getInput('token');
const octokit = new Octokit({ auth: `token ${token}` });
const contents = core.getInput("contents");
const issueContents = core.getInput("issue-contents");
async function doAddAssignees (owner, repo, issueNumber, assignees) {
await octokit.issues.addAssignees({
@@ -296,6 +300,41 @@ async function doUpdateIssue (
}
};
async function doWelcome (owner, repo, assignees, labels, body) {
const context = github.context;
const isIssue = !!context.payload.issue;
if (!isIssue) {
core.setFailed("The event that triggered this action must be a issue. Error!");
} else {
const auth = context.payload.sender.login;
core.info(`Actions: [welcome: auth=][${auth}]`);
const issueNumber = context.issue.number;
const creator = 'zoo-js-bot';
const issues = await doQueryIssues(owner, repo, false, 'all', creator);
if (issues.length == 0 || (issues.length == 1 && issues[0].number == issueNumber)) {
if (core.getInput("body")) {
await doCreateComment(owner, repo, issueNumber, body);
} else {
core.info(`Actions: [welcome] no body!`);
}
if (assignees) {
await doAddAssignees(owner, repo, issueNumber, assignees);
}
if (labels) {
await doAddLabels(owner, repo, issueNumber, labels);
}
if (issueContents) {
await doCreateIssueContent(owner, repo, issueNumber, dealInput(issueContents));
}
} else {
core.info(`Actions: [welcome][${auth}] is not first time!`);
}
}
};
// tool
function testContent(con) {
if (ALLREACTIONS.includes(con)) {
@@ -324,4 +363,5 @@ module.exports = {
doUnlockIssue,
doUpdateComment,
doUpdateIssue,
doWelcome,
};