jira

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package jira provides a client for the JIRA Cloud REST API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Board

type Board struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
	Type string `json:"type"`
}

Board represents a JIRA agile board.

type BoardConfig

type BoardConfig struct {
	Filter BoardFilter `json:"filter"`
}

BoardConfig represents a JIRA board's configuration.

type BoardFilter

type BoardFilter struct {
	ID string `json:"id"`
}

BoardFilter represents the filter reference in a board config.

type BoardListResult

type BoardListResult struct {
	PaginatedResponse
	Values []Board `json:"values"`
}

BoardListResult represents the paginated board list response.

type ChangeItem

type ChangeItem struct {
	Field      string `json:"field"`
	FieldType  string `json:"fieldtype"`
	From       string `json:"from"`
	FromString string `json:"fromString"`
	To         string `json:"to"`
	ToString   string `json:"toString"`
}

ChangeItem represents a single field change.

type Changelog

type Changelog struct {
	PaginatedResponse
	Histories []ChangelogEntry `json:"histories"`
}

Changelog represents the changelog for an issue.

type ChangelogEntry

type ChangelogEntry struct {
	ID      string       `json:"id"`
	Created JiraTime     `json:"created"`
	Author  User         `json:"author"`
	Items   []ChangeItem `json:"items"`
}

ChangelogEntry represents a single changelog entry.

type ChangelogResult

type ChangelogResult struct {
	PaginatedResponse
	Values []ChangelogEntry `json:"values"`
}

ChangelogResult represents the standalone changelog API response.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the main JIRA Cloud API client.

func NewClient

func NewClient(creds Credentials) *Client

NewClient creates a new JIRA Cloud API client.

func (*Client) BaseURL

func (c *Client) BaseURL() string

BaseURL returns the JIRA instance base URL.

func (*Client) BrowseURL

func (c *Client) BrowseURL(issueKey string) string

BrowseURL returns the URL to view an issue in the JIRA UI.

func (*Client) FetchIssuesWithHistory

func (c *Client) FetchIssuesWithHistory(ctx context.Context, jql string, progressFn func(current, total int)) ([]IssueWithHistory, error)

FetchIssuesWithHistory fetches all issues matching JQL and their changelogs. This is the main entry point for metrics calculations.

func (*Client) GetBoardConfiguration

func (c *Client) GetBoardConfiguration(ctx context.Context, boardID int) (*BoardConfig, error)

GetBoardConfiguration returns the configuration for a board, including its filter.

func (*Client) GetFilter

func (c *Client) GetFilter(ctx context.Context, filterID string) (*Filter, error)

GetFilter returns a JIRA saved filter by ID.

func (*Client) GetFullChangelog

func (c *Client) GetFullChangelog(ctx context.Context, issueKey string) ([]ChangelogEntry, error)

GetFullChangelog fetches all changelog entries for an issue, handling pagination.

func (*Client) GetIssueChangelog

func (c *Client) GetIssueChangelog(ctx context.Context, issueKey string, startAt int) (*ChangelogResult, error)

GetIssueChangelog fetches the changelog for a specific issue.

func (*Client) GetIssueWithChangelog

func (c *Client) GetIssueWithChangelog(ctx context.Context, issueKey string) (*IssueWithHistory, error)

GetIssueWithChangelog fetches an issue with its full changelog.

func (*Client) ListBoards

func (c *Client) ListBoards(ctx context.Context, projectKey string) ([]Board, error)

ListBoards returns all agile boards for the given project key. It resolves the project key to a numeric ID and uses the projectLocation parameter, which is more reliable than projectKeyOrId for finding boards.

func (*Client) SearchAllIssues

func (c *Client) SearchAllIssues(ctx context.Context, jql string, fields string, expand string) ([]Issue, error)

SearchAllIssues fetches all issues matching the JQL query, handling pagination.

func (*Client) SearchIssues

func (c *Client) SearchIssues(ctx context.Context, jql string, opts SearchOptions) (*SearchResult, error)

SearchIssues performs a JQL search with pagination.

func (*Client) TestConnection

func (c *Client) TestConnection(ctx context.Context) error

TestConnection verifies the JIRA credentials work.

func (*Client) WhoAmI

func (c *Client) WhoAmI(ctx context.Context) (*User, error)

WhoAmI returns the authenticated JIRA user. Useful for printing a "Connected as ..." line after credentials are saved.

func (*Client) WithDebug

func (c *Client) WithDebug(v bool) *Client

WithDebug toggles per-request debug logging (method, URL, status, duration).

func (*Client) WithDumpResponses

func (c *Client) WithDumpResponses(v bool) *Client

WithDumpResponses toggles full response-body dumping. Off by default; only enable on commands that explicitly opt in via --debug-upstream-response.

type Credentials

type Credentials struct {
	Domain          string // e.g., "mycompany" (becomes mycompany.atlassian.net)
	Email           string // User email
	APIToken        string // API token from id.atlassian.com/manage/api-tokens
	BaseURLOverride string // If set, use instead of https://{domain}.atlassian.net
}

Credentials holds JIRA Cloud authentication details.

func (*Credentials) BaseURL

