From a80bd28a32ae2afe38facee44726f8e114a2cc8f Mon Sep 17 00:00:00 2001 From: Orta Date: Mon, 14 Jun 2021 21:25:56 +0100 Subject: [PATCH 1/2] Checks the issue body before editing the message --- src/updatesIssue.ts | 2 +- src/utils/api.ts | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/updatesIssue.ts b/src/updatesIssue.ts index e898f20..2d5eb9c 100644 --- a/src/updatesIssue.ts +++ b/src/updatesIssue.ts @@ -42,7 +42,7 @@ async function updateMainComment(newRuns: TwoslashResults[], api: API, issue: Is const intro = (runLength: number) => { const repros = runLength === 1 ? 'repro' : `${runLength} repros` const docsLink = 'https://github.com/microsoft/TypeScript-Twoslash-Repro-Action/tree/master/docs/user-facing.md' - return `:wave: Hi, I'm the [Repro bot](${docsLink}). I can help narrow down and track compiler bugs across releases! This comment reflects the current state of the ${repros} in this issue running against the nightly TypeScript. If something changes, I will post a new comment.
` + return `:wave: Hi, I'm the [Repro bot](${docsLink}). I can help narrow down and track compiler bugs across releases! This comment reflects the current state of the ${repros} in this issue running against the nightly TypeScript.
` } /** Above the fold */ diff --git a/src/utils/api.ts b/src/utils/api.ts index a762aac..78a99f7 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -3,6 +3,13 @@ import {Context} from '../getContext' const addComment = `mutation($input: AddCommentInput!) { addComment(input: $input) { clientMutationId } }` const editComment = `mutation($input: UpdateIssueCommentInput!) { updateIssueComment(input: $input) { clientMutationId } }` +const getComment = `query GetComment ($commentID: ID!) { + node(id: $commentID) { + ... on Comment { + body + } + } +}` export type API = ReturnType @@ -14,7 +21,13 @@ export const createAPI = (ctx: Context) => { // https://regex101.com/r/ZORaaK/1 const sanitizedBody = body.replace(/home\/runner\/work\/TypeScript-Twoslash-Repro-Action\/TypeScript-Twoslash-Repro-Action\/dist/g, "[root]") if (commentID) { - await octokit.graphql(editComment, {input: {id: commentID, body: sanitizedBody}}) + const commentReq = await octokit.graphql<{ node: { body: string }}>(getComment, { commentID }) + const commentBody = commentReq.node.body + // TODO: Remove + console.log(commentBody) + if (commentBody !== sanitizedBody) { + await octokit.graphql(editComment, {input: {id: commentID, body: sanitizedBody}}) + } } else { await octokit.graphql(addComment, {input: {subjectId: issueID, body: sanitizedBody}}) } From c593ab61a91afd74383676eb2a508c19300d2ac0 Mon Sep 17 00:00:00 2001 From: Orta Date: Mon, 14 Jun 2021 21:29:49 +0100 Subject: [PATCH 2/2] Support TS 4.4 --- src/runTwoslashRuns.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/runTwoslashRuns.ts b/src/runTwoslashRuns.ts index 88a9d36..f9dcf34 100644 --- a/src/runTwoslashRuns.ts +++ b/src/runTwoslashRuns.ts @@ -21,7 +21,7 @@ export type TwoslashResults = { label: string // e.g. 3.9.5 description: string // e.g. Issue body by orta state: RunState - commentID?: string + commentID?: string | undefined } export function runTwoslashRuns(issue: Issue, runs: TwoslashRun): TwoslashResults[] { @@ -68,7 +68,7 @@ export const runTwoSlash = (label: string) => ( try { const opts = {noErrorValidation: true, noStaticSemanticInfo: true} result = twoslasher(run.block.content, run.block.lang, {defaultOptions: opts, tsModule}) - } catch (error) { + } catch (error: any) { return { assertions: [], fails: [],