mirror of
https://github.com/mshick/add-pr-comment.git
synced 2026-01-01 22:49:45 +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
|
|
@ -53,6 +53,23 @@ export async function updateComment(
|
|||
return updatedComment.data
|
||||
}
|
||||
|
||||
export async function deleteComment(
|
||||
octokit: InstanceType<typeof GitHub>,
|
||||
owner: string,
|
||||
repo: string,
|
||||
existingCommentId: number,
|
||||
body: string,
|
||||
): Promise<CreateIssueCommentResponseData> {
|
||||
const deletedComment = await octokit.rest.issues.deleteComment({
|
||||
comment_id: existingCommentId,
|
||||
owner,
|
||||
repo,
|
||||
body,
|
||||
})
|
||||
|
||||
return deletedComment.data
|
||||
}
|
||||
|
||||
export async function createComment(
|
||||
octokit: InstanceType<typeof GitHub>,
|
||||
owner: string,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import * as github from '@actions/github'
|
|||
import fs from 'node:fs/promises'
|
||||
|
||||
interface Inputs {
|
||||
refreshMessagePosition: boolean
|
||||
allowRepeats: boolean
|
||||
message?: string
|
||||
messageId: string
|
||||
|
|
@ -30,6 +31,8 @@ export async function getInputs(): Promise<Inputs> {
|
|||
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')
|
||||
|
|
@ -74,6 +77,7 @@ export async function getInputs(): Promise<Inputs> {
|
|||
const [owner, repo] = repoFullName.split('/')
|
||||
|
||||
return {
|
||||
refreshMessagePosition,
|
||||
allowRepeats,
|
||||
message,
|
||||
messageId: `<!-- ${messageId} -->`,
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import {
|
|||
CreateIssueCommentResponseData,
|
||||
getExistingCommentId,
|
||||
updateComment,
|
||||
deleteComment,
|
||||
} from './comments'
|
||||
import { getInputs } from './config'
|
||||
import { getIssueNumberFromCommitPullsList } from './issues'
|
||||
|
|
@ -16,6 +17,7 @@ const run = async (): Promise<void> => {
|
|||
allowRepeats,
|
||||
message,
|
||||
messageId,
|
||||
refreshMessagePosition,
|
||||
repoToken,
|
||||
proxyUrl,
|
||||
issue,
|
||||
|
|
@ -74,7 +76,12 @@ const run = async (): Promise<void> => {
|
|||
})
|
||||
core.setOutput(existingCommentId ? 'comment-updated' : 'comment-created', 'true')
|
||||
} else if (existingCommentId) {
|
||||
comment = await updateComment(octokit, owner, repo, existingCommentId, body)
|
||||
if (refreshMessagePosition) {
|
||||
await deleteComment(octokit, owner, repo, existingCommentId, body)
|
||||
comment = await createComment(octokit, owner, repo, issueNumber, body)
|
||||
} else {
|
||||
comment = await updateComment(octokit, owner, repo, existingCommentId, body)
|
||||
}
|
||||
core.setOutput('comment-updated', 'true')
|
||||
} else {
|
||||
comment = await createComment(octokit, owner, repo, issueNumber, body)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue