mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2025-12-13 20:21:13 +00:00
Add option to read message from path
This commit is contained in:
parent
b687a2750c
commit
834b325ec2
4 changed files with 42 additions and 3 deletions
|
|
@ -90,6 +90,15 @@ with:
|
||||||
This is message from push.
|
This is message from push.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Read comment from a file
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
uses: marocchino/sticky-pull-request-comment@v1
|
||||||
|
with:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
path: path-to-comment-contents.txt
|
||||||
|
```
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
Install the dependencies
|
Install the dependencies
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,10 @@ inputs:
|
||||||
required: false
|
required: false
|
||||||
message:
|
message:
|
||||||
description: "comment message"
|
description: "comment message"
|
||||||
required: true
|
required: false
|
||||||
|
path:
|
||||||
|
description: "path to file containing comment message"
|
||||||
|
required: false
|
||||||
number:
|
number:
|
||||||
description: "pull request number for push event"
|
description: "pull request number for push event"
|
||||||
required: false
|
required: false
|
||||||
|
|
|
||||||
14
lib/main.js
14
lib/main.js
|
|
@ -19,6 +19,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const core = __importStar(require("@actions/core"));
|
const core = __importStar(require("@actions/core"));
|
||||||
const github_1 = require("@actions/github");
|
const github_1 = require("@actions/github");
|
||||||
const comment_1 = require("./comment");
|
const comment_1 = require("./comment");
|
||||||
|
const fs_1 = require("fs");
|
||||||
function run() {
|
function run() {
|
||||||
var _a, _b;
|
var _a, _b;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
|
@ -30,12 +31,23 @@ function run() {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const repo = github_1.context.repo;
|
const repo = github_1.context.repo;
|
||||||
const body = core.getInput("message", { required: true });
|
const message = core.getInput("message", { required: false });
|
||||||
|
const path = core.getInput("path", { required: false });
|
||||||
const header = core.getInput("header", { required: false }) || "";
|
const header = core.getInput("header", { required: false }) || "";
|
||||||
const append = core.getInput("append", { required: false }) || false;
|
const append = core.getInput("append", { required: false }) || false;
|
||||||
const githubToken = core.getInput("GITHUB_TOKEN", { required: true });
|
const githubToken = core.getInput("GITHUB_TOKEN", { required: true });
|
||||||
const octokit = new github_1.GitHub(githubToken);
|
const octokit = new github_1.GitHub(githubToken);
|
||||||
const previous = yield comment_1.findPreviousComment(octokit, repo, number, header);
|
const previous = yield comment_1.findPreviousComment(octokit, repo, number, header);
|
||||||
|
if (!message && !path) {
|
||||||
|
throw { message: 'Either message or path input is required' };
|
||||||
|
}
|
||||||
|
let body;
|
||||||
|
if (path) {
|
||||||
|
body = fs_1.readFileSync(path);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
body = message;
|
||||||
|
}
|
||||||
if (previous) {
|
if (previous) {
|
||||||
if (append) {
|
if (append) {
|
||||||
yield comment_1.updateComment(octokit, repo, previous.id, body, header, previous.body);
|
yield comment_1.updateComment(octokit, repo, previous.id, body, header, previous.body);
|
||||||
|
|
|
||||||
17
src/main.ts
17
src/main.ts
|
|
@ -1,6 +1,7 @@
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import { context, GitHub } from "@actions/github";
|
import { context, GitHub } from "@actions/github";
|
||||||
import { findPreviousComment, createComment, updateComment } from "./comment";
|
import { findPreviousComment, createComment, updateComment } from "./comment";
|
||||||
|
import { readFileSync } from 'fs';
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
const number =
|
const number =
|
||||||
|
|
@ -13,12 +14,26 @@ async function run() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const repo = context.repo;
|
const repo = context.repo;
|
||||||
const body = core.getInput("message", { required: true });
|
const message = core.getInput("message", { required: false });
|
||||||
|
const path = core.getInput("path", { required: false });
|
||||||
const header = core.getInput("header", { required: false }) || "";
|
const header = core.getInput("header", { required: false }) || "";
|
||||||
const append = core.getInput("append", { required: false }) || false;
|
const append = core.getInput("append", { required: false }) || false;
|
||||||
const githubToken = core.getInput("GITHUB_TOKEN", { required: true });
|
const githubToken = core.getInput("GITHUB_TOKEN", { required: true });
|
||||||
const octokit = new GitHub(githubToken);
|
const octokit = new GitHub(githubToken);
|
||||||
const previous = await findPreviousComment(octokit, repo, number, header);
|
const previous = await findPreviousComment(octokit, repo, number, header);
|
||||||
|
|
||||||
|
if (!message && !path) {
|
||||||
|
throw { message: 'Either message or path input is required' };
|
||||||
|
}
|
||||||
|
|
||||||
|
let body;
|
||||||
|
|
||||||
|
if (path) {
|
||||||
|
body = readFileSync(path);
|
||||||
|
} else {
|
||||||
|
body = message;
|
||||||
|
}
|
||||||
|
|
||||||
if (previous) {
|
if (previous) {
|
||||||
if (append) {
|
if (append) {
|
||||||
await updateComment(octokit, repo, previous.id, body, header, previous.body);
|
await updateComment(octokit, repo, previous.id, body, header, previous.body);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue