d7002057d7
This PR moves the tldraw.com app into the public repo. ### Change Type - [x] `internal` — Any other changes that don't affect the published package[^2] --------- Co-authored-by: Dan Groshev <git@dgroshev.com> Co-authored-by: alex <alex@dytry.ch>
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { APP_USER_NAME, TLDRAW_ORG, TLDRAW_PUBLIC_REPO } from './config'
|
|
import { Ctx } from './ctx'
|
|
|
|
export async function findHuppyCommentIfExists(ctx: Ctx, prNumber: number) {
|
|
const { data: comments } = await ctx.octokit.rest.issues.listComments({
|
|
owner: TLDRAW_ORG,
|
|
repo: TLDRAW_PUBLIC_REPO,
|
|
issue_number: prNumber,
|
|
per_page: 100,
|
|
sort: 'created',
|
|
direction: 'asc',
|
|
})
|
|
|
|
const foundComment = comments.find((comment) => comment.user?.login === APP_USER_NAME)
|
|
|
|
return foundComment ?? null
|
|
}
|
|
|
|
export async function updateHuppyCommentIfExists(ctx: Ctx, prNumber: number, body: string) {
|
|
const foundComment = await findHuppyCommentIfExists(ctx, prNumber)
|
|
if (foundComment) {
|
|
await ctx.octokit.rest.issues.updateComment({
|
|
owner: TLDRAW_ORG,
|
|
repo: TLDRAW_PUBLIC_REPO,
|
|
comment_id: foundComment.id,
|
|
body,
|
|
})
|
|
}
|
|
}
|
|
|
|
export async function createOrUpdateHuppyComment(ctx: Ctx, prNumber: number, body: string) {
|
|
const foundComment = await findHuppyCommentIfExists(ctx, prNumber)
|
|
if (foundComment) {
|
|
await ctx.octokit.rest.issues.updateComment({
|
|
owner: TLDRAW_ORG,
|
|
repo: TLDRAW_PUBLIC_REPO,
|
|
comment_id: foundComment.id,
|
|
body,
|
|
})
|
|
} else {
|
|
await ctx.octokit.rest.issues.createComment({
|
|
owner: TLDRAW_ORG,
|
|
repo: TLDRAW_PUBLIC_REPO,
|
|
issue_number: prNumber,
|
|
body,
|
|
})
|
|
}
|
|
}
|