mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2026-04-20 21:24:07 +00:00
dist with new generator
This commit is contained in:
parent
6b16c03623
commit
831680f812
8 changed files with 6804 additions and 68 deletions
80
src/main.ts
80
src/main.ts
|
|
@ -1,61 +1,77 @@
|
|||
import * as core from "@actions/core";
|
||||
import * as github from "@actions/github";
|
||||
import { findPreviousComment, createComment, updateComment, deleteComment } from "./comment";
|
||||
import { readFileSync } from 'fs';
|
||||
import * as core from '@actions/core'
|
||||
import * as github from '@actions/github'
|
||||
import {
|
||||
findPreviousComment,
|
||||
createComment,
|
||||
updateComment,
|
||||
deleteComment
|
||||
} from './comment'
|
||||
import {readFileSync} from 'fs'
|
||||
|
||||
async function run() {
|
||||
async function run(): Promise<undefined> {
|
||||
const number =
|
||||
github.context?.payload?.pull_request?.number ||
|
||||
+core.getInput("number", { required: false });
|
||||
+core.getInput('number', {required: false})
|
||||
if (isNaN(number) || number < 1) {
|
||||
core.info("no numbers given: skip step");
|
||||
return;
|
||||
core.info('no pull request numbers given: skip step')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const repo = core.getInput("repo", { required: false }) || github.context.repo;
|
||||
const message = core.getInput("message", { required: false });
|
||||
const path = core.getInput("path", { required: false });
|
||||
const header = core.getInput("header", { required: false }) || "";
|
||||
const append = (core.getInput("append", { required: false }) || "false") === "true";
|
||||
const recreate = (core.getInput("recreate", { required: false }) || "false") === "true";
|
||||
const deleteOldComment = (core.getInput("delete", { required: false }) || "false") === "true";
|
||||
const githubToken = core.getInput("GITHUB_TOKEN", { required: true });
|
||||
const octokit = github.getOctokit(githubToken);
|
||||
const previous = await findPreviousComment(octokit, repo, number, header);
|
||||
const repo = github.context.repo
|
||||
repo.repo = core.getInput('repo', {required: false}) || repo.repo
|
||||
const message = core.getInput('message', {required: false})
|
||||
const path = core.getInput('path', {required: false})
|
||||
const header = core.getInput('header', {required: false}) || ''
|
||||
const append =
|
||||
(core.getInput('append', {required: false}) || 'false') === 'true'
|
||||
const recreate =
|
||||
(core.getInput('recreate', {required: false}) || 'false') === 'true'
|
||||
const deleteOldComment =
|
||||
(core.getInput('delete', {required: false}) || 'false') === 'true'
|
||||
const githubToken = core.getInput('GITHUB_TOKEN', {required: true})
|
||||
const octokit = github.getOctokit(githubToken)
|
||||
const previous = await findPreviousComment(octokit, repo, number, header)
|
||||
|
||||
if (!deleteOldComment && !message && !path) {
|
||||
throw { message: 'Either message or path input is required' };
|
||||
throw new Error('Either message or path input is required')
|
||||
}
|
||||
|
||||
if (deleteOldComment && recreate) {
|
||||
throw { message: 'delete and recreate cannot be both set to true' };
|
||||
throw new Error('delete and recreate cannot be both set to true')
|
||||
}
|
||||
|
||||
let body;
|
||||
let body
|
||||
|
||||
if (path) {
|
||||
body = readFileSync(path, 'utf-8');
|
||||
body = readFileSync(path, 'utf-8')
|
||||
} else {
|
||||
body = message;
|
||||
body = message
|
||||
}
|
||||
|
||||
if (previous) {
|
||||
const previousBody = append && previous.body;
|
||||
const previousBody = append ? previous.body : undefined
|
||||
if (deleteOldComment) {
|
||||
await deleteComment(octokit, repo, previous.id);
|
||||
await deleteComment(octokit, repo, previous.id)
|
||||
} else if (recreate) {
|
||||
await deleteComment(octokit, repo, previous.id);
|
||||
await createComment(octokit, repo, number, body, header, previousBody);
|
||||
await deleteComment(octokit, repo, previous.id)
|
||||
await createComment(octokit, repo, number, body, header, previousBody)
|
||||
} else {
|
||||
await updateComment(octokit, repo, previous.id, body, header, previousBody);
|
||||
await updateComment(
|
||||
octokit,
|
||||
repo,
|
||||
previous.id,
|
||||
body,
|
||||
header,
|
||||
previousBody
|
||||
)
|
||||
}
|
||||
} else {
|
||||
await createComment(octokit, repo, number, body, header);
|
||||
await createComment(octokit, repo, number, body, header)
|
||||
}
|
||||
} catch ({ message }) {
|
||||
core.setFailed(message);
|
||||
} catch (error) {
|
||||
core.setFailed(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
||||
run()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue