|
| 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 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 | + |
| 28 | +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. |
| 29 | + |
| 30 | +###Step 1: Create a GitHub Workflow file |
| 31 | + |
| 32 | +In your repository, create a new file in the`./.github/workflows/` directory named`triage-bug.yaml`. Within that file, add the following code: |
| 33 | + |
| 34 | +```yaml |
| 35 | +name:Start Coder Task |
| 36 | + |
| 37 | +on: |
| 38 | +issues: |
| 39 | +types: |
| 40 | + -labeled |
| 41 | + |
| 42 | +permissions: |
| 43 | +issues:write |
| 44 | + |
| 45 | +jobs: |
| 46 | +coder-create-task: |
| 47 | +runs-on:ubuntu-latest |
| 48 | +if:github.event.label.name == 'coder' |
| 49 | +steps: |
| 50 | + -name:Coder Create Task |
| 51 | +uses:coder/create-coder-task@v0 |
| 52 | +with: |
| 53 | +coder-url:${{ secrets.CODER_URL }} |
| 54 | +coder-token:${{ secrets.CODER_TOKEN }} |
| 55 | +coder-organization:"default" |
| 56 | +coder-template-name:"my-template" |
| 57 | +coder-task-name-prefix:"gh-task" |
| 58 | +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." |
| 59 | +github-user-id:${{ github.event.sender.id }} |
| 60 | +github-issue-url:${{ github.event.issue.html_url }} |
| 61 | +github-token:${{ github.token }} |
| 62 | +comment-on-issue:true |
| 63 | +``` |
| 64 | +
|
| 65 | +This code will perform the following actions: |
| 66 | +
|
| 67 | +- Create a Coder Task when you apply the`coder` label to an existing GitHub issue |
| 68 | +-Pass as a prompt to the Coder Task |
| 69 | + |
| 70 | +1. Use the GitHub CLI to access and read the content of the linked GitHub issue |
| 71 | +1. Generate an initial implementation plan to solve the bug |
| 72 | +1. Write that plan to a `PLAN.md` file |
| 73 | +1. Wait for additional input |
| 74 | + |
| 75 | +-Post an update on the GitHub ticket with a link to the task |
| 76 | + |
| 77 | +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. |
| 78 | + |
| 79 | +### Step 2: Setup the Required Secrets & Inputs |
| 80 | + |
| 81 | +The GHA has multiple required inputs that require configuring before the workflow can successfully operate. |
| 82 | + |
| 83 | +You must set the following inputs as secrets within your repository: |
| 84 | + |
| 85 | +-`coder-url`:the URL of your Coder deployment, e.g. https://coder.example.com |
| 86 | +-`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 |
| 87 | + |
| 88 | +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: |
| 89 | + |
| 90 | +-By viewing the URL of the template in the UI, e.g. `https://your-coder-url/templates/<org-name>/<template-name>` |
| 91 | +-Using the Coder CLI: |
| 92 | + |
| 93 | +```bash |
| 94 | +# List all templates in your organization |
| 95 | +coder templates list |
| 96 | +
|
| 97 | +# List templates in a specific organization |
| 98 | +coder templates list --org your-org-name |
| 99 | +``` |
| 100 | + |
| 101 | +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. |
| 102 | + |
| 103 | +### Step 3: Test Your Setup |
| 104 | + |
| 105 | +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. |
| 106 | + |
| 107 | +Add the `coder` label to that GitHub issue. You should see the following things occur: |
| 108 | + |
| 109 | +-A comment is made on the issue saying `Task created:https://your-coder-url/tasks/username/task-id` |
| 110 | +-A Coder Task will spin up, and you'll receive a Tasks notification to that effect |
| 111 | +-You can click the link to follow the Task's progress in creating a plan to solve your bug |
| 112 | + |
| 113 | +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. |
| 114 | + |
| 115 | +And that’s it! You may now enjoy all the hours you have saved because of this easy integration. |
| 116 | + |
| 117 | +#### Step 4: Adapt this Workflow to your Processes |
| 118 | + |
| 119 | +Following the above steps sets up a GitHub Workflow that will |
| 120 | + |
| 121 | +1. Allow you to label bugs with `coder` |
| 122 | +1. A coding agent will determine a plan to address the bug |
| 123 | +1. You'll receive a notification to review the plan and prompt the agent to proceed, or change course |
| 124 | + |
| 125 | +We recommend that you further adapt this workflow to better match your process. For example, you could: |
| 126 | + |
| 127 | +-Modify the prompt to implement the plan it came up with, and then create a PR once it has a solution |
| 128 | +-Update your GitHub issue template to automatically apply the `coder` label to attempt to solve bugs that have been logged |
| 129 | +-Modify the underlying use case to handle updating documentation, implementing a small feature, reviewing bug reports for completeness, or even writing unit test |
| 130 | +-Modify the workflow trigger for other scenarios such as: |
| 131 | + |
| 132 | +```yml |
| 133 | +# Comment-based trigger slash commands |
| 134 | +on: |
| 135 | + issue_comment: |
| 136 | + types: [created] |
| 137 | +
|
| 138 | +jobs: |
| 139 | + trigger-on-comment: |
| 140 | + runs-on: ubuntu-latest |
| 141 | + if: startsWith(github.event.comment.body, '/coder') |
| 142 | +
|
| 143 | +# On Pull Request Creation |
| 144 | +jobs: |
| 145 | + on-pr-opened: |
| 146 | + runs-on: ubuntu-latest |
| 147 | + # No if needed - just runs on PR open |
| 148 | +
|
| 149 | +# On changes to a specific directory |
| 150 | +on: |
| 151 | + pull_request: |
| 152 | + paths: |
| 153 | + - 'docs/**' |
| 154 | + - 'src/api/**' |
| 155 | + - '*.md' |
| 156 | +
|
| 157 | +jobs: |
| 158 | + on-docs-changed: |
| 159 | + runs-on: ubuntu-latest |
| 160 | + # Runs automatically when files in these paths change |
| 161 | +``` |
| 162 | + |
| 163 | +## Summary |
| 164 | + |
| 165 | +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. |
| 166 | + |
| 167 | +## Troubleshooting |
| 168 | + |
| 169 | +### "No Coder user found with GitHub user ID X" |
| 170 | + |
| 171 | +**Cause:** The user who triggered the workflow hasn't linked their GitHub account to Coder. |
| 172 | + |
| 173 | +**Solution:** |
| 174 | +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)) |
| 175 | +2. Have the user visit `https://your-coder-url/settings/external-auth` and link their GitHub account |
| 176 | +3. Retry the workflow by re-applying the `coder` label or however else the workflow is triggered |
| 177 | + |
| 178 | +### "Failed to create task: 403 Forbidden" |
| 179 | + |
| 180 | +**Cause:** The `coder-token` doesn't have the required permissions. |
| 181 | + |
| 182 | +**Solution:** The token must have: |
| 183 | +-Read users in organization |
| 184 | +-Create tasks for any user |
| 185 | + |
| 186 | +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. |
| 187 | + |
| 188 | +### "Template 'my-template' not found" |
| 189 | + |
| 190 | +**Cause:** The `coder-template-name` is incorrect or the template doesn't exist in the specified organization. |
| 191 | + |
| 192 | +**Solution:** |
| 193 | +1. Verify the template name using:`coder templates list --org your-org-name` |
| 194 | +2. Update the `coder-template-name` input in your workflow file to match exactly, or input secret or variable saved in GitHub |
| 195 | +3. Ensure the template exists in the organization specified by `coder-organization` |