mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2026-04-11 08:50:04 +00:00
feat: actual logic
This commit is contained in:
parent
29d48cbb29
commit
cb9470fc12
9 changed files with 108 additions and 147 deletions
49
src/main.ts
49
src/main.ts
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue