feat: actual logic

This commit is contained in:
marocchino 2019-11-21 09:49:05 +09:00
parent 29d48cbb29
commit cb9470fc12
No known key found for this signature in database
GPG key ID: AFF521DBDB122570
9 changed files with 108 additions and 147 deletions

View file

@ -1,18 +1,43 @@
import * as core from '@actions/core';
import {wait} from './wait'
import * as core from "@actions/core";
import { context, GitHub } from "@actions/github";
async function run() {
try {
const ms = core.getInput('milliseconds');
console.log(`Waiting ${ms} milliseconds ...`)
core.debug((new Date()).toTimeString())
await wait(parseInt(ms, 10));
core.debug((new Date()).toTimeString())
core.setOutput('time', new Date().toTimeString());
} catch (error) {
core.setFailed(error.message);
const repo = context.repo;
const issue_number = context?.payload?.pull_request?.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(githubToken);
const { data: comments } = await octokit.issues.listComments({
...repo,
issue_number
});
const myComment = comments.find(
comment => comment.user.login === "github-actions[bot]"
);
if (myComment) {
await octokit.issues.updateComment({
...repo,
comment_id: myComment.id,
body
});
} else {
await octokit.issues.createComment({
...repo,
issue_number,
body
});
}
} catch ({ message }) {
core.setFailed(message);
}
}

View file

@ -1,10 +0,0 @@
export function wait(milliseconds: number) {
return new Promise((resolve) => {
if (isNaN(milliseconds)) {
throw new Error('milleseconds not a number');
}
setTimeout(() => resolve("done!"), milliseconds)
});
}