Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 80 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,87 @@

This GitHub action starts a [Coder Task](https://coder.com/docs/ai-coder/tasks) and optionally posts a comment on a GitHub issue. It's designed to be used as part of a wider workflow.

## Features
## Overview

- Starts a Coder Task using your specified template and preset
- Posts a single status comment on a GitHub issue
- Maps GitHub users to Coder users
- When creating a Coder task, you must specify the Github user ID as an input.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- When creating a Coder task, you must specify the Github user ID as an input.
- When creating a Coder task, you must specify the Github username as an input.

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We store the GitHub user ID in the users table and lookup based on that, not the username.

- The action then queries the Coder deployment to find the Coder user associated with the given Github user ID.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

- Note that this requires the Coder deployment to be configured with [GitHub OAuth](https://coder.com/docs/admin/external-auth#configure-a-github-oauth-app) and for the Coder user to have linked their GitHub account.
- If no corresponding Coder user is found, the action will fail.
- The action will then create a [Coder Task](https://coder.com/docs/ai-coder/tasks) for the user with the given template and prompt.
- Once the task has been created successfully, the action will post a comment on the GitHub issue with the task URL.

## Requirements

- A running Coder deployment (v2.28 or higher) accessible to the GitHub Actions runner.
- A [Tasks-capable](https://coder.com/docs/ai-coder/tasks#getting-started-with-tasks) Coder template
- A Coder session token with the required permissions to:
- Read all users in the given organization
- Create tasks for any user in the given organization

## Example Usage

TODO
The below example will start a Coder task when the `coder` label is applied to an issue.

```yaml
name: Start Coder Task

on:
issues:
types:
- labeled

permissions:
issues: write

jobs:
start-coder-task:
runs-on: ubuntu-latest
if: github.event.label.name == 'coder'
steps:
- name: Start Coder Task
uses: coder/start-coder-task@v0.0.2
with:
coder-url: ${{ secrets.CODER_URL }}
coder-token: ${{ secrets.CODER_TOKEN }}
coder-organization: "default"
coder-template-name: "my-template"
coder-task-name-prefix: "gh-task"
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."
github-user-id: ${{ github.event.sender.id }}
github-issue-url: ${{ github.event.issue.html_url }}
github-token: ${{ github.token }}
comment-on-issue: true
```

## Inputs

<!--
yq -r '.inputs | to_entries[] | "| \(.key) | \(.value.description) | \(.value.required // false ) | \(.value.default // \"-\") |"' action.yaml
-->

| Name | Description | Required | Default |
| ---------------------- | --------------------------------------- | -------- | --------- |
| coder-task-prompt | Prompt/instructions to send to the task | true | - |
| coder-token | Coder session token for authentication | true | - |
| coder-url | Coder deployment URL | true | - |
| coder-template-name | Coder template to use for workspace | true | - |
| github-issue-url | GitHub issue URL to link this task to | true | - |
| github-token | GitHub token for API operations | true | - |
| github-user-id | GitHub user ID to create task for | true | - |
| coder-organization | Coder organization name | false | "default" |
| coder-task-name-prefix | Prefix for task name | false | "gh" |
| coder-template-preset | Template preset to use (optional) | false | - |
| comment-on-issue | Whether to comment on the GitHub issue | false | true |

## Outputs

<!--
yq -r '.outputs | to_entries[] | "| \(.key) | \(.value.description) |"' action.yaml
-->

| Name | Description |
| -------------- | -------------------------------------------------------------------- |
| coder-username | The Coder username resolved from GitHub user |
| task-name | The task name |
| task-url | The URL to view the task in Coder |
| task-created | Whether the task was newly created (true) or already existed (false) |
18 changes: 10 additions & 8 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ inputs:
description: "Coder deployment URL"
required: true

coder-organization:
description: "Coder organization name"
required: true

coder-task-name-prefix:
description: "Prefix for task name"
required: true

coder-template-name:
description: "Coder template to use for workspace"
required: true
Expand All @@ -40,6 +32,16 @@ inputs:
required: true

# Optional inputs
coder-organization:
description: "Coder organization name"
required: false
default: "default"

coder-task-name-prefix:
description: "Prefix for task name"
required: false
default: "gh"

coder-template-preset:
description: "Template preset to use (optional)"
required: false
Expand Down
1 change: 1 addition & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26928,6 +26928,7 @@ class CoderTaskAction {
if (!this.inputs.coderTaskNamePrefix || !this.inputs.githubIssueURL) {
throw new Error("either taskName or both taskNamePrefix and issueURL must be provided");
}
core.info(`Coder organization: ${this.inputs.coderOrganization}`);
const taskNameString = `${this.inputs.coderTaskNamePrefix}-${githubIssueNumber}`;
const taskName = TaskNameSchema.parse(taskNameString);
core.info(`Coder Task name: ${taskName}`);
Expand Down Expand Up @@ -27004,12 +27005,12 @@ var ActionInputsSchema = exports_external.object({
coderTaskPrompt: exports_external.string().min(1),
coderToken: exports_external.string().min(1),
coderURL: exports_external.string().url(),
coderOrganization: exports_external.string().min(1),
coderTaskNamePrefix: exports_external.string().min(1),
coderTemplateName: exports_external.string().min(1),
githubIssueURL: exports_external.string().url(),
githubToken: exports_external.string(),
githubUserID: exports_external.number().min(1),
coderOrganization: exports_external.string().min(1).optional().default("default"),
coderTaskNamePrefix: exports_external.string().min(1).optional().default("gh"),
coderTemplatePreset: exports_external.string().optional(),
commentOnIssue: exports_external.boolean().default(true)
});
Expand Down
1 change: 1 addition & 0 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export class CoderTaskAction {
"either taskName or both taskNamePrefix and issueURL must be provided",
);
}
core.info(`Coder organization: ${this.inputs.coderOrganization}`);
const taskNameString = `${this.inputs.coderTaskNamePrefix}-${githubIssueNumber}`;
const taskName = TaskNameSchema.parse(taskNameString);
core.info(`Coder Task name: ${taskName}`);
Expand Down
4 changes: 2 additions & 2 deletions src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ export const ActionInputsSchema = z.object({
coderTaskPrompt: z.string().min(1),
coderToken: z.string().min(1),
coderURL: z.string().url(),
coderOrganization: z.string().min(1),
coderTaskNamePrefix: z.string().min(1),
coderTemplateName: z.string().min(1),
githubIssueURL: z.string().url(),
githubToken: z.string(),
githubUserID: z.number().min(1),
// Optional
coderOrganization: z.string().min(1).optional().default("default"),
coderTaskNamePrefix: z.string().min(1).optional().default("gh"),
coderTemplatePreset: z.string().optional(),
commentOnIssue: z.boolean().default(true),
});
Expand Down
Loading