Skip to content

Checks the issue body before editing the message #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/runTwoslashRuns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] {
Expand Down Expand Up @@ -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: [],
Expand Down
2 changes: 1 addition & 1 deletion src/updatesIssue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.<hr />`
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.<hr />`
}

/** Above the fold */
Expand Down
15 changes: 14 additions & 1 deletion src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof createAPI>

Expand All @@ -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}})
}
Expand Down