mirror of
https://github.com/mshick/add-pr-comment.git
synced 2026-01-02 14:59:43 +11:00
Adding the possibility to auto refresh the sticky comment position... (#66)
* Allow to refresh the uniq comment position to be the latest one in the PR feed. * Allow to refresh the uniq comment position to be the latest one in the PR feed. * Removed "auto-" from func name + now defaulting new option to "false"
This commit is contained in:
parent
a65df5f64f
commit
fe6766b6b0
10 changed files with 2641 additions and 2572 deletions
|
|
@ -1,6 +1,6 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createComment = exports.updateComment = exports.getExistingCommentId = void 0;
|
||||
exports.createComment = exports.deleteComment = exports.updateComment = exports.getExistingCommentId = void 0;
|
||||
async function getExistingCommentId(octokit, owner, repo, issueNumber, messageId) {
|
||||
const parameters = {
|
||||
owner,
|
||||
|
|
@ -31,6 +31,16 @@ async function updateComment(octokit, owner, repo, existingCommentId, body) {
|
|||
return updatedComment.data;
|
||||
}
|
||||
exports.updateComment = updateComment;
|
||||
async function deleteComment(octokit, owner, repo, existingCommentId, body) {
|
||||
const deletedComment = await octokit.rest.issues.deleteComment({
|
||||
comment_id: existingCommentId,
|
||||
owner,
|
||||
repo,
|
||||
body,
|
||||
});
|
||||
return deletedComment.data;
|
||||
}
|
||||
exports.deleteComment = deleteComment;
|
||||
async function createComment(octokit, owner, repo, issueNumber, body) {
|
||||
const createdComment = await octokit.rest.issues.createComment({
|
||||
issue_number: issueNumber,
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ async function getInputs() {
|
|||
const issue = core.getInput('issue', { required: false });
|
||||
const proxyUrl = core.getInput('proxy-url', { required: false }).replace(/\/$/, '');
|
||||
const allowRepeats = core.getInput('allow-repeats', { required: true }) === 'true';
|
||||
const refreshMessagePosition = core.getInput('refresh-message-position', { required: false }) === 'true';
|
||||
if (messageInput && messagePath) {
|
||||
throw new Error('must specify only one, message or message-path');
|
||||
}
|
||||
|
|
@ -73,6 +74,7 @@ async function getInputs() {
|
|||
}
|
||||
const [owner, repo] = repoFullName.split('/');
|
||||
return {
|
||||
refreshMessagePosition,
|
||||
allowRepeats,
|
||||
message,
|
||||
messageId: `<!-- ${messageId} -->`,
|
||||
|
|
|
|||
10
lib/main.js
10
lib/main.js
|
|
@ -31,7 +31,7 @@ const issues_1 = require("./issues");
|
|||
const proxy_1 = require("./proxy");
|
||||
const run = async () => {
|
||||
try {
|
||||
const { allowRepeats, message, messageId, repoToken, proxyUrl, issue, pullRequestNumber, commitSha, repo, owner, } = await (0, config_1.getInputs)();
|
||||
const { allowRepeats, message, messageId, refreshMessagePosition, repoToken, proxyUrl, issue, pullRequestNumber, commitSha, repo, owner, } = await (0, config_1.getInputs)();
|
||||
const octokit = github.getOctokit(repoToken);
|
||||
let issueNumber;
|
||||
if (issue) {
|
||||
|
|
@ -72,7 +72,13 @@ const run = async () => {
|
|||
core.setOutput(existingCommentId ? 'comment-updated' : 'comment-created', 'true');
|
||||
}
|
||||
else if (existingCommentId) {
|
||||
comment = await (0, comments_1.updateComment)(octokit, owner, repo, existingCommentId, body);
|
||||
if (refreshMessagePosition) {
|
||||
await (0, comments_1.deleteComment)(octokit, owner, repo, existingCommentId, body);
|
||||
comment = await (0, comments_1.createComment)(octokit, owner, repo, issueNumber, body);
|
||||
}
|
||||
else {
|
||||
comment = await (0, comments_1.updateComment)(octokit, owner, repo, existingCommentId, body);
|
||||
}
|
||||
core.setOutput('comment-updated', 'true');
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue