mirror of
https://github.com/aljazceru/opencode.git
synced 2026-01-10 11:24:59 +01:00
fix: dirty check
This commit is contained in:
@@ -442,9 +442,10 @@ export const GithubRunCommand = cmd({
|
|||||||
const head = (await $`git rev-parse HEAD`).stdout.toString().trim()
|
const head = (await $`git rev-parse HEAD`).stdout.toString().trim()
|
||||||
const dataPrompt = buildPromptDataForPR(prData)
|
const dataPrompt = buildPromptDataForPR(prData)
|
||||||
const response = await chat(`${userPrompt}\n\n${dataPrompt}`, promptFiles)
|
const response = await chat(`${userPrompt}\n\n${dataPrompt}`, promptFiles)
|
||||||
if (await branchIsDirty(head)) {
|
const { dirty, uncommittedChanges } = await branchIsDirty(head)
|
||||||
|
if (dirty) {
|
||||||
const summary = await summarize(response)
|
const summary = await summarize(response)
|
||||||
await pushToLocalBranch(summary)
|
await pushToLocalBranch(summary, uncommittedChanges)
|
||||||
}
|
}
|
||||||
const hasShared = prData.comments.nodes.some((c) => c.body.includes(`${shareBaseUrl}/s/${shareId}`))
|
const hasShared = prData.comments.nodes.some((c) => c.body.includes(`${shareBaseUrl}/s/${shareId}`))
|
||||||
await updateComment(`${response}${footer({ image: !hasShared })}`)
|
await updateComment(`${response}${footer({ image: !hasShared })}`)
|
||||||
@@ -455,9 +456,10 @@ export const GithubRunCommand = cmd({
|
|||||||
const head = (await $`git rev-parse HEAD`).stdout.toString().trim()
|
const head = (await $`git rev-parse HEAD`).stdout.toString().trim()
|
||||||
const dataPrompt = buildPromptDataForPR(prData)
|
const dataPrompt = buildPromptDataForPR(prData)
|
||||||
const response = await chat(`${userPrompt}\n\n${dataPrompt}`, promptFiles)
|
const response = await chat(`${userPrompt}\n\n${dataPrompt}`, promptFiles)
|
||||||
if (await branchIsDirty(head)) {
|
const { dirty, uncommittedChanges } = await branchIsDirty(head)
|
||||||
|
if (dirty) {
|
||||||
const summary = await summarize(response)
|
const summary = await summarize(response)
|
||||||
await pushToForkBranch(summary, prData)
|
await pushToForkBranch(summary, prData, uncommittedChanges)
|
||||||
}
|
}
|
||||||
const hasShared = prData.comments.nodes.some((c) => c.body.includes(`${shareBaseUrl}/s/${shareId}`))
|
const hasShared = prData.comments.nodes.some((c) => c.body.includes(`${shareBaseUrl}/s/${shareId}`))
|
||||||
await updateComment(`${response}${footer({ image: !hasShared })}`)
|
await updateComment(`${response}${footer({ image: !hasShared })}`)
|
||||||
@@ -470,9 +472,10 @@ export const GithubRunCommand = cmd({
|
|||||||
const issueData = await fetchIssue()
|
const issueData = await fetchIssue()
|
||||||
const dataPrompt = buildPromptDataForIssue(issueData)
|
const dataPrompt = buildPromptDataForIssue(issueData)
|
||||||
const response = await chat(`${userPrompt}\n\n${dataPrompt}`, promptFiles)
|
const response = await chat(`${userPrompt}\n\n${dataPrompt}`, promptFiles)
|
||||||
if (await branchIsDirty(head)) {
|
const { dirty, uncommittedChanges } = await branchIsDirty(head)
|
||||||
|
if (dirty) {
|
||||||
const summary = await summarize(response)
|
const summary = await summarize(response)
|
||||||
await pushToNewBranch(summary, branch)
|
await pushToNewBranch(summary, branch, uncommittedChanges)
|
||||||
const pr = await createPR(
|
const pr = await createPR(
|
||||||
repoData.data.default_branch,
|
repoData.data.default_branch,
|
||||||
branch,
|
branch,
|
||||||
@@ -805,33 +808,39 @@ export const GithubRunCommand = cmd({
|
|||||||
return `opencode/${type}${issueId}-${timestamp}`
|
return `opencode/${type}${issueId}-${timestamp}`
|
||||||
}
|
}
|
||||||
|
|
||||||
async function pushToNewBranch(summary: string, branch: string) {
|
async function pushToNewBranch(summary: string, branch: string, commit: boolean) {
|
||||||
console.log("Pushing to new branch...")
|
console.log("Pushing to new branch...")
|
||||||
await $`git add .`
|
if (commit) {
|
||||||
await $`git commit -m "${summary}
|
await $`git add .`
|
||||||
|
await $`git commit -m "${summary}
|
||||||
|
|
||||||
Co-authored-by: ${actor} <${actor}@users.noreply.github.com>"`
|
Co-authored-by: ${actor} <${actor}@users.noreply.github.com>"`
|
||||||
|
}
|
||||||
await $`git push -u origin ${branch}`
|
await $`git push -u origin ${branch}`
|
||||||
}
|
}
|
||||||
|
|
||||||
async function pushToLocalBranch(summary: string) {
|
async function pushToLocalBranch(summary: string, commit: boolean) {
|
||||||
console.log("Pushing to local branch...")
|
console.log("Pushing to local branch...")
|
||||||
await $`git add .`
|
if (commit) {
|
||||||
await $`git commit -m "${summary}
|
await $`git add .`
|
||||||
|
await $`git commit -m "${summary}
|
||||||
|
|
||||||
Co-authored-by: ${actor} <${actor}@users.noreply.github.com>"`
|
Co-authored-by: ${actor} <${actor}@users.noreply.github.com>"`
|
||||||
|
}
|
||||||
await $`git push`
|
await $`git push`
|
||||||
}
|
}
|
||||||
|
|
||||||
async function pushToForkBranch(summary: string, pr: GitHubPullRequest) {
|
async function pushToForkBranch(summary: string, pr: GitHubPullRequest, commit: boolean) {
|
||||||
console.log("Pushing to fork branch...")
|
console.log("Pushing to fork branch...")
|
||||||
|
|
||||||
const remoteBranch = pr.headRefName
|
const remoteBranch = pr.headRefName
|
||||||
|
|
||||||
await $`git add .`
|
if (commit) {
|
||||||
await $`git commit -m "${summary}
|
await $`git add .`
|
||||||
|
await $`git commit -m "${summary}
|
||||||
|
|
||||||
Co-authored-by: ${actor} <${actor}@users.noreply.github.com>"`
|
Co-authored-by: ${actor} <${actor}@users.noreply.github.com>"`
|
||||||
|
}
|
||||||
await $`git push fork HEAD:${remoteBranch}`
|
await $`git push fork HEAD:${remoteBranch}`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -839,9 +848,17 @@ Co-authored-by: ${actor} <${actor}@users.noreply.github.com>"`
|
|||||||
console.log("Checking if branch is dirty...")
|
console.log("Checking if branch is dirty...")
|
||||||
const ret = await $`git status --porcelain`
|
const ret = await $`git status --porcelain`
|
||||||
const status = ret.stdout.toString().trim()
|
const status = ret.stdout.toString().trim()
|
||||||
if (status.length > 0) return true
|
if (status.length > 0) {
|
||||||
|
return {
|
||||||
|
dirty: true,
|
||||||
|
uncommittedChanges: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
const head = await $`git rev-parse HEAD`
|
const head = await $`git rev-parse HEAD`
|
||||||
return head.stdout.toString().trim() !== originalHead
|
return {
|
||||||
|
dirty: head.stdout.toString().trim() !== originalHead,
|
||||||
|
uncommittedChanges: false,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function assertPermissions() {
|
async function assertPermissions() {
|
||||||
|
|||||||
Reference in New Issue
Block a user