mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2026-04-07 23:10:07 +00:00
feat: actual logic
This commit is contained in:
parent
29d48cbb29
commit
cb9470fc12
9 changed files with 108 additions and 147 deletions
38
lib/main.js
38
lib/main.js
|
|
@ -1,9 +1,10 @@
|
|||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
|
|
@ -16,19 +17,36 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const wait_1 = require("./wait");
|
||||
const github_1 = require("@actions/github");
|
||||
function run() {
|
||||
var _a, _b, _c;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
const ms = core.getInput('milliseconds');
|
||||
console.log(`Waiting ${ms} milliseconds ...`);
|
||||
core.debug((new Date()).toTimeString());
|
||||
wait_1.wait(parseInt(ms));
|
||||
core.debug((new Date()).toTimeString());
|
||||
core.setOutput('time', new Date().toTimeString());
|
||||
const repo = github_1.context.repo;
|
||||
const issue_number = (_c = (_b = (_a = github_1.context) === null || _a === void 0 ? void 0 : _a.payload) === null || _b === void 0 ? void 0 : _b.pull_request) === null || _c === void 0 ? void 0 : _c.number;
|
||||
if (!issue_number) {
|
||||
core.setFailed("This action only works for pull_request");
|
||||
return;
|
||||
}
|
||||
const body = core.getInput("message");
|
||||
const githubToken = core.getInput("GITHUB_TOKEN");
|
||||
if (!body || !githubToken) {
|
||||
core.setFailed("invalid input: please check your workflow");
|
||||
return;
|
||||
}
|
||||
const octokit = new github_1.GitHub(githubToken);
|
||||
const { data: comments } = yield octokit.issues.listComments(Object.assign(Object.assign({}, repo), { issue_number }));
|
||||
const myComment = comments.find(comment => comment.user.login === "github-actions[bot]");
|
||||
if (myComment) {
|
||||
yield octokit.issues.updateComment(Object.assign(Object.assign({}, repo), { comment_id: myComment.id, body }));
|
||||
}
|
||||
else {
|
||||
yield octokit.issues.createComment(Object.assign(Object.assign({}, repo), { issue_number,
|
||||
body }));
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
core.setFailed(error.message);
|
||||
catch ({ message }) {
|
||||
core.setFailed(message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
11
lib/wait.js
11
lib/wait.js
|
|
@ -1,11 +0,0 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
function wait(milliseconds) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (typeof (milliseconds) !== 'number') {
|
||||
throw new Error('milleseconds not a number');
|
||||
}
|
||||
setTimeout(() => resolve("done!"), milliseconds);
|
||||
});
|
||||
}
|
||||
exports.wait = wait;
|
||||
Loading…
Add table
Add a link
Reference in a new issue