feat: update/delete comment support find-comments out (#63)

* fix: find comments

* add out

* add more

* add

* add doc

* fix link

* perf

* update doc

* Update gh-pages.yml

* Update .github/workflows/gh-pages.yml
This commit is contained in:
xrkffgg
2021-02-19 17:51:19 +08:00
committed by GitHub
parent 19c073d744
commit efca7df548
14 changed files with 222 additions and 92 deletions

89
dist/index.js vendored
View File

@@ -7705,6 +7705,7 @@ async function doFindComments(owner, repo, issueNumber) {
}
});
core.setOutput('comments', comments);
core.info(`out-comments: ${JSON.stringify(comments)}`);
}
async function doLockIssues(owner, repo, labels) {
@@ -8010,12 +8011,27 @@ async function doCreateLabel(owner, repo) {
}
async function doDeleteComment(owner, repo, commentId) {
await octokit.issues.deleteComment({
owner,
repo,
comment_id: commentId,
});
core.info(`Actions: [delete-comment][${commentId}] success!`);
let id = commentId;
const outComments = core.getInput('out-comments');
if (outComments) {
const outCommentsArr = JSON.parse(outComments);
core.info(`Actions: [out-comments-length][${outCommentsArr.length}] success!`);
outCommentsArr.forEach(async item => {
await doDelet(item.id);
});
} else {
await doDelet(id);
}
async function doDelet(id) {
await octokit.issues.deleteComment({
owner,
repo,
comment_id: id,
});
core.info(`Actions: [delete-comment][${id}] success!`);
}
}
async function doLockIssue(owner, repo, issueNumber) {
@@ -8193,32 +8209,47 @@ async function doUnlockIssue(owner, repo, issueNumber) {
}
async function doUpdateComment(owner, repo, commentId, body, updateMode, ifUpdateBody) {
const comment = await octokit.issues.getComment({
owner,
repo,
comment_id: commentId,
});
const comment_body = comment.data.body;
let id = commentId;
let params = {
owner,
repo,
comment_id: commentId,
};
if (core.getInput('body') || ifUpdateBody) {
if (updateMode === 'append') {
params.body = `${comment_body}\n${body}`;
} else {
params.body = body;
}
await octokit.issues.updateComment(params);
core.info(`Actions: [update-comment][${commentId}] success!`);
const outComments = core.getInput('out-comments');
if (outComments) {
const outCommentsArr = JSON.parse(outComments);
core.info(`Actions: [out-comments-length][${outCommentsArr.length}] success!`);
outCommentsArr.forEach(async item => {
await doComment(item.id);
});
} else {
await doComment(id);
}
if (contents) {
await doCreateCommentContent(owner, repo, commentId, dealStringToArr(contents));
async function doComment(id) {
const comment = await octokit.issues.getComment({
owner,
repo,
comment_id: id,
});
const comment_body = comment.data.body;
let params = {
owner,
repo,
comment_id: id,
};
if (core.getInput('body') || ifUpdateBody) {
if (updateMode === 'append') {
params.body = `${comment_body}\n${body}`;
} else {
params.body = body;
}
await octokit.issues.updateComment(params);
core.info(`Actions: [update-comment][${id}] success!`);
}
if (contents) {
await doCreateCommentContent(owner, repo, id, dealStringToArr(contents));
}
}
}