Skip to content

Commit 1149b98

Browse files
author
Frank
committed
wip: github actions
1 parent 81fb1b3 commit 1149b98

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

packages/opencode/src/cli/cmd/github.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,9 @@ export const GithubRunCommand = cmd({
375375
const runUrl = `/${owner}/${repo}/actions/runs/${runId}`
376376
const shareBaseUrl = isMock ? "https://dev.opencode.ai" : "https://opencode.ai"
377377

378+
// TODO
379+
console.log("payload", payload)
380+
378381
let appToken: string
379382
let octoRest: Octokit
380383
let octoGraph: typeof graphql
@@ -386,14 +389,14 @@ export const GithubRunCommand = cmd({
386389
type PromptFiles = Awaited<ReturnType<typeof getUserPrompt>>["promptFiles"]
387390

388391
try {
389-
const { userPrompt, promptFiles } = await getUserPrompt()
390392
const actionToken = isMock ? args.token! : await getOidcToken()
391393
appToken = await exchangeForAppToken(actionToken)
392394
octoRest = new Octokit({ auth: appToken })
393395
octoGraph = graphql.defaults({
394396
headers: { authorization: `token ${appToken}` },
395397
})
396398

399+
const { userPrompt, promptFiles } = await getUserPrompt()
397400
await configureGit(appToken)
398401
await assertPermissions()
399402

@@ -531,20 +534,31 @@ export const GithubRunCommand = cmd({
531534
}[] = []
532535

533536
// Search for files
537+
// ie. <img alt="Image" src="https://github.com/user-attachments/assets/xxxx" />
534538
// ie. [api.json](https://github.com/user-attachments/files/21433810/api.json)
535539
// ie. ![Image](https://github.com/user-attachments/assets/xxxx)
536-
const imgTags = prompt.matchAll(/!?\[.*?\]\((https:\/\/github\.com\/user-attachments\/[^)]+)\)/gi)
540+
const mdMatches = prompt.matchAll(/!?\[.*?\]\((https:\/\/github\.com\/user-attachments\/[^)]+)\)/gi)
541+
const tagMatches = prompt.matchAll(/<img .*?src="(https:\/\/github\.com\/user-attachments\/[^"]+)" \/>/gi)
542+
const matches = [...mdMatches, ...tagMatches].sort((a, b) => a.index - b.index)
537543

538544
let offset = 0
539-
for (const imgTag of imgTags) {
540-
const tag = imgTag[0]
541-
const url = imgTag[1]
542-
const start = imgTag.index
545+
for (const m of matches) {
546+
const tag = m[0]
547+
const url = m[1]
548+
const start = m.index
543549
const filename = path.basename(url)
544550

545551
// Download image
546-
const res = await fetch(url)
552+
const res = await fetch(url, {
553+
headers: {
554+
Authorization: `Bearer ${appToken}`,
555+
Accept: "application/vnd.github.v3+json",
556+
},
557+
})
547558
if (!res.ok) {
559+
// TODO
560+
//console.log(res)
561+
//throw new Error("manual")
548562
console.error(`Failed to download image: ${url}`)
549563
continue
550564
}

0 commit comments

Comments
 (0)