Skip to content

Commit afbe9ea

Browse files
docs: add GitHub to Coder Task Workflow Guide (#20928)
Co-authored-by: Danielle Maywood <danielle@themaywoods.com>
1 parent cf6bb40 commit afbe9ea

File tree

2 files changed

+267
-7
lines changed

2 files changed

+267
-7
lines changed

docs/ai-coder/github-to-tasks.md

Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
# Guide: Create a GitHub to Coder Tasks Workflow
2+
3+
## Background
4+
5+
Most software engineering organizations track and manage their codebase through GitHub, and use project management tools like Asana, Jira, or even GitHub's Projects to coordinate work. Across these systems, engineers are frequently performing the same repetitive workflows: triaging and addressing bugs, updating documentation, or implementing well-defined changes for example.
6+
7+
Coder Tasks provides a method for automating these repeatable workflows. With a Task, you can direct an agent like Claude Code to update your documentation or even diagnose and address a bug. By connecting GitHub to Coder Tasks, you can build out a GitHub workflow that will for example:
8+
9+
1. Trigger an automation to take a pre-existing issue
10+
1. Automatically spin up a Coder Task with the context from that issue and direct an agent to work on it
11+
1. Focus on other higher-priority needs, while the agent addresses the issue
12+
1. Get notified that the issue has been addressed, and you can review the proposed solution
13+
14+
This guide walks you through how to configure GitHub and Coder together so that you can tag Coder in a GitHub issue comment, and securely delegate work to coding agents in a Coder Task.
15+
16+
## Implementing the GHA
17+
18+
The below steps outline how to use the Coder [Create Task Action GHA](https://github.com/coder/create-task-action) in a GitHub workflow to solve a bug. The guide makes the following assumptions:
19+
20+
- You have access to a Coder Server that is running. If you don't have a Coder Server running, follow our [Quickstart Guide](https://coder.com/docs/tutorials/quickstart)
21+
- Your Coder Server is accessible from GitHub
22+
- You have an AI-enabled Task Template that can successfully create a Coder Task. If you don't have a Task Template available, follow our [Getting Started with Tasks Guide](https://coder.com/docs/ai-coder/tasks#getting-started-with-tasks)
23+
- Check the [Requirements section of the GHA](https://github.com/coder/create-task-action?tab=readme-ov-file#requirements) for specific version requirements for your Coder deployment and the following
24+
- GitHub OAuth is configured in your Coder Deployment
25+
- Users have linked their GitHub account to Coder via `/settings/external-auth`
26+
27+
This guide can be followed for other use cases beyond bugs like updating documentation or implementing a small feature, but may require minor changes to file names and the prompts provided to the Coder Task.
28+
29+
### Step 1: Create a GitHub Workflow file
30+
31+
In your repository, create a new file in the `./.github/workflows/` directory named `triage-bug.yaml`. Within that file, add the following code:
32+
33+
```yaml
34+
name: Start Coder Task
35+
36+
on:
37+
issues:
38+
types:
39+
- labeled
40+
41+
permissions:
42+
issues: write
43+
44+
jobs:
45+
coder-create-task:
46+
runs-on: ubuntu-latest
47+
if: github.event.label.name == 'coder'
48+
steps:
49+
- name: Coder Create Task
50+
uses: coder/create-task-action@v0
51+
with:
52+
coder-url: ${{ secrets.CODER_URL }}
53+
coder-token: ${{ secrets.CODER_TOKEN }}
54+
coder-organization: "default"
55+
coder-template-name: "my-template"
56+
coder-task-name-prefix: "gh-task"
57+
coder-task-prompt: "Use the gh CLI to read ${{ github.event.issue.html_url }}, write an appropriate plan for solving the issue to PLAN.md, and then wait for feedback."
58+
github-user-id: ${{ github.event.sender.id }}
59+
github-issue-url: ${{ github.event.issue.html_url }}
60+
github-token: ${{ github.token }}
61+
comment-on-issue: true
62+
```
63+
64+
This code will perform the following actions:
65+
66+
- Create a Coder Task when you apply the `coder` label to an existing GitHub issue
67+
- Pass as a prompt to the Coder Task:
68+
69+
1. Use the GitHub CLI to access and read the content of the linked GitHub issue
70+
1. Generate an initial implementation plan to solve the bug
71+
1. Write that plan to a `PLAN.md` file
72+
1. Wait for additional input
73+
74+
- Post an update on the GitHub ticket with a link to the task
75+
76+
The prompt text can be modified to not wait for additional human input, but continue with implementing the proposed solution and creating a PR for example. Note that this example prompt uses the GitHub CLI `gh`, which must be installed in your Coder template. The CLI will automatically authenticate using the user's linked GitHub account via Coder's external auth.
77+
78+
### Step 2: Setup the Required Secrets & Inputs
79+
80+
The GHA has multiple required inputs that require configuring before the workflow can successfully operate.
81+
82+
You must set the following inputs as secrets within your repository:
83+
84+
- `coder-url`: the URL of your Coder deployment, e.g. https://coder.example.com
85+
- `coder-token`: follow our [API Tokens documentation](https://coder.com/docs/admin/users/sessions-tokens#long-lived-tokens-api-tokens) to generate a token. Note that the token must be an admin/org-level with the "Read users in organization" and "Create tasks for any user" permissions
86+
87+
You must also set `coder-template-name` as part of this. The GHA example has this listed as a secret, but the value doesn't need to be stored as a secret. The template name can be determined the following ways:
88+
89+
- By viewing the URL of the template in the UI, e.g. `https://<your-coder-url>/templates/<org-name>/<template-name>`
90+
- Using the Coder CLI:
91+
92+
```bash
93+
# List all templates in your organization
94+
coder templates list
95+
96+
# List templates in a specific organization
97+
coder templates list --org your-org-name
98+
```
99+
100+
You can also choose to modify the other [input parameters](https://github.com/coder/create-task-action?tab=readme-ov-file#inputs) to better fit your desired workflow.
101+
102+
#### Template Requirements for GitHub CLI
103+
104+
If your prompt uses the GitHub CLI `gh`, your template must pass the user's GitHub token to the agent. Add this to your template's Terraform:
105+
106+
```terraform
107+
data "coder_external_auth" "github" {
108+
id = "github" # Must match your CODER_EXTERNAL_AUTH_0_ID
109+
}
110+
111+
resource "coder_agent" "dev" {
112+
# ... other config ...
113+
env = {
114+
GITHUB_TOKEN = data.coder_external_auth.github.access_token
115+
}
116+
}
117+
```
118+
119+
Note that tokens passed as environment variables represent a snapshot at task creation time and are not automatically refreshed during task execution.
120+
121+
- If your GitHub external auth is configured as a GitHub App with token expiration enabled (the default), tokens expire after 8 hours
122+
- If configured as a GitHub OAuth App or GitHub App with expiration disabled, tokens remain valid unless unused for 1 year
123+
124+
Because of this, we recommend to:
125+
126+
- Keep tasks under 8 hours to avoid token expiration issues
127+
- For longer workflows, break work into multiple sequential tasks
128+
- If authentication fails mid-task, users must re-authenticate at /settings/external-auth and restart the task
129+
130+
For more information, see our [External Authentication documentation](https://coder.com/docs/admin/external-auth#configure-a-github-oauth-app).
131+
132+
### Step 3: Test Your Setup
133+
134+
Create a new GitHub issue for a bug in your codebase. We recommend a basic bug, for this test, like “The sidebar color needs to be red” or “The text ‘Coder Tasks are Awesome’ needs to appear in the top left corner of the screen”. You should adapt the phrasing to be specific to your codebase.
135+
136+
Add the `coder` label to that GitHub issue. You should see the following things occur:
137+
138+
- A comment is made on the issue saying `Task created: https://<your-coder-url>/tasks/username/task-id`
139+
- A Coder Task will spin up, and you'll receive a Tasks notification to that effect
140+
- You can click the link to follow the Task's progress in creating a plan to solve your bug
141+
142+
Depending on the complexity of the task and the size of your repository, the Coder Task may take minutes or hours to complete. Our recommendation is to rely on Task Notifications to know when the Task completes, and further action is required.
143+
144+
And that’s it! You may now enjoy all the hours you have saved because of this easy integration.
145+
146+
### Step 4: Adapt this Workflow to your Processes
147+
148+
Following the above steps sets up a GitHub Workflow that will
149+
150+
1. Allow you to label bugs with `coder`
151+
1. A coding agent will determine a plan to address the bug
152+
1. You'll receive a notification to review the plan and prompt the agent to proceed, or change course
153+
154+
We recommend that you further adapt this workflow to better match your process. For example, you could:
155+
156+
- Modify the prompt to implement the plan it came up with, and then create a PR once it has a solution
157+
- Update your GitHub issue template to automatically apply the `coder` label to attempt to solve bugs that have been logged
158+
- Modify the underlying use case to handle updating documentation, implementing a small feature, reviewing bug reports for completeness, or even writing unit tests
159+
- Modify the workflow trigger for other scenarios such as:
160+
161+
```yml
162+
# Comment-based trigger slash commands
163+
on:
164+
issue_comment:
165+
types: [created]
166+
167+
jobs:
168+
trigger-on-comment:
169+
runs-on: ubuntu-latest
170+
if: startsWith(github.event.comment.body, '/coder')
171+
172+
# On Pull Request Creation
173+
jobs:
174+
on-pr-opened:
175+
runs-on: ubuntu-latest
176+
# No if needed - just runs on PR open
177+
178+
# On changes to a specific directory
179+
on:
180+
pull_request:
181+
paths:
182+
- 'docs/**'
183+
- 'src/api/**'
184+
- '*.md'
185+
186+
jobs:
187+
on-docs-changed:
188+
runs-on: ubuntu-latest
189+
# Runs automatically when files in these paths change
190+
```
191+
192+
## Summary
193+
194+
This guide shows you how to automatically delegate routine engineering work to AI coding agents by connecting GitHub issues to Coder Tasks. When you label an issue (like a bug report or documentation update), a coding agent spins up in a secure Coder workspace, reads the issue context, and works on solving it while you focus on higher-priority tasks. The agent reports back with a proposed solution for you to review and approve, turning hours of repetitive work into minutes of oversight. This same pattern can be adapted to handle documentation updates, test writing, code reviews, and other automatable workflows across your development process.
195+
196+
## Troubleshooting
197+
198+
### "No Coder user found with GitHub user ID X"
199+
200+
**Cause:** The user who triggered the workflow hasn't linked their GitHub account to Coder.
201+
202+
**Solution:**
203+
204+
1. Ensure GitHub OAuth is configured in your Coder deployment (see [External Authentication docs](https://coder.com/docs/admin/external-auth#configure-a-github-oauth-app))
205+
1. Have the user visit `https://<your-coder-url>/settings/external-auth` and link their GitHub account
206+
1. Retry the workflow by re-applying the `coder` label or however else the workflow is triggered
207+
208+
### "Failed to create task: 403 Forbidden"
209+
210+
**Cause:** The `coder-token` doesn't have the required permissions.
211+
212+
**Solution:** The token must have:
213+
214+
- Read users in organization
215+
- Create tasks for any user
216+
217+
Generate a new token with these permissions at `https://<your-coder-url>/deployment/general`. See the [Coder Create Task GHA requirements](https://github.com/coder/create-task-action?tab=readme-ov-file#requirements) for more specific information.
218+
219+
### "Template 'my-template' not found"
220+
221+
**Cause:** The `coder-template-name` is incorrect or the template doesn't exist in the specified organization.
222+
223+
**Solution:**
224+
225+
1. Verify the template name using: `coder templates list --org your-org-name`
226+
1. Update the `coder-template-name` input in your workflow file to match exactly, or input secret or variable saved in GitHub
227+
1. Ensure the template exists in the organization specified by `coder-organization`
228+
229+
### Task fails with "authentication failed" or "Bad credentials" after running for hours
230+
231+
**Symptoms:**
232+
233+
- Task starts successfully and works initially
234+
- After some time passes, `gh` CLI commands fail with:
235+
236+
- `authentication failed`
237+
- `Bad credentials`
238+
- `HTTP 401 Unauthorized`
239+
- `error getting credentials` from git operations
240+
241+
**Cause:** The GitHub token expired during task execution. Tokens passed as environment variables are captured at task creation time and expire after 8 hours (for GitHub Apps with expiration enabled). These tokens are not automatically refreshed during task execution.
242+
243+
**Diagnosis:**
244+
245+
From within the running task workspace, check if the token is still valid:
246+
247+
```bash
248+
# Check if the token still works
249+
curl -H "Authorization: token ${GITHUB_TOKEN}" \
250+
https://api.github.com/user
251+
```
252+
253+
If this returns 401 Unauthorized or Bad credentials, the token has expired.
254+
255+
**Solution:**
256+
257+
1. Have the user re-authenticate at https://<your-coder-url>/settings/external-auth
258+
1. Verify the GitHub provider shows "Authenticated" with a green checkmark
259+
1. Re-trigger the workflow to create a new task with a fresh token

docs/manifest.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -891,30 +891,31 @@
891891
"title": "Coder Tasks",
892892
"description": "Run Coding Agents on your Own Infrastructure",
893893
"path": "./ai-coder/tasks.md",
894-
"state": ["beta"],
895894
"children": [
896895
{
897896
"title": "Understanding Coder Tasks",
898897
"description": "Core principles and concepts behind Coder Tasks",
899-
"path": "./ai-coder/tasks-core-principles.md",
900-
"state": ["beta"]
898+
"path": "./ai-coder/tasks-core-principles.md"
901899
},
902900
{
903901
"title": "Custom Agents",
904902
"description": "Run custom agents with Coder Tasks",
905-
"path": "./ai-coder/custom-agents.md",
906-
"state": ["beta"]
903+
"path": "./ai-coder/custom-agents.md"
907904
},
908905
{
909906
"title": "Tasks Migration Guide",
910907
"description": "Changes to Coder Tasks made in v2.28",
911-
"path": "./ai-coder/tasks-migration.md",
912-
"state": ["beta"]
908+
"path": "./ai-coder/tasks-migration.md"
913909
},
914910
{
915911
"title": "Security \u0026 Boundaries",
916912
"description": "Learn about security and boundaries when running AI coding agents in Coder",
917913
"path": "./ai-coder/security.md"
914+
},
915+
{
916+
"title": "Create a GitHub to Coder Tasks Workflow",
917+
"description": "How to setup Coder Tasks to run in GitHub",
918+
"path": "./ai-coder/github-to-tasks.md"
918919
}
919920
]
920921
},

0 commit comments

Comments
 (0)