Documentation
¶
Overview ¶
Package gojira is the public library facade for the gojira Jira-to-Markdown mirror tool. It exposes exactly four named capabilities committed in PRD §8:
- Classify — classify a URL or bare issue key.
- LoadConfig / Config — build and validate a runtime configuration.
- FetchAndRender — fetch one Jira issue and return rendered Markdown.
- Crawl / Summary — run a full recursive crawl to disk.
Public surface invariants ¶
- No flag parsing, CLI argument handling, or process-level signal handling.
- No os.Exit calls.
- No hard-coded credentials, Jira domains, or project keys.
- All internal packages are hidden; only the four capabilities and their supporting types are exported.
- The CLI binary (cmd/gojira) is a thin consumer of this package; it is never required to use the library.
Minimal usage example (third-party consumer workflow from PRD §8) ¶
cfg, err := gojira.LoadConfig(map[string]string{
"GOJIRA_SITE": "https://mycompany.atlassian.net",
"GOJIRA_USER": "me@example.com",
"GOJIRA_TOKEN": os.Getenv("JIRA_TOKEN"),
"GOJIRA_OUTPUT_DIR": "./jira-mirror",
})
if err != nil {
log.Fatal(err)
}
summary, err := gojira.Crawl(ctx, cfg, []string{"PROJ-1"}, nil)
if err != nil {
log.Fatal(err)
}
fmt.Printf("fetched=%d stubbed=%d failed=%d\n",
summary.Fetched, summary.Stubbed, summary.Failed)
Index ¶
Constants ¶
const ( KindIssueFetched = events.KindIssueFetched KindIssueStubbed = events.KindIssueStubbed KindIssueFailed = events.KindIssueFailed KindIssueCapReached = events.KindIssueCapReached KindPRReferenceFound = events.KindPRReferenceFound KindCrawlSummary = events.KindCrawlSummary )
const Version = "v0.1.0"
Version is the current library version. The authoritative release tag is set in Phase 7; this constant is declared early so callers can read it.
Variables ¶
var ( // This is a total-failure condition: credentials are invalid. ErrUnauthorized = client.ErrUnauthorized // ErrForbidden is returned when Jira responds with 403. // The crawl renders a permission-denied stub and continues. ErrForbidden = client.ErrForbidden // ErrNotFound is returned when Jira responds with 404. // The crawl renders a not-found stub and continues. ErrNotFound = client.ErrNotFound // ErrRateLimited is returned when Jira responds with 429 and all // retry attempts are exhausted. ErrRateLimited = client.ErrRateLimited )
Functions ¶
func Classify ¶
Classify determines the kind of link represented by input.
It is a direct re-export of classify.Classify. The returned classify.Result carries the Kind and any extracted fields (IssueKey, Owner, Repo, PRNumber, URL). classify is a public package; callers may import it directly for the Kind constants.
jiraSite is the Jira Cloud base URL (e.g. "https://mycompany.atlassian.net"). Only the host portion is used for matching.
func FetchAndRender ¶
func FetchAndRender(ctx context.Context, cfg Config, key string, opts ...client.Option) (indexMD, outboundMD string, discoveredKeys []string, err error)
FetchAndRender fetches a single Jira issue identified by key, parses its ADF description and relationships, and returns the rendered Markdown content for both the issue page and its outbound reference index.
It does NOT write anything to disk. The caller decides what to do with the returned strings (write them, embed them in a larger pipeline, etc.).
Parameters ¶
- ctx: controls the lifetime of the HTTP request.
- cfg: validated runtime configuration (construct via LoadConfig).
- key: Jira issue key, e.g. "PROJ-1".
- opts: optional client.Option values (e.g. client.WithHTTPClient for tests). Pass nil or omit for production use.
Return values ¶
- indexMD: Markdown content for <KEY>/index.md.
- outboundMD: Markdown content for <KEY>/references/outbound.md. Empty string when the issue has no outbound references.
- discoveredKeys: Jira issue keys found in the issue's description and relationships, in extract's documented order (description → parent → subtasks → issuelinks → remotelinks). May contain duplicates; the caller is responsible for deduplication.
- err: non-nil on fetch, parse, extract, or render failure.
Neighbour resolution ¶
Because FetchAndRender fetches a single issue in isolation, the neighbours set passed to the renderer is always empty. Relationship links therefore render as absolute Jira browse URLs rather than relative Markdown paths. Use Crawl for a full recursive crawl where relative links are resolved.
Types ¶
type Config ¶
Config is the validated runtime configuration for a gojira run. It is an alias for the internal config type; construct it via LoadConfig.
func LoadConfig ¶
LoadConfig validates the key-value pairs in kv against the canonical GOJIRA_* key set defined in PRD §6, applies defaults for optional keys, and returns a populated Config.
kv may come from any source: environment variables, CLI flags, a config file, or a test fixture. This package does not read environment variables itself.
On the first validation failure, LoadConfig returns a zero Config and a descriptive error. Use errors.Is with config.ErrMissingRequired or config.ErrInvalidValue to distinguish failure classes.
type Event ¶
Event is a single observable occurrence emitted by the library. It is an alias for the internal events.Event type.
type Sink ¶
Sink is the interface callers implement to receive structured events from the library. It is an alias for the internal events.Sink interface, so callers can implement their own sink without importing internal/events.
NoopSink discards every event. Pass it (or nil) to Crawl when you do not need to observe crawl progress.
func NewSlogSink ¶
NewSlogSink returns a Sink that emits each event as a structured slog record through logger. It is the recommended way for callers (including the gojira CLI) to bridge gojira's event stream onto the standard log/slog pipeline without importing internal/events directly.
A nil logger is replaced with slog.Default so the resulting sink is always safe to call. The Event-to-slog mapping (kind → level, attribute names) is documented on the underlying events.SlogSink.
type Summary ¶
Summary is the structured result returned by Crawl after a run completes. It is an alias for the internal crawl summary type.
func Crawl ¶
Crawl executes a full recursive Jira issue crawl starting from startKeys.
It constructs the real HTTP client and fetcher from cfg, then delegates to the internal crawl orchestrator. Output files are written to cfg.OutputDir.
sink receives structured events for every state transition (issue queued, fetched, skipped, stubbed, failed, cap reached, PR found, crawl summary). Pass nil to use NoopSink and discard all events.
Error handling ¶
- 401 Unauthorized: the crawl is aborted immediately. Crawl returns a partial Summary and an error wrapping ErrUnauthorized. Map to exit 1.
- 403 / 404: a stub index.md is written; the crawl continues.
- Rate limited (429, retries exhausted): counted in Summary.Failed.
- Network/transport error: a stub is written; the crawl continues.
- Context cancellation: in-flight fetches complete; no new fetches start.
Skip-if-exists ¶
When cfg.Refetch is false (the default), issues whose index.md already exists on disk are skipped without making an API call. This makes repeated runs additive and fast.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package classify provides pure, stateless classification of strings into one of four link kinds: a bare Jira issue key, a Jira issue URL, a GitHub pull request URL, or an unclassified external link.
|
Package classify provides pure, stateless classification of strings into one of four link kinds: a bare Jira issue key, a Jira issue URL, a GitHub pull request URL, or an unclassified external link. |
|
Package client implements the Jira Cloud HTTP transport for gojira.
|
Package client implements the Jira Cloud HTTP transport for gojira. |
|
cmd
|
|
|
gojira
command
Command gojira is the CLI binary for the gojira Jira-to-Markdown mirror tool.
|
Command gojira is the CLI binary for the gojira Jira-to-Markdown mirror tool. |
|
internal
|
|
|
adf
Package adf provides pure, stateless traversal and rendering of Atlassian Document Format (ADF) documents.
|
Package adf provides pure, stateless traversal and rendering of Atlassian Document Format (ADF) documents. |
|
config
Package config validates and constructs the runtime configuration consumed by every other gojira package.
|
Package config validates and constructs the runtime configuration consumed by every other gojira package. |
|
crawl
Package crawl is the recursive crawl orchestrator for gojira.
|
Package crawl is the recursive crawl orchestrator for gojira. |
|
devstatus
Package devstatus enriches an already-fetched Jira issue with all the development metadata Jira's Dev Status API surfaces: pull requests, branches, commits, repositories, and builds.
|
Package devstatus enriches an already-fetched Jira issue with all the development metadata Jira's Dev Status API surfaces: pull requests, branches, commits, repositories, and builds. |
|
events
Package events defines the structured event sink interface used by every gojira package to report progress, warnings, errors, and partial-success states.
|
Package events defines the structured event sink interface used by every gojira package to report progress, warnings, errors, and partial-success states. |
|
extract
Package extract discovers all outbound references from a parsed Jira issue.
|
Package extract discovers all outbound references from a parsed Jira issue. |
|
fetch
Package fetch provides a thin adapter between the crawl orchestrator and the Jira Cloud HTTP client.
|
Package fetch provides a thin adapter between the crawl orchestrator and the Jira Cloud HTTP client. |
|
hierarchy
Package hierarchy discovers Jira hierarchy children for an already-fetched issue via JQL search.
|
Package hierarchy discovers Jira hierarchy children for an already-fetched issue via JQL search. |
|
output
Package output is the filesystem writer for gojira.
|
Package output is the filesystem writer for gojira. |
|
parse
Package parse converts raw Jira Cloud REST API v3 issue JSON into a typed Issue value.
|
Package parse converts raw Jira Cloud REST API v3 issue JSON into a typed Issue value. |
|
render
Package render converts a parsed Jira issue into Markdown content.
|
Package render converts a parsed Jira issue into Markdown content. |
|
Package log is gojira's small slog-compatible logging facade.
|
Package log is gojira's small slog-compatible logging facade. |