Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit26204a6

Browse files
committed
feat: add AI documentation check workflow for pull requests
This workflow automatically analyzes PRs to identify documentation updates needed.Features:- Triggers on PR opened/synchronize/reopened events- Posts initial comment when starting analysis- Creates Coder task to analyze code changes against existing docs- Identifies updates needed, deprecated docs, and new docs required- Updates PR comment with actionable documentation recommendationsIncludes:- .github/workflows/documentation-check.yaml: GitHub Actions workflow- scripts/documentation-check.sh: Helper script for task management
1 parent1c8ee5c commit26204a6

File tree

2 files changed

+387
-0
lines changed

2 files changed

+387
-0
lines changed
Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
name:AI Documentation Updates Automation
2+
3+
on:
4+
pull_request:
5+
types:
6+
-opened
7+
-synchronize
8+
-reopened
9+
workflow_dispatch:
10+
inputs:
11+
pr_number:
12+
description:"Pull Request number to process"
13+
required:true
14+
type:number
15+
16+
jobs:
17+
documentation-check:
18+
name:Check Documentation Updates with Claude Code
19+
runs-on:ubuntu-latest
20+
timeout-minutes:30
21+
env:
22+
CODER_URL:${{ secrets.TRAIAGE_CODER_URL }}
23+
CODER_SESSION_TOKEN:${{ secrets.TRAIAGE_CODER_SESSION_TOKEN }}
24+
permissions:
25+
contents:read
26+
pull-requests:write
27+
actions:write
28+
29+
steps:
30+
-name:Determine PR Number
31+
id:determine-pr
32+
env:
33+
GITHUB_EVENT_NAME:${{ github.event_name }}
34+
GITHUB_EVENT_PR_NUMBER:${{ github.event.pull_request.number }}
35+
INPUTS_PR_NUMBER:${{ inputs.pr_number }}
36+
run:|
37+
if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
38+
echo "pr_number=${INPUTS_PR_NUMBER}" >> "${GITHUB_OUTPUT}"
39+
elif [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
40+
echo "pr_number=${GITHUB_EVENT_PR_NUMBER}" >> "${GITHUB_OUTPUT}"
41+
else
42+
echo "::error::Unsupported event type: ${GITHUB_EVENT_NAME}"
43+
exit 1
44+
fi
45+
46+
-name:Verify push access
47+
env:
48+
GITHUB_REPOSITORY:${{ github.repository }}
49+
GH_TOKEN:${{ github.token }}
50+
GITHUB_ACTOR:${{ github.actor }}
51+
run:|
52+
can_push="$(gh api "/repos/${GITHUB_REPOSITORY}/collaborators/${GITHUB_ACTOR}/permission" --jq '.user.permissions.push')"
53+
if [[ "${can_push}" != "true" ]]; then
54+
echo "::error title=Access Denied::${GITHUB_ACTOR} does not have push access to ${GITHUB_REPOSITORY}"
55+
exit 1
56+
fi
57+
58+
-name:Post initial comment
59+
id:post-comment
60+
env:
61+
GH_TOKEN:${{ github.token }}
62+
PR_NUMBER:${{ steps.determine-pr.outputs.pr_number }}
63+
GITHUB_REPOSITORY:${{ github.repository }}
64+
RUN_ID:${{ github.run_id }}
65+
run:|
66+
COMMENT_BODY="🤖 **Documentation Check Started**
67+
68+
Analyzing PR changes to determine if documentation updates are needed...
69+
70+
[View workflow run](https://github.com/${GITHUB_REPOSITORY}/actions/runs/${RUN_ID})
71+
"
72+
COMMENT_ID=$(gh pr comment"${PR_NUMBER}" --body "${COMMENT_BODY}" --repo "${GITHUB_REPOSITORY}" | grep -oP 'https://github.com/.*/pull/.*#issuecomment-\K\d+')
73+
echo "comment_id=${COMMENT_ID}" >> "${GITHUB_OUTPUT}"
74+
75+
-name:Download and install Coder binary
76+
shell:bash
77+
env:
78+
CODER_URL:${{ secrets.TRAIAGE_CODER_URL }}
79+
run:|
80+
if [ "${{ runner.arch }}" == "ARM64" ]; then
81+
ARCH="arm64"
82+
else
83+
ARCH="amd64"
84+
fi
85+
mkdir -p "${HOME}/.local/bin"
86+
curl -fsSL --compressed "$CODER_URL/bin/coder-linux-${ARCH}" -o "${HOME}/.local/bin/coder"
87+
chmod +x "${HOME}/.local/bin/coder"
88+
export PATH="$HOME/.local/bin:$PATH"
89+
coder version
90+
coder whoami
91+
echo "$HOME/.local/bin" >> "${GITHUB_PATH}"
92+
93+
-name:Get Coder username from GitHub actor
94+
id:get-coder-username
95+
env:
96+
CODER_SESSION_TOKEN:${{ secrets.TRAIAGE_CODER_SESSION_TOKEN }}
97+
GH_TOKEN:${{ github.token }}
98+
GITHUB_ACTOR:${{ github.actor }}
99+
run:|
100+
GITHUB_USER_ID=$(gh api "users/${GITHUB_ACTOR}" --jq '.id')
101+
user_json=$(coder users list --github-user-id="${GITHUB_USER_ID}" --output=json)
102+
coder_username=$(jq -r 'first | .username' <<< "$user_json")
103+
[[ -z "${coder_username}" || "${coder_username}" == "null" ]] && echo "No Coder user with GitHub user ID ${GITHUB_USER_ID} found" && exit 1
104+
echo "coder_username=${coder_username}" >> "${GITHUB_OUTPUT}"
105+
106+
-name:Checkout repository
107+
uses:actions/checkout@v4
108+
with:
109+
persist-credentials:false
110+
fetch-depth:0
111+
112+
-name:Create Coder task for documentation analysis
113+
id:create-task
114+
env:
115+
CODER_USERNAME:${{ steps.get-coder-username.outputs.coder_username }}
116+
GH_TOKEN:${{ github.token }}
117+
GITHUB_REPOSITORY:${{ github.repository }}
118+
PR_NUMBER:${{ steps.determine-pr.outputs.pr_number }}
119+
RUN_ID:${{ github.run_id }}
120+
TEMPLATE_NAME:"traiage"
121+
TEMPLATE_PRESET:"Default"
122+
run:|
123+
# Fetch PR details using `gh` CLI
124+
pr_json=$(gh pr view "${PR_NUMBER}" --repo "${GITHUB_REPOSITORY}" --json 'title,body,url,files')
125+
pr_title=$(echo "${pr_json}" | jq -r '.title')
126+
pr_body=$(echo "${pr_json}" | jq -r '.body')
127+
pr_url=$(echo "${pr_json}" | jq -r '.url')
128+
129+
# Get list of changed files
130+
files_changed=$(echo "${pr_json}" | jq -r '.files[] | " - \(.path) (\(.additions) additions, \(.deletions) deletions)"')
131+
132+
# Get the actual diff for code changes
133+
pr_diff=$(gh pr diff "${PR_NUMBER}" --repo "${GITHUB_REPOSITORY}")
134+
135+
# Build comprehensive prompt
136+
PROMPT=$(cat <<EOF
137+
Analyze PR ${pr_url} for documentation updates.
138+
139+
## Task Description
140+
You are tasked with analyzing code changes in a pull request and determining what documentation updates are needed. Please:
141+
142+
1. Review the PR description and code changes to understand what was changed
143+
2. Examine the existing documentation in the docs/ directory
144+
3. Identify any of the following needs:
145+
-Updates required to existing documentation
146+
-Documentation that needs to be deprecated
147+
-New documentation that should be added
148+
4. Provide a clear, actionable list of documentation changes needed
149+
150+
## PR Details
151+
**Title**: ${pr_title}
152+
153+
**Description**:
154+
${pr_body}
155+
156+
**Files Changed**:
157+
${files_changed}
158+
159+
**Code Diff**:
160+
\`\`\`diff
161+
${pr_diff}
162+
\`\`\`
163+
164+
## Output Format
165+
Please provide your analysis in the following format:
166+
167+
### Documentation Updates Required
168+
169+
#### Updates to Existing Documentation
170+
-[List any existing docs that need updates with specific changes needed]
171+
172+
#### Documentation to Deprecate
173+
-[List any docs that should be marked as deprecated or removed]
174+
175+
#### New Documentation Needed
176+
-[List any new documentation that should be created]
177+
178+
#### No Changes Needed
179+
-[If no documentation changes are required, explain why]
180+
181+
Be specific and provide file paths and section references where applicable.
182+
EOF
183+
)
184+
export PROMPT
185+
186+
export TASK_NAME="doccheck-pr-${PR_NUMBER}-${RUN_ID}"
187+
export CONTEXT_KEY="gh-pr-${PR_NUMBER}"
188+
echo "Creating task:${CODER_USERNAME}/${TASK_NAME}"
189+
190+
./scripts/documentation-check.sh create
191+
192+
echo "TASK_NAME=${CODER_USERNAME}/${TASK_NAME}" >> "${GITHUB_OUTPUT}"
193+
echo "TASK_NAME=${CODER_USERNAME}/${TASK_NAME}" >> "${GITHUB_ENV}"
194+
195+
-name:Wait for task completion and get results
196+
id:get-results
197+
env:
198+
TASK_NAME:${{ steps.create-task.outputs.TASK_NAME }}
199+
run:|
200+
echo "Waiting for task to complete..."
201+
./scripts/documentation-check.sh wait
202+
203+
echo "Getting task results..."
204+
TASK_OUTPUT=$(./scripts/documentation-check.sh summary)
205+
206+
# Save output to file for next step
207+
echo "${TASK_OUTPUT}" > /tmp/task_output.txt
208+
209+
echo "Task completed successfully"
210+
211+
-name:Update PR comment with results
212+
env:
213+
GH_TOKEN:${{ github.token }}
214+
PR_NUMBER:${{ steps.determine-pr.outputs.pr_number }}
215+
GITHUB_REPOSITORY:${{ github.repository }}
216+
COMMENT_ID:${{ steps.post-comment.outputs.comment_id }}
217+
TASK_NAME:${{ steps.create-task.outputs.TASK_NAME }}
218+
RUN_ID:${{ github.run_id }}
219+
run:|
220+
TASK_OUTPUT=$(cat /tmp/task_output.txt)
221+
222+
COMMENT_BODY="🤖 **Documentation Check Complete**
223+
224+
${TASK_OUTPUT}
225+
226+
---
227+
Task:https://dev.coder.com/tasks/${TASK_NAME}
228+
[View workflow run](https://github.com/${GITHUB_REPOSITORY}/actions/runs/${RUN_ID})
229+
"
230+
231+
# Update the existing comment
232+
gh api \
233+
--method PATCH \
234+
"/repos/${GITHUB_REPOSITORY}/issues/comments/${COMMENT_ID}" \
235+
-f body="${COMMENT_BODY}"
236+
237+
-name:Cleanup task
238+
if:always()
239+
env:
240+
TASK_NAME:${{ steps.create-task.outputs.TASK_NAME }}
241+
run:|
242+
if [[ -n "${TASK_NAME}" ]]; then
243+
echo "Cleaning up task: ${TASK_NAME}"
244+
./scripts/documentation-check.sh delete ||true
245+
fi

‎scripts/documentation-check.sh‎

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#!/usr/bin/env bash
2+
3+
SCRIPT_DIR=$(dirname"${BASH_SOURCE[0]}")
4+
# shellcheck source=scripts/lib.sh
5+
source"${SCRIPT_DIR}/lib.sh"
6+
7+
CODER_BIN=${CODER_BIN:-"$(which coder)"}
8+
9+
TEMPDIR=$(mktemp -d)
10+
trap'rm -rf "${TEMPDIR}"' EXIT
11+
12+
[[-n${VERBOSE:-} ]]&&set -x
13+
set -euo pipefail
14+
15+
usage() {
16+
echo"Usage:$0 <options>"
17+
echo"Commands:"
18+
echo" create - Create a new documentation check task"
19+
echo" wait - Wait for task to complete"
20+
echo" summary - Get task output summary"
21+
echo" delete - Delete the task"
22+
exit 1
23+
}
24+
25+
create() {
26+
requiredenvs CODER_URL CODER_SESSION_TOKEN CODER_USERNAME TASK_NAME TEMPLATE_NAME TEMPLATE_PRESET PROMPT
27+
28+
# Check if a task already exists
29+
set +e
30+
task_json=$("${CODER_BIN}" \
31+
--url"${CODER_URL}" \
32+
--token"${CODER_SESSION_TOKEN}" \
33+
exp tasks status"${CODER_USERNAME}/${TASK_NAME}" \
34+
--output json2>/dev/null)
35+
set -e
36+
37+
if [["${TASK_NAME}"==$(jq -r'.name'<<<"${task_json}"2>/dev/null) ]];then
38+
echo"Task\"${CODER_USERNAME}/${TASK_NAME}\" already exists. Sending prompt to existing task."
39+
prompt
40+
exit 0
41+
fi
42+
43+
"${CODER_BIN}" \
44+
--url"${CODER_URL}" \
45+
--token"${CODER_SESSION_TOKEN}" \
46+
exp tasks create \
47+
--name"${TASK_NAME}" \
48+
--template"${TEMPLATE_NAME}" \
49+
--preset"${TEMPLATE_PRESET}" \
50+
--org coder \
51+
--owner"${CODER_USERNAME}" \
52+
--stdin<<<"${PROMPT}"
53+
exit 0
54+
}
55+
56+
prompt() {
57+
requiredenvs CODER_URL CODER_SESSION_TOKEN TASK_NAME PROMPT
58+
59+
${CODER_BIN} \
60+
--url"${CODER_URL}" \
61+
--token"${CODER_SESSION_TOKEN}" \
62+
exp tasks status"${TASK_NAME}" \
63+
--watch>/dev/null
64+
65+
${CODER_BIN} \
66+
--url"${CODER_URL}" \
67+
--token"${CODER_SESSION_TOKEN}" \
68+
exp tasks send"${TASK_NAME}" \
69+
--stdin \
70+
<<<"${PROMPT}"
71+
}
72+
73+
wait_for_completion() {
74+
requiredenvs CODER_URL CODER_SESSION_TOKEN TASK_NAME
75+
76+
${CODER_BIN} \
77+
--url"${CODER_URL}" \
78+
--token"${CODER_SESSION_TOKEN}" \
79+
exp tasks status"${TASK_NAME}" \
80+
--watch>/dev/null
81+
}
82+
83+
summary() {
84+
requiredenvs CODER_URL CODER_SESSION_TOKEN TASK_NAME
85+
86+
last_msg_json=$(
87+
${CODER_BIN} \
88+
--url"${CODER_URL}" \
89+
--token"${CODER_SESSION_TOKEN}" \
90+
exp tasks logs"${TASK_NAME}" \
91+
--output json
92+
)
93+
94+
# Extract the last output message from the task
95+
last_output_msg=$(jq -r'last(.[] | select(.type=="output")) | .content'<<<"${last_msg_json}")
96+
97+
# Clean up the output (remove bullet points and tool markers)
98+
last_msg=$(echo"${last_output_msg}"| sed's/^● //'| sed's/●//g')
99+
100+
echo"${last_msg}"
101+
}
102+
103+
delete() {
104+
requiredenvs CODER_URL CODER_SESSION_TOKEN TASK_NAME
105+
106+
"${CODER_BIN}" \
107+
--url"${CODER_URL}" \
108+
--token"${CODER_SESSION_TOKEN}" \
109+
delete \
110+
"${TASK_NAME}" \
111+
--yes
112+
exit 0
113+
}
114+
115+
main() {
116+
dependencies coder
117+
118+
if [[$#-eq 0 ]];then
119+
usage
120+
fi
121+
122+
case"$1"in
123+
create)
124+
create
125+
;;
126+
wait)
127+
wait_for_completion
128+
;;
129+
summary)
130+
summary
131+
;;
132+
delete)
133+
delete
134+
;;
135+
*)
136+
echo"Unknown option:$1"
137+
usage
138+
;;
139+
esac
140+
}
141+
142+
main"$@"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp