11# .github/workflows/oai-agent.yml
2- name : OAI Coding Agenttttt
2+ name : OAI Coding Agent
33
44on :
55 issues :
66 types : [opened, labeled]
77 issue_comment :
88 types : [created]
9+ pull_request_review_comment :
10+ types : [created]
11+ pull_request_review :
12+ types : [submitted]
913
1014jobs :
1115 run-agent :
1216 # Only proceed if:
13- # - on opened: issue has @oai in body OR already labeled "oai"
14- # - on labeled: the new label is exactly "oai"
15- # - on comment: the comment body contains "@oai"
17+ # For issues:
18+ # - on opened: issue has @oai in body OR already labeled "oai"
19+ # - on labeled: the new label is exactly "oai"
20+ # For PR interactions:
21+ # - any PR comment (conversation or inline) that contains "@oai"
22+ # - a *changes requested* review on a PR authored by the agent
1623 if : >-
1724 (
1825 github.event_name == 'issues' &&
@@ -29,32 +36,36 @@ jobs:
2936 (
3037 github.event_name == 'issue_comment' &&
3138 contains(github.event.comment.body, '@oai')
39+ ) ||
40+ (
41+ github.event_name == 'pull_request_review_comment' &&
42+ contains(github.event.comment.body, '@oai')
43+ ) ||
44+ (
45+ github.event_name == 'pull_request_review' &&
46+ github.event.review.state == 'changes_requested' &&
47+ github.event.pull_request.user.login == 'oai-coding-agent[bot]'
3248 )
3349
3450 runs-on : ubuntu-latest
3551 permissions :
3652 id-token : write
37- contents : write
38- issues : read
39- pull-requests : write
4053 steps :
41- - name : Checkout repository
42- uses : actions/checkout@v4
54+ # Agent dependencies
55+ - name : Set up Node.js (latest LTS)
56+ uses : actions/setup-node@v4
4357 with :
44- # allow pushing back
45- persist-credentials : true
58+ node-version : " lts/*"
4659
4760 - name : Set up uv
4861 uses : astral-sh/setup-uv@v6
62+ with :
63+ ignore-empty-workdir : true
4964
50- - name : Sync dependencies with uv
65+ - name : Install oai
66+ shell : bash
5167 run : |
52- uv sync
53-
54- - name : Set up Node.js (latest LTS)
55- uses : actions/setup-node@v4
56- with :
57- node-version : " lts/*"
68+ uv tool install oai-coding-agent
5869
5970 - name : Get GitHub App access token via token exchange
6071 id : get-token
@@ -74,29 +85,125 @@ jobs:
7485 echo "::add-mask::$GITHUB_ACCESS_TOKEN"
7586 echo "github_access_token=$GITHUB_ACCESS_TOKEN" >> $GITHUB_OUTPUT
7687
77- - name : Create a fresh branch for the agent
88+ - name : Checkout repository
89+ uses : actions/checkout@v4
90+ with :
91+ fetch-depth : 0
92+ token : ${{ steps.get-token.outputs.github_access_token }}
93+
94+ # Determine PR / issue context and build dynamic prompt.
95+ - name : Determine context
96+ id : context
97+ env :
98+ GH_TOKEN : ${{ steps.get-token.outputs.github_access_token }}
99+ shell : bash
78100 run : |
79- git config user.name "oai-coding-agent[bot]"
101+ set -e
102+ EVENT_NAME="${{ github.event_name }}"
103+ EVENT_PATH="$GITHUB_EVENT_PATH"
104+ PROMPT_FILE=agent_prompt.txt
105+ TARGET_BRANCH=""
106+
107+ if [[ "$EVENT_NAME" == "issues" ]]; then
108+ ISSUE_NUMBER=$(jq -r '.issue.number' "$EVENT_PATH")
109+ TITLE=$(jq -r '.issue.title' "$EVENT_PATH")
110+ BODY=$(jq -r '.issue.body' "$EVENT_PATH")
111+
112+ printf "Complete the following GitHub issue:\nRepository: %s\nIssue #%s: %s\n\nBody:\n%s\n" \
113+ "${{ github.event.repository.html_url }}" \
114+ "${ISSUE_NUMBER}" \
115+ "${TITLE}" \
116+ "${BODY}" > "$PROMPT_FILE"
117+
118+ elif [[ "$EVENT_NAME" == "issue_comment" ]]; then
119+ # If the comment is on a PR (issues event with pull_request field)
120+ if jq -e '.issue.pull_request' "$EVENT_PATH" >/dev/null; then
121+ PR_NUMBER=$(jq -r '.issue.number' "$EVENT_PATH")
122+ COMMENT=$(jq -r '.comment.body' "$EVENT_PATH")
123+ TARGET_BRANCH=$(curl -s -H "Authorization: Bearer $GH_TOKEN" \
124+ -H "Accept: application/vnd.github+json" \
125+ "https://api.github.com/repos/${{ github.repository }}/pulls/${PR_NUMBER}" | jq -r '.head.ref')
126+
127+ printf "A reviewer left the following comment on PR #%s and mentioned @oai:\n\n---\n%s\n---\n\nPlease apply the requested changes on this PR branch.\n" \
128+ "${PR_NUMBER}" \
129+ "${COMMENT}" > "$PROMPT_FILE"
130+
131+ else
132+ # Regular issue comment
133+ ISSUE_NUMBER=$(jq -r '.issue.number' "$EVENT_PATH")
134+ COMMENT=$(jq -r '.comment.body' "$EVENT_PATH")
135+ printf "A new comment was left on Issue #%s mentioning @oai:\n\n---\n%s\n---\n\nPlease take the appropriate action.\n" \
136+ "${ISSUE_NUMBER}" \
137+ "${COMMENT}" > "$PROMPT_FILE"
138+ fi
139+
140+ elif [[ "$EVENT_NAME" == "pull_request_review_comment" ]]; then
141+ PR_NUMBER=$(jq -r '.pull_request.number' "$EVENT_PATH")
142+ COMMENT=$(jq -r '.comment.body' "$EVENT_PATH")
143+ TARGET_BRANCH=$(jq -r '.pull_request.head.ref' "$EVENT_PATH")
144+
145+ printf "An inline review comment on PR #%s mentioned @oai:\n\n---\n%s\n---\n\nPlease address it and push updates.\n" \
146+ "${PR_NUMBER}" \
147+ "${COMMENT}" > "$PROMPT_FILE"
148+
149+ elif [[ "$EVENT_NAME" == "pull_request_review" ]]; then
150+ if [[ "$(jq -r '.review.state' "$EVENT_PATH")" == "changes_requested" ]]; then
151+ PR_NUMBER=$(jq -r '.pull_request.number' "$EVENT_PATH")
152+ TARGET_BRANCH=$(jq -r '.pull_request.head.ref' "$EVENT_PATH")
153+ BODY=$(jq -r '.review.body' "$EVENT_PATH")
154+
155+ printf "A *Changes Requested* review was submitted on PR #%s:\n\n---\n%s\n---\n\nYou authored this PR. Address the feedback and push changes.\n" \
156+ "${PR_NUMBER}" \
157+ "${BODY}" > "$PROMPT_FILE"
158+ fi
159+ fi
160+
161+ echo "target_branch=${TARGET_BRANCH}" >> $GITHUB_OUTPUT
162+ echo "prompt_file=${PROMPT_FILE}" >> $GITHUB_OUTPUT
163+
164+ - name : Create or checkout branch for issue
165+ if : steps.context.outputs.target_branch == ''
166+ shell : bash
167+ run : |
168+ set -e
169+ git config user.name "oai-coding-agent[bot]"
80170 git config user.email "214839426+oai-coding-agent[bot]@users.noreply.github.com"
81171 ISSUE_NUMBER="${{ github.event.issue.number }}"
82172 BRANCH="oai/issue-${ISSUE_NUMBER}"
83- git checkout -b "$BRANCH"
84- git push --set-upstream origin HEAD
85173
86- - name : Run OAI coding agent in headless mode
174+ if git ls-remote --heads origin "$BRANCH" | grep -q "$BRANCH"; then
175+ echo "Branch $BRANCH already exists, checking it out"
176+ git fetch origin "$BRANCH"
177+ git checkout "$BRANCH"
178+ else
179+ echo "Creating new branch $BRANCH"
180+ git checkout -b "$BRANCH"
181+ git push --set-upstream origin HEAD
182+ fi
183+
184+ - name : Checkout PR branch
185+ if : steps.context.outputs.target_branch != ''
186+ shell : bash
187+ run : |
188+ git config user.name "oai-coding-agent[bot]"
189+ git config user.email "214839426+oai-coding-agent[bot]@users.noreply.github.com"
190+ BRANCH="${{ steps.context.outputs.target_branch }}"
191+ echo "Fetching and checking out branch $BRANCH"
192+ git fetch origin "$BRANCH"
193+ git checkout "$BRANCH"
194+
195+ # Enter your own repo set up here
196+ # - name: Install dependencies
197+ # run: |
198+ # uv sync
199+ # npm install
200+
201+ - name : Run oai coding agent
87202 env :
88- RICH_FORCE_TERMINAL : " 1" # these provide pretty logs in GHA
203+ RICH_FORCE_TERMINAL : " 1"
89204 TTY_COMPATIBLE : " 1"
90205 OPENAI_API_KEY : ${{ secrets.OPENAI_API_KEY }}
91206 shell : bash
92207 run : |
93- uv sync
94- source .venv/bin/activate
95- oai --github-token ${{ steps.get-token.outputs.github_access_token }} --prompt - << 'PROMPT_END'
96- Complete the following GitHub issue:
97- Repository: ${{ github.event.repository.html_url }}
98- Issue #${{ github.event.issue.number }}: ${{ github.event.issue.title }}
99-
100- Body:
101- ${{ github.event.issue.body }}
102- PROMPT_END
208+ PROMPT_CONTENT=$(cat "${{ steps.context.outputs.prompt_file }}")
209+ oai --github-token ${{ steps.get-token.outputs.github_access_token }} --prompt "$PROMPT_CONTENT"
0 commit comments