mirror of
https://github.com/mshick/add-pr-comment.git
synced 2025-12-31 22:29:45 +11:00
Issue number (#64)
* Major code reorg * Add issue arg * Paginate existing comment list
This commit is contained in:
parent
e8076c64f7
commit
8645f3f0ea
17 changed files with 2187 additions and 1968 deletions
71
src/comments.ts
Normal file
71
src/comments.ts
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import { GitHub } from '@actions/github/lib/utils'
|
||||
import { Endpoints } from '@octokit/types'
|
||||
|
||||
export type CreateIssueCommentResponseData =
|
||||
Endpoints['POST /repos/{owner}/{repo}/issues/{issue_number}/comments']['response']['data']
|
||||
|
||||
export async function getExistingCommentId(
|
||||
octokit: InstanceType<typeof GitHub>,
|
||||
owner: string,
|
||||
repo: string,
|
||||
issueNumber: number,
|
||||
messageId: string,
|
||||
): Promise<number | undefined> {
|
||||
const parameters = {
|
||||
owner,
|
||||
repo,
|
||||
issue_number: issueNumber,
|
||||
per_page: 100,
|
||||
}
|
||||
|
||||
let found
|
||||
|
||||
for await (const comments of octokit.paginate.iterator(
|
||||
octokit.rest.issues.listComments,
|
||||
parameters,
|
||||
)) {
|
||||
found = comments.data.find(({ body }) => {
|
||||
return (body?.search(messageId) ?? -1) > -1
|
||||
})
|
||||
|
||||
if (found) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return found?.id
|
||||
}
|
||||
|
||||
export async function updateComment(
|
||||
octokit: InstanceType<typeof GitHub>,
|
||||
owner: string,
|
||||
repo: string,
|
||||
existingCommentId: number,
|
||||
body: string,
|
||||
): Promise<CreateIssueCommentResponseData> {
|
||||
const updatedComment = await octokit.rest.issues.updateComment({
|
||||
comment_id: existingCommentId,
|
||||
owner,
|
||||
repo,
|
||||
body,
|
||||
})
|
||||
|
||||
return updatedComment.data
|
||||
}
|
||||
|
||||
export async function createComment(
|
||||
octokit: InstanceType<typeof GitHub>,
|
||||
owner: string,
|
||||
repo: string,
|
||||
issueNumber: number,
|
||||
body: string,
|
||||
): Promise<CreateIssueCommentResponseData> {
|
||||
const createdComment = await octokit.rest.issues.createComment({
|
||||
issue_number: issueNumber,
|
||||
owner,
|
||||
repo,
|
||||
body,
|
||||
})
|
||||
|
||||
return createdComment.data
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue