@@ -27,17 +27,43 @@ jobs:
2727actions :write
2828
2929steps :
30- -name :Determine PR Number
31- id :determine-pr
30+ -name :Determine Inputs
31+ id :determine-inputs
32+ if :always()
3233env :
34+ GITHUB_ACTOR :${{ github.actor }}
3335GITHUB_EVENT_NAME :${{ github.event_name }}
3436GITHUB_EVENT_PR_NUMBER :${{ github.event.pull_request.number }}
37+ GITHUB_EVENT_USER_ID :${{ github.event.sender.id }}
38+ GITHUB_EVENT_USER_LOGIN :${{ github.event.sender.login }}
3539INPUTS_PR_NUMBER :${{ inputs.pr_number }}
40+ GH_TOKEN :${{ github.token }}
3641run :|
42+ # For workflow_dispatch, use the actor who triggered it
43+ # For pull_request events, use the PR author
3744 if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
45+ if ! GITHUB_USER_ID=$(gh api "users/${GITHUB_ACTOR}" --jq '.id'); then
46+ echo "::error::Failed to get GitHub user ID for actor ${GITHUB_ACTOR}"
47+ exit 1
48+ fi
49+ echo "Using workflow_dispatch actor: ${GITHUB_ACTOR} (ID: ${GITHUB_USER_ID})"
50+ echo "github_user_id=${GITHUB_USER_ID}" >> "${GITHUB_OUTPUT}"
51+ echo "github_username=${GITHUB_ACTOR}" >> "${GITHUB_OUTPUT}"
52+
53+ echo "Using PR number: ${INPUTS_PR_NUMBER}"
3854 echo "pr_number=${INPUTS_PR_NUMBER}" >> "${GITHUB_OUTPUT}"
55+
56+ exit 0
3957 elif [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
58+ GITHUB_USER_ID=${GITHUB_EVENT_USER_ID}
59+ echo "Using PR author: ${GITHUB_EVENT_USER_LOGIN} (ID: ${GITHUB_USER_ID})"
60+ echo "github_user_id=${GITHUB_USER_ID}" >> "${GITHUB_OUTPUT}"
61+ echo "github_username=${GITHUB_EVENT_USER_LOGIN}" >> "${GITHUB_OUTPUT}"
62+
63+ echo "Using PR number: ${GITHUB_EVENT_PR_NUMBER}"
4064 echo "pr_number=${GITHUB_EVENT_PR_NUMBER}" >> "${GITHUB_OUTPUT}"
65+
66+ exit 0
4167 else
4268 echo "::error::Unsupported event type: ${GITHUB_EVENT_NAME}"
4369 exit 1
@@ -47,19 +73,21 @@ jobs:
4773env :
4874GITHUB_REPOSITORY :${{ github.repository }}
4975GH_TOKEN :${{ github.token }}
50- GITHUB_ACTOR :${{ github.actor }}
76+ GITHUB_USERNAME :${{ steps.determine-inputs.outputs.github_username }}
77+ GITHUB_USER_ID :${{ steps.determine-inputs.outputs.github_user_id }}
5178run :|
52- can_push="$(gh api "/repos/${GITHUB_REPOSITORY}/collaborators/${GITHUB_ACTOR}/permission" --jq '.user.permissions.push')"
79+ # Query the actor's permission on this repo
80+ can_push="$(gh api "/repos/${GITHUB_REPOSITORY}/collaborators/${GITHUB_USERNAME}/permission" --jq '.user.permissions.push')"
5381 if [[ "${can_push}" != "true" ]]; then
54- echo "::error title=Access Denied::${GITHUB_ACTOR } does not have push access to ${GITHUB_REPOSITORY}"
82+ echo "::error title=Access Denied::${GITHUB_USERNAME } does not have push access to ${GITHUB_REPOSITORY}"
5583 exit 1
5684 fi
5785
5886 -name :Post initial comment
5987id :post-comment
6088env :
6189GH_TOKEN :${{ github.token }}
62- PR_NUMBER :${{ steps.determine-pr .outputs.pr_number }}
90+ PR_NUMBER :${{ steps.determine-inputs .outputs.pr_number }}
6391GITHUB_REPOSITORY :${{ github.repository }}
6492RUN_ID :${{ github.run_id }}
6593run :|
@@ -97,10 +125,11 @@ jobs:
97125env :
98126CODER_SESSION_TOKEN :${{ secrets.TRAIAGE_CODER_SESSION_TOKEN }}
99127GH_TOKEN :${{ github.token }}
100- GITHUB_ACTOR :${{github.actor }}
128+ GITHUB_USER_ID :${{steps.determine-inputs.outputs.github_user_id }}
101129run :|
102- GITHUB_USER_ID=$(gh api "users/${GITHUB_ACTOR}" --jq '.id')
103- user_json=$(coder users list --github-user-id="${GITHUB_USER_ID}" --output=json)
130+ user_json=$(
131+ coder users list --github-user-id="${GITHUB_USER_ID}" --output=json
132+ )
104133 coder_username=$(jq -r 'first | .username' <<< "$user_json")
105134 [[ -z "${coder_username}" || "${coder_username}" == "null" ]] && echo "No Coder user with GitHub user ID ${GITHUB_USER_ID} found" && exit 1
106135 echo "coder_username=${coder_username}" >> "${GITHUB_OUTPUT}"
@@ -117,7 +146,7 @@ jobs:
117146CODER_USERNAME :${{ steps.get-coder-username.outputs.coder_username }}
118147GH_TOKEN :${{ github.token }}
119148GITHUB_REPOSITORY :${{ github.repository }}
120- PR_NUMBER :${{ steps.determine-pr .outputs.pr_number }}
149+ PR_NUMBER :${{ steps.determine-inputs .outputs.pr_number }}
121150RUN_ID :${{ github.run_id }}
122151TEMPLATE_NAME :" traiage"
123152TEMPLATE_PRESET :" Default"
@@ -135,7 +164,7 @@ jobs:
135164 pr_diff=$(gh pr diff "${PR_NUMBER}" --repo "${GITHUB_REPOSITORY}")
136165
137166 # Build comprehensive prompt
138- PROMPT=$(cat <<EOF
167+ PROMPT=$(cat <<' EOF'
139168Analyze PR ${pr_url} for documentation updates.
140169
141170# # Task Description
@@ -159,9 +188,9 @@ ${pr_body}
159188${files_changed}
160189
161190**Code Diff**:
162- \`\`\ `diff
191+ ` ` ` diff
163192${pr_diff}
164- \`\`\ `
193+ ` ` `
165194
166195# # Output Format
167196Please provide your analysis in the following format :
@@ -183,6 +212,11 @@ Please provide your analysis in the following format:
183212Be specific and provide file paths and section references where applicable.
184213EOF
185214)
215+ # Expand variables in the prompt
216+ PROMPT=$(eval "cat <<EOF
217+ ${PROMPT}
218+ EOF
219+ " )
186220 export PROMPT
187221
188222 export TASK_NAME=" doccheck-pr-${PR_NUMBER}-${RUN_ID}"
213247 -name :Update PR comment with results
214248env :
215249GH_TOKEN :${{ github.token }}
216- PR_NUMBER :${{ steps.determine-pr .outputs.pr_number }}
250+ PR_NUMBER :${{ steps.determine-inputs .outputs.pr_number }}
217251GITHUB_REPOSITORY :${{ github.repository }}
218252COMMENT_ID :${{ steps.post-comment.outputs.comment_id }}
219253TASK_NAME :${{ steps.create-task.outputs.TASK_NAME }}