Skip to content
GitHub

DevelopOther

@holtkeeper/issues-jira

A read-only IssueTracker (@holtkeeper/issues) for Jira Cloud and Jira Data Center / Server. The server builds it from a credential of kind jira whose scope covers the repository; without one, nothing calls Jira.

import { jiraTracker } from '@holtkeeper/issues-jira'
const tracker = jiraTracker({
url: 'https://widgets.atlassian.net',
auth: { kind: 'basic', email: 'bot@example.com', token: process.env.JIRA_TOKEN! },
})
const issues = await tracker.issues(['ABC-1', 'ABC-2'])
  • jiraTracker({ url, auth, flavor?, projects?, fetch? }) — auth is { kind: 'basic', email, token } (Cloud API token) or { kind: 'bearer', token } (Data Center personal access token). flavor defaults to cloud for *.atlassian.net and api.atlassian.com, datacenter otherwise. projects (project keys like ABC) limits which keys are ever sent; keys of other projects read as unknown.
  • jiraFromCredential(credential, secret, { fetch? }) — the tracker of a stored jira credential: url is the site, options { authKind: 'basic', email } or { authKind: 'bearer' } with optional flavor and projects; throws on another kind or invalid options.
  • validateJiraCredentialOptions(kind, options) — a CredentialOptionsValidator for @holtkeeper/credentials: field: message problems for jira credentials, undefined for other kinds.
  • JIRA_CREDENTIAL_KIND (jira), JiraApiError (status), JIRA_DESCRIPTION_MAX_CHARS.
Flavor Search (up to 100 keys) One issue
Cloud GET /rest/api/3/search/jql?jql=key in (...)&fields=summary,status,issuetype GET /rest/api/3/issue/{key}?fields=...
Data Center GET /rest/api/2/search?jql=key in (...)&fields=summary,status,issuetype&validateQuery=warn GET /rest/api/2/issue/{key}?fields=...

Keys that do not look like Jira keys (ABC-123) are never sent, so no text from commits reaches the query. Jira refuses a search naming a key that does not exist with 400; the tracker then asks for each key on its own, five at a time, and leaves out the ones answering 404. issue(key) reads one issue with description added to the fields: a Cloud document (REST v3) is flattened to plain text, Data Center wiki text is kept as is, and both are cut at JIRA_DESCRIPTION_MAX_CHARS (6000). It is undefined when Jira answers 401, 403 or 404, for a malformed key and for a project outside projects; other failures throw. Status categories new, indeterminate and done become todo, doing and done; url is <site>/browse/<key> (none through api.atlassian.com). Requests never follow redirects, and errors carry the status but never the credentials.

Cloud. Create an API token for the account Holtkeeper reads as (a bot account with Browse projects is enough) and store a credential { kind: 'jira', url: 'https://<site>.atlassian.net', secret: <token>, options: { authKind: 'basic', email } }. Data Center. Create a personal access token and store { kind: 'jira', url: <base URL>, secret: <token>, options: { authKind: 'bearer' } }. Scope the credential to the teams, folders or repositories whose tickets live in that Jira, and set options.projects to their Jira projects: anyone who may read releases of a covered repository sees the title, type and status of every ticket key its release ranges mention, and reviews of its merge requests get the description of the ticket they name.