Jira
Jira Cloud is an issue tracker: an issue assigned to kōjō’s Atlassian account, labelled with a label you choose, or a comment that mentions kōjō starts a session on the repository the issue’s project maps to. kōjō comments the outcome on the issue, with the pull request’s link, and the pull request’s title carries the issue key so that Jira links the two.
See Surfaces for how Jira compares with Linear and Asana, and Who may trigger what for whose requests may change code.
How it connects
kōjō acts as an Atlassian account of its own, reached with that account’s email and an API token (basic authentication against https://<site>.atlassian.net, REST API v3). Assigning an issue to that account, or mentioning it, is how people ask kōjō for work.
A Jira admin creates a webhook to <public_url>/webhooks/jira with a secret. Jira signs every delivery with it: X-Hub-Signature is sha256= and the hex HMAC-SHA256 of the raw body, keyed with the secret (webhook_secret). kōjō refuses a delivery that is not signed with it, so a webhook without a secret delivers nothing. A delivery Jira retries carries the same X-Atlassian-Webhook-Identifier, and kōjō handles it once.
kōjō then reads the issue with the API token, and posts comments and transitions the issue the same way.
Set up
kojo setup jira --public-url https://kojo.example.com --site https://acme.atlassian.net prints these steps with your addresses filled in.
-
Create the Atlassian account kōjō acts as. In each project it works on it needs Browse projects and Add comments, and Transition issues if
statusis set. Sign in as it and create an API token without scopes at https://id.atlassian.com/manage-profile/security/api-tokens. A token with scopes only works throughapi.atlassian.com, which kōjō does not use. -
As a Jira admin, create a webhook: Jira settings → System → WebHooks. The URL is
<public_url>/webhooks/jira. Generate a secret and keep it. Select the events Issue created, Issue updated and Comment created, and optionally a JQL filter such asproject in (PAY, WEB). -
Add the tracker to
kojo.yaml:trackers: jira: base_url: https://acme.atlassian.net email: ${JIRA_EMAIL} # the account of the API token api_token: ${JIRA_API_TOKEN} webhook_secret: ${JIRA_WEBHOOK_SECRET} labels: [kojo] # optional: adding this label also starts work status: # optional: off unless set started: In Progress review: In Review users: # Atlassian account ID: email in the rbac object "557058:f58131cb-b67d-43c7-b30d-6b58d40bd077": ana@example.com -
Map each project to its repository in the
reposobject (dashboard: Settings → Repositories). See Mapping issues to repositories. -
Map the people who may have kōjō change code under
users, and give their emails the operator role in therbacobject. See Who may change code. -
Run
kojo doctor. It checks that the API token reads its own account, and warns when no enabled repository takes Jira issues.
Events
| Webhook event | Becomes |
|---|---|
jira:issue_updated with the assignee changed to kōjō’s account |
A request for the issue |
jira:issue_updated with one of the labels in labels added |
A request for the issue |
jira:issue_created with kōjō’s account as the assignee, or with one of the labels |
A request for the issue |
comment_created, when the comment mentions kōjō’s account |
A request for the issue, or a message to its session |
A mention is read from the comment’s body in either form Jira may send: a mention node in Atlassian Document Format, or [~accountid:…] in wiki markup. kōjō’s own changes and comments are ignored, and so is every other event. An issue that already has a session at work does not start another when it is assigned or labelled.
Mapping issues to repositories
An issue becomes work on the repository whose tickets entry matches it. A Jira entry names a project by its key, and may add a label:
repos:
github/acme/payments:
enabled: true
tickets:
- { tracker: jira, project: PAY }
github/acme/web:
enabled: true
tickets:
- { tracker: jira, project: WEB }
- { tracker: jira, project: PAY, label: frontend }
An issue that matches no enabled repository, or several (in this example, a PAY issue labelled frontend), starts nothing: kōjō comments on it that it belongs to no repository, or names the repositories it belongs to. The full rules are under repos.
Who may change code
Jira gives a bot no email it can rely on: webhooks leave the address out, the REST API hides it unless the person chose to show it, an Atlassian account’s address is not necessarily verified, and Atlassian’s documentation identifies people by account ID. So kōjō does not read emails from Jira. users maps an Atlassian account ID to the email of that person’s entry in the rbac object, and the role found there decides.
- Someone mapped to an email with the operator or admin role gets a trusted session, which may change code and open a pull request.
- Anyone else gets a read-only session: kōjō answers on the issue and changes nothing. See What an untrusted session may do.
A person’s account ID is the last part of the address of their profile in Jira. users is in kojo.yaml, so changing it needs a restart.
What kōjō posts
- The outcome is a comment on the issue: the summary, the pull request’s link, and the goal critic’s report when the change did not meet every criterion. kōjō writes Markdown and posts it as Atlassian Document Format: paragraphs, bullet lists, code blocks, links, inline code and bold. The orchestrator may also post short interim comments while it works.
- The pull request opened on the forge starts its title with the issue key (
PAY-7: …), and its description links the issue. GitHub for Jira and Jira’s GitLab integration link a pull request whose title holds the key. - The status moves only when
statusnames one:startedwhen a session that may change code is queued for the issue,reviewwhen it opens a pull request. kōjō makes the issue’s transition that leads to the status of that name, and leaves an issue that is already there alone. A read-only session moves nothing.
The issue’s summary, description, labels and its latest 10 comments are part of the request, inside the fence that marks them as data. See Security.
Talking to a session at work
A new comment that mentions kōjō on an issue whose session is queued or running goes to that session as a message when its author is mapped to the operator role. kōjō acknowledges it with a comment, and the session’s next model step reads it. A comment from anyone else is a read-only request of its own. See Talking to a session at work.
Webhook
kōjō answers 200 to a delivery it handled, ignored or turned down, 401 to one whose signature does not verify, and 500 when it could not handle it, for example because Jira’s API did not answer; Jira retries a 500.
Limits
- Jira Cloud only. Jira Data Center and Server are not supported, and neither are scoped API tokens, service accounts (both need
api.atlassian.com) or Jira apps (Connect, Forge, OAuth 2.0). - An approval the merge policy would ask for in chat has no chat thread to be asked in, so the session takes the more careful outcome there.