Skip to content

Commit e28060a

Browse files
authored
Merge pull request #7499 from continuedev/at-continuedev-gh
cai: mention continue workflow
2 parents 35f2d9d + 0bdb246 commit e28060a

File tree

1 file changed

+215
-0
lines changed

1 file changed

+215
-0
lines changed
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
name: Respond to @continuedev Comments
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
pull_request_review_comment:
7+
types: [created]
8+
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
issues: write
13+
14+
jobs:
15+
respond-to-comment:
16+
# Only run on pull request comments
17+
if: github.event_name == 'issue_comment' && github.event.issue.pull_request
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Check if comment contains @continuedev
22+
id: check-mention
23+
run: |
24+
if echo "${{ github.event.comment.body }}" | grep -q "@continuedev"; then
25+
echo "contains_mention=true" >> $GITHUB_OUTPUT
26+
else
27+
echo "contains_mention=false" >> $GITHUB_OUTPUT
28+
fi
29+
30+
- name: Checkout PR branch
31+
if: steps.check-mention.outputs.contains_mention == 'true'
32+
uses: actions/checkout@v4
33+
with:
34+
token: ${{ secrets.GITHUB_TOKEN }}
35+
fetch-depth: 0
36+
37+
- name: Get PR information
38+
if: steps.check-mention.outputs.contains_mention == 'true'
39+
id: pr-info
40+
uses: actions/github-script@v7
41+
with:
42+
script: |
43+
const { data: pr } = await github.rest.pulls.get({
44+
owner: context.repo.owner,
45+
repo: context.repo.repo,
46+
pull_number: context.issue.number
47+
});
48+
49+
core.setOutput('head_ref', pr.head.ref);
50+
core.setOutput('head_sha', pr.head.sha);
51+
return pr;
52+
53+
- name: Checkout PR branch
54+
if: steps.check-mention.outputs.contains_mention == 'true'
55+
run: |
56+
git checkout ${{ steps.pr-info.outputs.head_ref }}
57+
58+
- name: Setup Node.js
59+
if: steps.check-mention.outputs.contains_mention == 'true'
60+
uses: actions/setup-node@v4
61+
with:
62+
node-version: "20"
63+
64+
- name: Install Continue CLI globally
65+
if: steps.check-mention.outputs.contains_mention == 'true'
66+
run: npm i -g @continuedev/cli
67+
68+
- name: Start remote session
69+
if: steps.check-mention.outputs.contains_mention == 'true'
70+
id: remote-session
71+
env:
72+
CONTINUE_API_KEY: ${{ secrets.CONTINUE_API_KEY }}
73+
run: |
74+
# Create the prompt for remote session
75+
PROMPT="Please help with the following request from @${{ github.event.comment.user.login }} on PR #${{ github.event.issue.number }}:
76+
77+
${{ github.event.comment.body }}
78+
79+
Please analyze the current PR, understand the request, implement the necessary changes, and commit them to this branch."
80+
81+
# Start remote session and capture JSON output
82+
SESSION_OUTPUT=$(echo "$PROMPT" | cn remote -s --branch ${{ steps.pr-info.outputs.head_ref }})
83+
echo "Raw session output: $SESSION_OUTPUT"
84+
85+
# Extract URL from JSON output
86+
SESSION_URL=$(echo "$SESSION_OUTPUT" | jq -r '.url // empty')
87+
88+
if [ -z "$SESSION_URL" ] || [ "$SESSION_URL" = "null" ]; then
89+
echo "Failed to extract session URL from output: $SESSION_OUTPUT"
90+
exit 1
91+
fi
92+
93+
echo "session_url=$SESSION_URL" >> $GITHUB_OUTPUT
94+
echo "✅ Started remote session: $SESSION_URL"
95+
96+
- name: Comment with session URL
97+
if: steps.check-mention.outputs.contains_mention == 'true' && steps.remote-session.outputs.session_url
98+
uses: actions/github-script@v7
99+
with:
100+
script: |
101+
const commentBody = `I've started [a remote session](${{ steps.remote-session.outputs.session_url }}) to help with your request:
102+
> ${{ github.event.comment.body }}`;
103+
104+
await github.rest.issues.createComment({
105+
owner: context.repo.owner,
106+
repo: context.repo.repo,
107+
issue_number: context.issue.number,
108+
body: commentBody
109+
});
110+
111+
- name: Log session details
112+
if: steps.check-mention.outputs.contains_mention == 'true'
113+
run: |
114+
echo "✅ Successfully started remote session for comment from ${{ github.event.comment.user.login }} on PR #${{ github.event.issue.number }}"
115+
echo "Session URL: ${{ steps.remote-session.outputs.session_url }}"
116+
echo "Original comment: ${{ github.event.comment.body }}"
117+
118+
respond-to-review-comment:
119+
# Only run on pull request review comments
120+
if: github.event_name == 'pull_request_review_comment'
121+
runs-on: ubuntu-latest
122+
123+
steps:
124+
- name: Check if comment contains @continuedev
125+
id: check-mention
126+
run: |
127+
if echo "${{ github.event.comment.body }}" | grep -q "@continuedev"; then
128+
echo "contains_mention=true" >> $GITHUB_OUTPUT
129+
else
130+
echo "contains_mention=false" >> $GITHUB_OUTPUT
131+
fi
132+
133+
- name: Checkout PR branch
134+
if: steps.check-mention.outputs.contains_mention == 'true'
135+
uses: actions/checkout@v4
136+
with:
137+
token: ${{ secrets.GITHUB_TOKEN }}
138+
fetch-depth: 0
139+
ref: ${{ github.event.pull_request.head.ref }}
140+
141+
- name: Setup Node.js
142+
if: steps.check-mention.outputs.contains_mention == 'true'
143+
uses: actions/setup-node@v4
144+
with:
145+
node-version: "20"
146+
147+
- name: Install Continue CLI globally
148+
if: steps.check-mention.outputs.contains_mention == 'true'
149+
run: npm i -g @continuedev/cli
150+
151+
- name: Start remote session
152+
if: steps.check-mention.outputs.contains_mention == 'true'
153+
id: remote-session
154+
env:
155+
CONTINUE_API_KEY: ${{ secrets.CONTINUE_API_KEY }}
156+
run: |
157+
# Create a temporary file for the prompt to handle special characters and newlines properly
158+
cat > /tmp/prompt.txt << 'PROMPT_EOF'
159+
Please help with the following code review comment from @${{ github.event.comment.user.login }} on PR #${{ github.event.pull_request.number }}:
160+
161+
**File:** ${{ github.event.comment.path }}
162+
**Line:** ${{ github.event.comment.line || github.event.comment.original_line || 'N/A' }}
163+
**Comment:** ${{ github.event.comment.body }}
164+
165+
Please analyze the specific file and line mentioned, understand the review feedback, implement the necessary changes, and commit them to this branch.
166+
PROMPT_EOF
167+
168+
# Debug output
169+
echo "PROMPT content:"
170+
cat /tmp/prompt.txt
171+
172+
# Start remote session and capture JSON output
173+
echo "Starting cn with prompt..."
174+
SESSION_OUTPUT=$(cat /tmp/prompt.txt | cn remote -s --branch ${{ github.event.pull_request.head.ref }})
175+
echo "Raw session output: $SESSION_OUTPUT"
176+
177+
# Extract URL from JSON output
178+
SESSION_URL=$(echo "$SESSION_OUTPUT" | jq -r '.url // empty')
179+
180+
if [ -z "$SESSION_URL" ] || [ "$SESSION_URL" = "null" ]; then
181+
echo "Failed to extract session URL from output: $SESSION_OUTPUT"
182+
exit 1
183+
fi
184+
185+
echo "session_url=$SESSION_URL" >> $GITHUB_OUTPUT
186+
echo "✅ Started remote session: $SESSION_URL"
187+
188+
- name: Comment with session URL
189+
if: steps.check-mention.outputs.contains_mention == 'true' && steps.remote-session.outputs.session_url
190+
uses: actions/github-script@v7
191+
with:
192+
script: |
193+
const commentBody = `I've started [a remote session](${{ steps.remote-session.outputs.session_url }}) to help with your request:
194+
> ${{ github.event.comment.body }}`;
195+
196+
const commentParams = {
197+
owner: context.repo.owner,
198+
repo: context.repo.repo,
199+
pull_number: ${{ github.event.pull_request.number }},
200+
body: commentBody,
201+
commit_id: '${{ github.event.pull_request.head.sha }}',
202+
path: '${{ github.event.comment.path }}',
203+
in_reply_to: ${{ github.event.comment.id }}
204+
};
205+
206+
await github.rest.pulls.createReviewComment(commentParams);
207+
208+
- name: Log session details
209+
if: steps.check-mention.outputs.contains_mention == 'true'
210+
run: |
211+
echo "✅ Successfully started remote session for review comment from ${{ github.event.comment.user.login }} on PR #${{ github.event.pull_request.number }}"
212+
echo "Session URL: ${{ steps.remote-session.outputs.session_url }}"
213+
echo "File: ${{ github.event.comment.path }}"
214+
echo "Line: ${{ github.event.comment.line }}"
215+
echo "Original comment: ${{ github.event.comment.body }}"

0 commit comments

Comments
 (0)