func (c *Credentials) BaseURL() string

BaseURL returns the JIRA Cloud base URL.

type Epic

type Epic struct {
	ID   int    `json:"id"`
	Key  string `json:"key"`
	Name string `json:"name"`
}

Epic represents epic information.

type ErrorResponse

type ErrorResponse struct {
	ErrorMessages []string          `json:"errorMessages"`
	Errors        map[string]string `json:"errors"`
}

ErrorResponse represents a JIRA API error.

type Fields

type Fields struct {
	Summary        string      `json:"summary"`
	Description    any         `json:"description,omitempty"` // Can be string or ADF object
	Status         Status      `json:"status"`
	IssueType      IssueType   `json:"issuetype"`
	Created        JiraTime    `json:"created"`
	Updated        JiraTime    `json:"updated"`
	ResolutionDate *JiraTime   `json:"resolutiondate,omitempty"`
	Resolution     *Resolution `json:"resolution,omitempty"`
	Project        Project     `json:"project"`
	Assignee       *User       `json:"assignee,omitempty"`
	Reporter       *User       `json:"reporter,omitempty"`
	Priority       *Priority   `json:"priority,omitempty"`
	Labels         []string    `json:"labels,omitempty"`
	Parent         *Parent     `json:"parent,omitempty"` // For subtasks or stories linked to epics
	Epic           *Epic       `json:"epic,omitempty"`   // Epic link (older style)
}

Fields contains issue field data.

type Filter

type Filter struct {
	ID  string `json:"id"`
	JQL string `json:"jql"`
}

Filter represents a JIRA saved filter.

type Issue

type Issue struct {
	Key       string     `json:"key"`
	ID        string     `json:"id"`
	Self      string     `json:"self"`
	Fields    Fields     `json:"fields"`
	Changelog *Changelog `json:"changelog,omitempty"`
}

Issue represents a JIRA issue.

type IssueType

type IssueType struct {
	ID           string `json:"id"`
	Name         string `json:"name"`
	Subtask      bool   `json:"subtask"`
	Hierarchical int    `json:"hierarchyLevel,omitempty"`
}

IssueType represents issue type (Story, Bug, Epic, etc.).

type IssueWithHistory

type IssueWithHistory struct {
	Issue
	Transitions []StatusTransition
}

IssueWithHistory combines an issue with its parsed status transitions.

type JiraTime

type JiraTime struct {
	time.Time
}

JiraTime handles JIRA's datetime format.

func (JiraTime) MarshalJSON

func (jt JiraTime) MarshalJSON() ([]byte, error)

MarshalJSON formats time for JIRA API.

func (*JiraTime) UnmarshalJSON

func (jt *JiraTime) UnmarshalJSON(data []byte) error

UnmarshalJSON parses JIRA's datetime format.

type PaginatedResponse

type PaginatedResponse struct {
	StartAt    int  `json:"startAt"`
	MaxResults int  `json:"maxResults"`
	Total      int  `json:"total"`
	IsLast     bool `json:"isLast,omitempty"`
}

PaginatedResponse represents JIRA's standard pagination structure.

type Parent

type Parent struct {
	ID     string `json:"id"`
	Key    string `json:"key"`
	Fields struct {
		Summary   string    `json:"summary"`
		Status    Status    `json:"status"`
		IssueType IssueType `json:"issuetype"`
	} `json:"fields"`
}

Parent represents the parent issue (for subtasks or epic links).

type Priority

type Priority struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

Priority represents issue priority.

type Project

type Project struct {
	ID   string `json:"id"`
	Key  string `json:"key"`
	Name string `json:"name"`
}

Project represents a JIRA project.

type Resolution

type Resolution struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

Resolution represents the resolution set when closing an issue.

type SearchOptions

type SearchOptions struct {
	StartAt    int
	MaxResults int
	Fields     string // Comma-separated field names
	Expand     string // changelog, transitions, etc.
}

SearchOptions configures JQL search requests.

type SearchResult

type SearchResult struct {
	PaginatedResponse
	Issues []Issue `json:"issues"`
}

SearchResult represents the JQL search response.

type Status

type Status struct {
	ID             string         `json:"id"`
	Name           string         `json:"name"`
	StatusCategory StatusCategory `json:"statusCategory"`
}

Status represents issue status.

type StatusCategory

type StatusCategory struct {
	ID   int    `json:"id"`
	Key  string `json:"key"`  // new, indeterminate, done
	Name string `json:"name"` // To Do, In Progress, Done
}

StatusCategory represents the status category.

type StatusTransition

type StatusTransition struct {
	Timestamp  time.Time
	FromStatus string
	ToStatus   string
}

StatusTransition represents a status change extracted from changelog.

func ExtractStatusTransitions

func ExtractStatusTransitions(entries []ChangelogEntry) []StatusTransition

ExtractStatusTransitions parses changelog entries to find status changes.

type User

type User struct {
	AccountID    string `json:"accountId"`
	DisplayName  string `json:"displayName"`
	EmailAddress string `json:"emailAddress,omitempty"`
	Active       bool   `json:"active"`
}

User represents a JIRA user.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL