Start runs from GitHub issues
Start runs from GitHub issues when your team plans its work in issues and wants an agent to pick up the ones you mark. In this guide you let the label codeband/webshop/fix_issue start the pipeline fix_issue of the factory webshop on an issue of the repository acme/webshop. At the end, the issue’s thread shows a comment that names the run, and the run ends with a draft pull request in acme/webshop. If no run starts, see Troubleshooting at the end of this page.
Before you start
Section titled “Before you start”- A daemon serves your factory as
webshop, ascodeband.tomlnames it. - You have write access to the GitHub repository, here
acme/webshop. - You have a GitHub token with Contents, Pull requests and Issues set to Read and write, such as the one of
gh auth token.
How an issue starts a run
Section titled “How an issue starts a run”The daemon polls the issues of each repository that codeband.toml names. When a person with write or triage access sets the label codeband/FACTORY/PIPELINE on an issue, the daemon starts that pipeline with the issue as its ticket. The person who sets the label vouches for the issue’s text: the run input holds the issue and every comment written before the label, by anyone. Comments written later reach no running run.
-
Take a ticket in the pipeline
Only a pipeline with a parameter
ticketof the SDK’s ticket type starts from an issue. The ticket holds the issue’s number as its ID, its title, its body followed by the comments written before the label, its labels as tags, and its URL:webshop/pipelines/fix_issue.py import codeband as cbfrom webshop.agents.fixer import FixInput, fixer@cb.pipelinedef fix_issue(ticket: cb.Ticket) -> cb.RunResult | None:"""Fix the bug that the issue describes and end the run with the fix."""agent_step = fixer.do(FixInput(title=ticket.title, body=ticket.body))change = cb.CodeChange(commit=agent_step.commit, title=agent_step.output.title, description=agent_step.output.summary)return cb.RunResult(code_change=change)cb.Ticketlists the fields of a ticket. -
Name the repository in
codeband.tomlAdd the repository to
repositoriesof the[github]table, next to the token:codeband.toml [factories.webshop]code_server = "unix:/var/run/codeband/webshop.sock"[github]token = { command = ["gh", "auth", "token"] }repositories = ["acme/webshop"]The token also needs read access to the collaborators of the repository, so that the daemon can check who set a label and who answers.
-
Restart the daemon
The daemon reads
codeband.tomlonly when it starts. Stop it with Ctrl-C and start it again:Terminal window codeband daemonThe daemon creates the label
codeband/webshop/fix_issueinacme/webshop, with the description offix_issue. The labels page of the repository on GitHub lists it. A label name has at most 50 characters, soFACTORY/PIPELINEmay have at most 41. -
Set the label on an issue
Open an issue in
acme/webshop, such as “The cart total ignores the discount”, and set the labelcodeband/webshop/fix_issue. On its next poll, the daemon starts a run ofwebshop/fix_issueon the default branch ofacme/webshopand comments on the issue with the run ID. -
Answer in the thread
A human step of the run posts its question as a comment in the issue’s thread. Answer it with a comment. Only a comment by a person with write access to the repository answers a human step, and the first answer that the run accepts counts. You can also answer in the web interface or with
codeband answer.
Check that it worked
Section titled “Check that it worked”When the run ends, the daemon comments on the issue with how it ended, and the run’s code change is a draft pull request in acme/webshop. Its description ends with a line that names the run. The page for the run in the web interface shows its steps, its agent transcripts and its scores.
Troubleshooting
Section titled “Troubleshooting”| What you see | Why | Fix |
|---|---|---|
| No run starts and no comment appears | The person who set the label has neither write nor triage access, or the repository is not in repositories |
Have a person with access set the label, or add the repository and restart the daemon |
| A comment says the pipeline does not exist or takes no ticket | The label names a pipeline that no factory has, or one without the parameter ticket |
Fix the label, or add the parameter ticket to the pipeline |
| A comment says the pipeline name is too long | codeband/FACTORY/PIPELINE is longer than GitHub’s 50 characters for a label |
Rename the pipeline or the factory |
| The daemon logs a warning that it cannot create labels | The token may not create labels in the repository | Create the label by hand, or give the token Issues set to Read and write. codeband check names the missing permission |
Next steps
Section titled “Next steps”- Run result: how the daemon changes the text of pull requests and issues before it writes them.
- Human step: the questions that a run asks in the issue’s thread.
- Scorer: the scores by which you see how the runs of your issues go.