|
17 | 17 | type:string |
18 | 18 | template_preset: |
19 | 19 | description:"Template preset to use" |
20 | | -required:true |
21 | | -default:"none" |
| 20 | +required:false |
| 21 | +default:"" |
22 | 22 | type:string |
23 | 23 | prefix: |
24 | 24 | description:"Prefix for workspace name" |
|
67 | 67 | GITHUB_EVENT_USER_LOGIN:${{ github.event.sender.login }} |
68 | 68 | INPUTS_ISSUE_URL:${{ inputs.issue_url }} |
69 | 69 | INPUTS_TEMPLATE_NAME:${{ inputs.template_name || 'coder' }} |
70 | | -INPUTS_TEMPLATE_PRESET:${{ inputs.template_preset || 'none'}} |
| 70 | +INPUTS_TEMPLATE_PRESET:${{ inputs.template_preset || ''}} |
71 | 71 | INPUTS_PREFIX:${{ inputs.prefix || 'traiage' }} |
72 | 72 | GH_TOKEN:${{ github.token }} |
73 | 73 | run:| |
@@ -124,94 +124,68 @@ jobs: |
124 | 124 | exit 1 |
125 | 125 | fi |
126 | 126 |
|
127 | | - -name:Extract context key from issue |
| 127 | + -name:Extract context keyand descriptionfrom issue |
128 | 128 | id:extract-context |
129 | 129 | env: |
130 | 130 | ISSUE_URL:${{ steps.determine-inputs.outputs.issue_url }} |
131 | 131 | GH_TOKEN:${{ github.token }} |
132 | 132 | run:| |
133 | 133 | issue_number="$(gh issue view "${ISSUE_URL}" --json number --jq '.number')" |
134 | 134 | context_key="gh-${issue_number}" |
135 | | - echo "context_key=${context_key}" >> "${GITHUB_OUTPUT}" |
136 | | - echo "CONTEXT_KEY=${context_key}" >> "${GITHUB_ENV}" |
137 | | -
|
138 | | - -name:Download and install Coder binary |
139 | | -shell:bash |
140 | | -env: |
141 | | -CODER_URL:${{ secrets.TRAIAGE_CODER_URL }} |
142 | | -run:| |
143 | | - if [ "${{ runner.arch }}" == "ARM64" ]; then |
144 | | - ARCH="arm64" |
145 | | - else |
146 | | - ARCH="amd64" |
147 | | - fi |
148 | | - mkdir -p "${HOME}/.local/bin" |
149 | | - curl -fsSL --compressed "$CODER_URL/bin/coder-linux-${ARCH}" -o "${HOME}/.local/bin/coder" |
150 | | - chmod +x "${HOME}/.local/bin/coder" |
151 | | - export PATH="$HOME/.local/bin:$PATH" |
152 | | - coder version |
153 | | - coder whoami |
154 | | - echo "$HOME/.local/bin" >> "${GITHUB_PATH}" |
155 | | -
|
156 | | - -name:Get Coder username from GitHub actor |
157 | | -id:get-coder-username |
158 | | -env: |
159 | | -CODER_SESSION_TOKEN:${{ secrets.TRAIAGE_CODER_SESSION_TOKEN }} |
160 | | -GH_TOKEN:${{ github.token }} |
161 | | -GITHUB_USER_ID:${{ steps.determine-inputs.outputs.github_user_id }} |
162 | | -run:| |
163 | | - user_json=$( |
164 | | - coder users list --github-user-id="${GITHUB_USER_ID}" --output=json |
165 | | - ) |
166 | | - coder_username=$(jq -r 'first | .username' <<< "$user_json") |
167 | | - [[ -z "${coder_username}" || "${coder_username}" == "null" ]] && echo "No Coder user with GitHub user ID ${GITHUB_USER_ID} found" && exit 1 |
168 | | - echo "coder_username=${coder_username}" >> "${GITHUB_OUTPUT}" |
169 | | -
|
170 | | - -name:Checkout repository |
171 | | -uses:actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8# v5.0.0 |
172 | | -with: |
173 | | -persist-credentials:false |
174 | | -fetch-depth:0 |
175 | 135 |
|
176 | | -# TODO(Cian): this is a good use-case for 'recipes' |
177 | | - -name:Create Coder task |
178 | | -id:create-task |
179 | | -env: |
180 | | -CODER_USERNAME:${{ steps.get-coder-username.outputs.coder_username }} |
181 | | -CONTEXT_KEY:${{ steps.extract-context.outputs.context_key }} |
182 | | -GH_TOKEN:${{ github.token }} |
183 | | -GITHUB_REPOSITORY:${{ github.repository }} |
184 | | -ISSUE_URL:${{ steps.determine-inputs.outputs.issue_url }} |
185 | | -PREFIX:${{ steps.determine-inputs.outputs.prefix }} |
186 | | -RUN_ID:${{ github.run_id }} |
187 | | -TEMPLATE_NAME:${{ steps.determine-inputs.outputs.template_name }} |
188 | | -TEMPLATE_PARAMETERS:${{ secrets.TRAIAGE_TEMPLATE_PARAMETERS }} |
189 | | -TEMPLATE_PRESET:${{ steps.determine-inputs.outputs.template_preset }} |
190 | | -run:| |
191 | 136 | # Fetch issue description using `gh` CLI |
192 | 137 | #shellcheck disable=SC2016 # The template string should not be subject to shell expansion |
193 | 138 | issue_description=$(gh issue view "${ISSUE_URL}" \ |
194 | 139 | --json 'title,body,comments' \ |
195 | 140 | --template '{{printf "%s\n\n%s\n\nComments:\n" .title .body}}{{range $k, $v := .comments}} - {{index $v.author "login"}}: {{printf "%s\n" $v.body}}{{end}}') |
196 | 141 |
|
197 | | - # Write a prompt to PROMPT_FILE |
198 | | - PROMPT=$(cat <<EOF |
| 142 | + TASK_PROMPT=$(cat <<EOF |
199 | 143 | Fix ${ISSUE_URL} |
200 | 144 |
|
201 | 145 | Analyze the below GitHub issue description, understand the root cause, and make appropriate changes to resolve the issue. |
202 | 146 | --- |
203 | 147 | ${issue_description} |
204 | 148 | EOF |
205 | 149 | ) |
206 | | - export PROMPT |
207 | 150 |
|
208 | | - export TASK_NAME="${PREFIX}-${CONTEXT_KEY}-${RUN_ID}" |
209 | | - echo "Creating task: $TASK_NAME" |
210 | | - ./scripts/traiage.sh create |
211 | | - if [[ "${ISSUE_URL}" == "https://github.com/${GITHUB_REPOSITORY}"* ]]; then |
212 | | - gh issue comment "${ISSUE_URL}" --body "Task created: https://dev.coder.com/tasks/${CODER_USERNAME}/${TASK_NAME}" --create-if-none --edit-last |
213 | | - else |
214 | | - echo "Skipping comment on other repo." |
215 | | - fi |
216 | | - echo "TASK_NAME=${CODER_USERNAME}/${TASK_NAME}" >> "${GITHUB_OUTPUT}" |
217 | | - echo "TASK_NAME=${CODER_USERNAME}/${TASK_NAME}" >> "${GITHUB_ENV}" |
| 151 | + echo "context_key=${context_key}" >> "${GITHUB_OUTPUT}" |
| 152 | + { |
| 153 | + echo "TASK_PROMPT<<EOF" |
| 154 | + echo "${TASK_PROMPT}" |
| 155 | + echo "EOF" |
| 156 | + } >> "${GITHUB_OUTPUT}" |
| 157 | +
|
| 158 | + -name:Checkout repository |
| 159 | +uses:actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8# v5.0.0 |
| 160 | +with: |
| 161 | +persist-credentials:false |
| 162 | +fetch-depth:1 |
| 163 | + |
| 164 | + -name:Create Coder Task |
| 165 | +id:create_task |
| 166 | +# TODO: remove manual vendoring when repo is public |
| 167 | +uses:./.github/actions/create-task-action |
| 168 | +with: |
| 169 | +coder-url:${{ secrets.TRAIAGE_CODER_URL }} |
| 170 | +coder-token:${{ secrets.TRAIAGE_CODER_SESSION_TOKEN }} |
| 171 | +coder-organization:"default" |
| 172 | +coder-template-name:coder |
| 173 | +coder-template-preset:${{ steps.determine-inputs.outputs.template_preset }} |
| 174 | +coder-task-name-prefix:traiage |
| 175 | +coder-task-prompt:${{ steps.extract-context.outputs.task_prompt }} |
| 176 | +github-user-id:${{ steps.determine-inputs.outputs.github_user_id }} |
| 177 | +github-token:${{ github.token }} |
| 178 | +github-issue-url:${{ steps.determine-inputs.outputs.issue_url }} |
| 179 | +comment-on-issue:${{ startsWith(steps.determine-inputs.outputs.issue_url, format('{0}/{1}', github.server_url, github.repository)) }} |
| 180 | + |
| 181 | + -name:Write outputs |
| 182 | +env: |
| 183 | +TASK_CREATED:${{ steps.create_task.outputs.task-created }} |
| 184 | +TASK_NAME:${{ steps.create_task.outputs.task-name }} |
| 185 | +TASK_URL:${{ steps.create_task.outputs.task-url }} |
| 186 | +run:| |
| 187 | + { |
| 188 | + echo "**Task created:** ${TASK_CREATED}" |
| 189 | + echo "**Task name:** ${TASK_NAME}" |
| 190 | + echo "**Task URL**: ${TASK_URL}" |
| 191 | + } >> "${GITHUB_STEP_SUMMARY}" |