@@ -168,7 +168,9 @@ try { |
168 | 168 | const summary = await summarize(response) |
169 | 169 | await pushToLocalBranch(summary) |
170 | 170 | } |
171 | | - const hasShared = prData.comments.nodes.some((c) => c.body.includes(`${useShareUrl()}/s/${shareId}`)) |
| 171 | + const hasShared = prData.comments.nodes.some((c) => |
| 172 | + c.body.includes(`${useShareUrl()}/s/${shareId}`), |
| 173 | + ) |
172 | 174 | await updateComment(`${response}${footer({ image: !hasShared })}`) |
173 | 175 | } |
174 | 176 | // Fork PR |
@@ -180,7 +182,9 @@ try { |
180 | 182 | const summary = await summarize(response) |
181 | 183 | await pushToForkBranch(summary, prData) |
182 | 184 | } |
183 | | - const hasShared = prData.comments.nodes.some((c) => c.body.includes(`${useShareUrl()}/s/${shareId}`)) |
| 185 | + const hasShared = prData.comments.nodes.some((c) => |
| 186 | + c.body.includes(`${useShareUrl()}/s/${shareId}`), |
| 187 | + ) |
184 | 188 | await updateComment(`${response}${footer({ image: !hasShared })}`) |
185 | 189 | } |
186 | 190 | } |
@@ -361,7 +365,9 @@ async function getAccessToken() { |
361 | 365 |
|
362 | 366 | if (!response.ok) { |
363 | 367 | const responseJson = (await response.json()) as { error?: string } |
364 | | - throw new Error(`App token exchange failed: ${response.status} ${response.statusText} - ${responseJson.error}`) |
| 368 | + throw new Error( |
| 369 | + `App token exchange failed: ${response.status} ${response.statusText} - ${responseJson.error}`, |
| 370 | + ) |
365 | 371 | } |
366 | 372 |
|
367 | 373 | const responseJson = (await response.json()) as { token: string } |
@@ -402,8 +408,12 @@ async function getUserPrompt() { |
402 | 408 | // ie. <img alt="Image" src="https://github.com/user-attachments/assets/xxxx" /> |
403 | 409 | // ie. [api.json](https://github.com/user-attachments/files/21433810/api.json) |
404 | 410 | // ie.  |
405 | | - const mdMatches = prompt.matchAll(/!?\[.*?\]\((https:\/\/github\.com\/user-attachments\/[^)]+)\)/gi) |
406 | | - const tagMatches = prompt.matchAll(/<img .*?src="(https:\/\/github\.com\/user-attachments\/[^"]+)" \/>/gi) |
| 411 | + const mdMatches = prompt.matchAll( |
| 412 | + /!?\[.*?\]\((https:\/\/github\.com\/user-attachments\/[^)]+)\)/gi, |
| 413 | + ) |
| 414 | + const tagMatches = prompt.matchAll( |
| 415 | + /<img .*?src="(https:\/\/github\.com\/user-attachments\/[^"]+)" \/>/gi, |
| 416 | + ) |
407 | 417 | const matches = [...mdMatches, ...tagMatches].sort((a, b) => a.index - b.index) |
408 | 418 | console.log("Images", JSON.stringify(matches, null, 2)) |
409 | 419 |
|
@@ -430,7 +440,8 @@ async function getUserPrompt() { |
430 | 440 |
|
431 | 441 | // Replace img tag with file path, ie. @image.png |
432 | 442 | const replacement = `@${filename}` |
433 | | - prompt = prompt.slice(0, start + offset) + replacement + prompt.slice(start + offset + tag.length) |
| 443 | + prompt = |
| 444 | + prompt.slice(0, start + offset) + replacement + prompt.slice(start + offset + tag.length) |
434 | 445 | offset += replacement.length - tag.length |
435 | 446 |
|
436 | 447 | const contentType = res.headers.get("content-type") |
@@ -498,7 +509,12 @@ async function subscribeSessionEvents() { |
498 | 509 | ? JSON.stringify(part.state.input) |
499 | 510 | : "Unknown" |
500 | 511 | console.log() |
501 | | - console.log(color + `|`, "\x1b[0m\x1b[2m" + ` ${tool.padEnd(7, " ")}`, "", "\x1b[0m" + title) |
| 512 | + console.log( |
| 513 | + color + `|`, |
| 514 | + "\x1b[0m\x1b[2m" + ` ${tool.padEnd(7, " ")}`, |
| 515 | + "", |
| 516 | + "\x1b[0m" + title, |
| 517 | + ) |
502 | 518 | } |
503 | 519 |
|
504 | 520 | if (part.type === "text") { |
@@ -710,7 +726,8 @@ async function assertPermissions() { |
710 | 726 | throw new Error(`Failed to check permissions for user ${actor}: ${error}`) |
711 | 727 | } |
712 | 728 |
|
713 | | - if (!["admin", "write"].includes(permission)) throw new Error(`User ${actor} does not have write permissions`) |
| 729 | + if (!["admin", "write"].includes(permission)) |
| 730 | + throw new Error(`User ${actor} does not have write permissions`) |
714 | 731 | } |
715 | 732 |
|
716 | 733 | async function updateComment(body: string) { |
@@ -730,12 +747,13 @@ async function updateComment(body: string) { |
730 | 747 | async function createPR(base: string, branch: string, title: string, body: string) { |
731 | 748 | console.log("Creating pull request...") |
732 | 749 | const { repo } = useContext() |
| 750 | + const truncatedTitle = title.length > 256 ? title.slice(0, 253) + "..." : title |
733 | 751 | const pr = await octoRest.rest.pulls.create({ |
734 | 752 | owner: repo.owner, |
735 | 753 | repo: repo.repo, |
736 | 754 | head: branch, |
737 | 755 | base, |
738 | | - title, |
| 756 | + title: truncatedTitle, |
739 | 757 | body, |
740 | 758 | }) |
741 | 759 | return pr.data.number |
@@ -753,7 +771,9 @@ function footer(opts?: { image?: boolean }) { |
753 | 771 |
|
754 | 772 | return `<a href="${useShareUrl()}/s/${shareId}"><img width="200" alt="${titleAlt}" src="https://social-cards.sst.dev/opencode-share/${title64}.png?model=${providerID}/${modelID}&version=${session.version}&id=${shareId}" /></a>\n` |
755 | 773 | })() |
756 | | - const shareUrl = shareId ? `[opencode session](${useShareUrl()}/s/${shareId}) | ` : "" |
| 774 | + const shareUrl = shareId |
| 775 | + ? `[opencode session](${useShareUrl()}/s/${shareId}) | ` |
| 776 | + : "" |
757 | 777 | return `\n\n${image}${shareUrl}[github run](${useEnvRunUrl()})` |
758 | 778 | } |
759 | 779 |
|
@@ -936,9 +956,13 @@ function buildPromptDataForPR(pr: GitHubPullRequest) { |
936 | 956 | }) |
937 | 957 | .map((c) => `- ${c.author.login} at ${c.createdAt}: ${c.body}`) |
938 | 958 |
|
939 | | - const files = (pr.files.nodes || []).map((f) => `- ${f.path} (${f.changeType}) +${f.additions}/-${f.deletions}`) |
| 959 | + const files = (pr.files.nodes || []).map( |
| 960 | + (f) => `- ${f.path} (${f.changeType}) +${f.additions}/-${f.deletions}`, |
| 961 | + ) |
940 | 962 | const reviewData = (pr.reviews.nodes || []).map((r) => { |
941 | | - const comments = (r.comments.nodes || []).map((c) => ` - ${c.path}:${c.line ?? "?"}: ${c.body}`) |
| 963 | + const comments = (r.comments.nodes || []).map( |
| 964 | + (c) => ` - ${c.path}:${c.line ?? "?"}: ${c.body}`, |
| 965 | + ) |
942 | 966 | return [ |
943 | 967 | `- ${r.author.login} at ${r.submittedAt}:`, |
944 | 968 | ` - Review body: ${r.body}`, |
@@ -960,9 +984,15 @@ function buildPromptDataForPR(pr: GitHubPullRequest) { |
960 | 984 | `Deletions: ${pr.deletions}`, |
961 | 985 | `Total Commits: ${pr.commits.totalCount}`, |
962 | 986 | `Changed Files: ${pr.files.nodes.length} files`, |
963 | | - ...(comments.length > 0 ? ["<pull_request_comments>", ...comments, "</pull_request_comments>"] : []), |
964 | | - ...(files.length > 0 ? ["<pull_request_changed_files>", ...files, "</pull_request_changed_files>"] : []), |
965 | | - ...(reviewData.length > 0 ? ["<pull_request_reviews>", ...reviewData, "</pull_request_reviews>"] : []), |
| 987 | + ...(comments.length > 0 |
| 988 | + ? ["<pull_request_comments>", ...comments, "</pull_request_comments>"] |
| 989 | + : []), |
| 990 | + ...(files.length > 0 |
| 991 | + ? ["<pull_request_changed_files>", ...files, "</pull_request_changed_files>"] |
| 992 | + : []), |
| 993 | + ...(reviewData.length > 0 |
| 994 | + ? ["<pull_request_reviews>", ...reviewData, "</pull_request_reviews>"] |
| 995 | + : []), |
966 | 996 | "</pull_request>", |
967 | 997 | ].join("\n") |
968 | 998 | } |
|