Skip to content
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
14 changes: 12 additions & 2 deletions .github/workflows/test-claude-create-pull-request.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions .github/workflows/test-codex-create-pull-request.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 27 additions & 2 deletions pkg/workflow/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2227,7 +2227,7 @@ func (c *Compiler) generateMainJobSteps(yaml *strings.Builder, data *WorkflowDat

// Add git patch generation step only if safe-outputs create-pull-request feature is used
if data.SafeOutputs != nil && (data.SafeOutputs.CreatePullRequests != nil || data.SafeOutputs.PushToBranch != nil) {
c.generateGitPatchStep(yaml)
c.generateGitPatchStep(yaml, data)
}

// Add post-steps (if any) after AI execution
Expand Down Expand Up @@ -2356,6 +2356,14 @@ func (c *Compiler) generatePrompt(yaml *strings.Builder, data *WorkflowData, eng
yaml.WriteString(", ")
}
yaml.WriteString("Updating Issues")
written = true
}

if data.SafeOutputs.PushToBranch != nil {
if written {
yaml.WriteString(", ")
}
yaml.WriteString("Pushing Changes to Branch")
}
yaml.WriteString("\n")
yaml.WriteString(" \n")
Expand Down Expand Up @@ -2388,7 +2396,7 @@ func (c *Compiler) generatePrompt(yaml *strings.Builder, data *WorkflowData, eng
yaml.WriteString(" To create a pull request:\n")
yaml.WriteString(" 1. Make any file changes directly in the working directory\n")
yaml.WriteString(" 2. If you haven't done so already, create a local branch using an appropriate unique name\n")
yaml.WriteString(" 3. Add and commit your files to the branch. Be careful to add exactly the files you intend, and check there are no extra files left un-added. Check you haven't deleted or changed any files you didn't intend to.\n")
yaml.WriteString(" 3. Add and commit your changes to the branch. Be careful to add exactly the files you intend, and check there are no extra files left un-added. Check you haven't deleted or changed any files you didn't intend to.\n")
yaml.WriteString(" 4. Do not push your changes. That will be done later. Instead append the PR specification to the file \"${{ env.GITHUB_AW_SAFE_OUTPUTS }}\":\n")
yaml.WriteString(" ```json\n")
yaml.WriteString(" {\"type\": \"create-pull-request\", \"branch\": \"branch-name\", \"title\": \"PR title\", \"body\": \"PR body in markdown\", \"labels\": [\"optional\", \"labels\"]}\n")
Expand Down Expand Up @@ -2434,6 +2442,19 @@ func (c *Compiler) generatePrompt(yaml *strings.Builder, data *WorkflowData, eng
yaml.WriteString(" \n")
}

if data.SafeOutputs.PushToBranch != nil {
yaml.WriteString(" **Pushing Changes to Branch**\n")
yaml.WriteString(" \n")
yaml.WriteString(" To push changes to a branch:\n")
yaml.WriteString(" 1. Make any file changes directly in the working directory\n")
yaml.WriteString(" 2. Add and commit your changes to the branch. Be careful to add exactly the files you intend, and check there are no extra files left un-added. Check you haven't deleted or changed any files you didn't intend to.\n")
yaml.WriteString(" 3. Indicate your intention to push to the branch by writing to the file \"${{ env.GITHUB_AW_SAFE_OUTPUTS }}\":\n")
yaml.WriteString(" ```json\n")
yaml.WriteString(" {\"type\": \"push-to-branch\", \"message\": \"Commit message describing the changes\"}\n")
yaml.WriteString(" ```\n")
yaml.WriteString(" \n")
}

yaml.WriteString(" **Example JSONL file content:**\n")
yaml.WriteString(" ```\n")

Expand All @@ -2455,6 +2476,10 @@ func (c *Compiler) generatePrompt(yaml *strings.Builder, data *WorkflowData, eng
yaml.WriteString(" {\"type\": \"add-issue-label\", \"labels\": [\"bug\", \"priority-high\"]}\n")
exampleCount++
}
if data.SafeOutputs.PushToBranch != nil {
yaml.WriteString(" {\"type\": \"push-to-branch\", \"message\": \"Update documentation with latest changes\"}\n")
exampleCount++
}

// If no SafeOutputs are enabled, show a generic example
if exampleCount == 0 {
Expand Down
18 changes: 16 additions & 2 deletions pkg/workflow/git_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ package workflow
import "strings"

// generateGitPatchStep generates a step that creates and uploads a git patch of changes
func (c *Compiler) generateGitPatchStep(yaml *strings.Builder) {
func (c *Compiler) generateGitPatchStep(yaml *strings.Builder, data *WorkflowData) {
yaml.WriteString(" - name: Generate git patch\n")
yaml.WriteString(" if: always()\n")
yaml.WriteString(" env:\n")
yaml.WriteString(" GITHUB_AW_SAFE_OUTPUTS: ${{ env.GITHUB_AW_SAFE_OUTPUTS }}\n")
// Add push-to-branch configuration if available
if data.SafeOutputs != nil && data.SafeOutputs.PushToBranch != nil {
yaml.WriteString(" GITHUB_AW_PUSH_BRANCH: \"" + data.SafeOutputs.PushToBranch.Branch + "\"\n")
}
yaml.WriteString(" run: |\n")
yaml.WriteString(" # Check current git status\n")
yaml.WriteString(" echo \"Current git status:\"\n")
Expand All @@ -25,7 +29,17 @@ func (c *Compiler) generateGitPatchStep(yaml *strings.Builder) {
yaml.WriteString(" # Extract branch value using sed\n")
yaml.WriteString(" BRANCH_NAME=$(echo \"$line\" | sed -n 's/.*\"branch\"[[:space:]]*:[[:space:]]*\"\\([^\"]*\\)\".*/\\1/p')\n")
yaml.WriteString(" if [ -n \"$BRANCH_NAME\" ]; then\n")
yaml.WriteString(" echo \"Extracted branch name: $BRANCH_NAME\"\n")
yaml.WriteString(" echo \"Extracted branch name from create-pull-request: $BRANCH_NAME\"\n")
yaml.WriteString(" break\n")
yaml.WriteString(" fi\n")
yaml.WriteString(" # Extract branch from push-to-branch line using simple grep and sed\n")
yaml.WriteString(" elif echo \"$line\" | grep -q '\"type\"[[:space:]]*:[[:space:]]*\"push-to-branch\"'; then\n")
yaml.WriteString(" echo \"Found push-to-branch line: $line\"\n")
yaml.WriteString(" # For push-to-branch, we don't extract branch from JSONL since it's configured in the workflow\n")
yaml.WriteString(" # The branch name should come from the environment variable GITHUB_AW_PUSH_BRANCH\n")
yaml.WriteString(" if [ -n \"$GITHUB_AW_PUSH_BRANCH\" ]; then\n")
yaml.WriteString(" BRANCH_NAME=\"$GITHUB_AW_PUSH_BRANCH\"\n")
yaml.WriteString(" echo \"Using configured push-to-branch target: $BRANCH_NAME\"\n")
yaml.WriteString(" break\n")
yaml.WriteString(" fi\n")
yaml.WriteString(" fi\n")
Expand Down