mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-22 02:04:22 +01:00
wip: github actions
This commit is contained in:
@@ -375,6 +375,9 @@ export const GithubRunCommand = cmd({
|
|||||||
const runUrl = `/${owner}/${repo}/actions/runs/${runId}`
|
const runUrl = `/${owner}/${repo}/actions/runs/${runId}`
|
||||||
const shareBaseUrl = isMock ? "https://dev.opencode.ai" : "https://opencode.ai"
|
const shareBaseUrl = isMock ? "https://dev.opencode.ai" : "https://opencode.ai"
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
console.log("payload", payload)
|
||||||
|
|
||||||
let appToken: string
|
let appToken: string
|
||||||
let octoRest: Octokit
|
let octoRest: Octokit
|
||||||
let octoGraph: typeof graphql
|
let octoGraph: typeof graphql
|
||||||
@@ -386,7 +389,6 @@ export const GithubRunCommand = cmd({
|
|||||||
type PromptFiles = Awaited<ReturnType<typeof getUserPrompt>>["promptFiles"]
|
type PromptFiles = Awaited<ReturnType<typeof getUserPrompt>>["promptFiles"]
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { userPrompt, promptFiles } = await getUserPrompt()
|
|
||||||
const actionToken = isMock ? args.token! : await getOidcToken()
|
const actionToken = isMock ? args.token! : await getOidcToken()
|
||||||
appToken = await exchangeForAppToken(actionToken)
|
appToken = await exchangeForAppToken(actionToken)
|
||||||
octoRest = new Octokit({ auth: appToken })
|
octoRest = new Octokit({ auth: appToken })
|
||||||
@@ -394,6 +396,7 @@ export const GithubRunCommand = cmd({
|
|||||||
headers: { authorization: `token ${appToken}` },
|
headers: { authorization: `token ${appToken}` },
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const { userPrompt, promptFiles } = await getUserPrompt()
|
||||||
await configureGit(appToken)
|
await configureGit(appToken)
|
||||||
await assertPermissions()
|
await assertPermissions()
|
||||||
|
|
||||||
@@ -531,20 +534,31 @@ export const GithubRunCommand = cmd({
|
|||||||
}[] = []
|
}[] = []
|
||||||
|
|
||||||
// Search for files
|
// Search for files
|
||||||
|
// ie. <img alt="Image" src="https://github.com/user-attachments/assets/xxxx" />
|
||||||
// ie. [api.json](https://github.com/user-attachments/files/21433810/api.json)
|
// ie. [api.json](https://github.com/user-attachments/files/21433810/api.json)
|
||||||
// ie. 
|
// ie. 
|
||||||
const imgTags = prompt.matchAll(/!?\[.*?\]\((https:\/\/github\.com\/user-attachments\/[^)]+)\)/gi)
|
const mdMatches = prompt.matchAll(/!?\[.*?\]\((https:\/\/github\.com\/user-attachments\/[^)]+)\)/gi)
|
||||||
|
const tagMatches = prompt.matchAll(/<img .*?src="(https:\/\/github\.com\/user-attachments\/[^"]+)" \/>/gi)
|
||||||
|
const matches = [...mdMatches, ...tagMatches].sort((a, b) => a.index - b.index)
|
||||||
|
|
||||||
let offset = 0
|
let offset = 0
|
||||||
for (const imgTag of imgTags) {
|
for (const m of matches) {
|
||||||
const tag = imgTag[0]
|
const tag = m[0]
|
||||||
const url = imgTag[1]
|
const url = m[1]
|
||||||
const start = imgTag.index
|
const start = m.index
|
||||||
const filename = path.basename(url)
|
const filename = path.basename(url)
|
||||||
|
|
||||||
// Download image
|
// Download image
|
||||||
const res = await fetch(url)
|
const res = await fetch(url, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${appToken}`,
|
||||||
|
Accept: "application/vnd.github.v3+json",
|
||||||
|
},
|
||||||
|
})
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
|
// TODO
|
||||||
|
//console.log(res)
|
||||||
|
//throw new Error("manual")
|
||||||
console.error(`Failed to download image: ${url}`)
|
console.error(`Failed to download image: ${url}`)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user