api

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package api provides HTTP clients for Atlassian Cloud APIs.

This package implements clients for:

  • Jira Cloud REST API v3
  • Jira Agile REST API v1 (for sprints/boards)
  • Confluence Cloud REST API v2 (for most operations)
  • Confluence Cloud REST API v1 (for archive, move)

All API calls use OAuth 2.0 Bearer token authentication. Tokens are automatically retrieved from the system keyring based on the configured host.

Example usage:

client, err := api.NewClientFromConfig()
if err != nil {
    return err
}
jira := api.NewJiraService(client)
issue, err := jira.GetIssue(ctx, "TEST-123")

Index

Constants

View Source
const (
	// AtlassianAPIURL is the base URL for Atlassian cloud API requests.
	// All Atlassian Cloud REST APIs are accessed through this gateway.
	AtlassianAPIURL = "https://api.atlassian.com"

	// DefaultTimeout is the default HTTP client timeout for API requests.
	DefaultTimeout = 30 * time.Second
)
View Source
const (
	// ConfluenceMaxLimit is the maximum allowed limit for Confluence API pagination.
	// The API returns 400 if you exceed this.
	ConfluenceMaxLimit = 250
)

Variables

This section is empty.

Functions

func ADFToText

func ADFToText(ourADF *ADF) string

ADFToText converts Atlassian Document Format to Markdown text. Uses the jira-cli adf library for proper Markdown formatting.

func BuildQueryString

func BuildQueryString(params map[string]string) string

BuildQueryString builds a URL query string from parameters.

func FormatCustomFieldValue added in v1.1.0

func FormatCustomFieldValue(raw json.RawMessage) string

FormatCustomFieldValue extracts a human-readable string from a raw JSON custom field value. Handles common Jira field value shapes: select/radio, user, ADF, arrays, strings, numbers, null.

func JoinPath

func JoinPath(base string, paths ...string) string

JoinPath joins path segments properly.

Types

type ADF

type ADF struct {
	Type    string       `json:"type"`
	Version int          `json:"version,omitempty"`
	Content []ADFContent `json:"content,omitempty"`
	Text    string       `json:"text,omitempty"`
	Attrs   *ADFAttrs    `json:"attrs,omitempty"`
	Marks   []ADFMark    `json:"marks,omitempty"`
}

ADF represents Atlassian Document Format content.

func MarkdownToADF

func MarkdownToADF(text string) *ADF

MarkdownToADF converts markdown text to Atlassian Document Format. Supports:

  • Headings: # h1, ## h2, etc.
  • Bold: **text** or __text__
  • Italic: *text* or _text_
  • Strikethrough: ~~text~~
  • Inline code: `code`
  • Code blocks: ```language\ncode\n```
  • Links: [text](url)
  • Bullet lists: - item or * item
  • Numbered lists: 1. item
  • Blockquotes: > text
  • Horizontal rules: --- or *** or ___
  • Tables: | col | col | (GFM-style)
  • Panels: :::info, :::warning, :::error, :::note, :::success
  • Expand: +++Title\ncontent\n+++
  • Media: !media[id] or !media[collection:id]

func TextToADF

func TextToADF(text string) *ADF

TextToADF converts plain text or markdown to Atlassian Document Format. Supports markdown syntax including: headings (#), bold (**), italic (*), inline code (`), code blocks (```), links, bullet lists (-/*), ordered lists, blockquotes (>), and horizontal rules (---).

type ADFAttrs

type ADFAttrs struct {
	Level    int    `json:"level,omitempty"`
	URL      string `json:"url,omitempty"`
	Href     string `json:"href,omitempty"`
	Language string `json:"language,omitempty"`
	// Media attributes
	ID         string `json:"id,omitempty"`
	Type       string `json:"type,omitempty"`
	Collection string `json:"collection,omitempty"`
	Alt        string `json:"alt,omitempty"`
	Width      int    `json:"width,omitempty"`
	Height     int    `json:"height,omitempty"`
	// Panel attributes
	PanelType string `json:"panelType,omitempty"`
	// Expand attributes
	Title string `json:"title,omitempty"`
	// Table attributes
	Layout string `json:"layout,omitempty"`
	// Table cell attributes
	Colspan  int   `json:"colspan,omitempty"`
	Rowspan  int   `json:"rowspan,omitempty"`
	Colwidth []int `json:"colwidth,omitempty"`
}

ADFAttrs represents attributes in ADF.

type ADFContent

type ADFContent struct {
	Type    string       `json:"type"`
	Content []ADFContent `json:"content,omitempty"`
	Text    string       `json:"text,omitempty"`
	Attrs   *ADFAttrs    `json:"attrs,omitempty"`
	Marks   []ADFMark    `json:"marks,omitempty"`
}

ADFContent represents content within an ADF document.

type ADFMark

type ADFMark struct {
	Type  string    `json:"type"`
	Attrs *ADFAttrs `json:"attrs,omitempty"`
}

ADFMark represents text marks in ADF.

type APIError

type APIError struct {
	StatusCode int
	Status     string
	Body       string
}

APIError represents an error response from the API.

func (*APIError) Error

func (e *APIError) Error() string

type AccessibleResource

type AccessibleResource struct {
	ID        string   `json:"id"`
	URL       string   `json:"url"`
	Name      string   `json:"name"`
	Scopes    []string `json:"scopes"`
	AvatarURL string   `json:"avatarUrl,omitempty"`
}

AccessibleResource represents an accessible Atlassian cloud resource.

func GetAccessibleResources

func GetAccessibleResources(ctx context.Context, accessToken string) ([]*AccessibleResource, error)

GetAccessibleResources fetches the list of accessible Atlassian resources. This is needed to get the cloud ID for a site.

type AccountID

type AccountID struct {
	AccountID string `json:"accountId"`
}

AccountID is used when setting assignee.

type AddCommentRequest

type AddCommentRequest struct {
	Body       *ADF               `json:"body"`
	Visibility *CommentVisibility `json:"visibility,omitempty"`
}

AddCommentRequest represents a request to add a comment.

type Attachment

type Attachment struct {
	ID       string `json:"id"`
	Filename string `json:"filename"`
	Author   *User  `json:"author,omitempty"`
	Created  string `json:"created"`
	Size     int64  `json:"size"`
	MimeType string `json:"mimeType"`
	Content  string `json:"content"` // URL to download the attachment
}

Attachment represents an attachment on an issue.

type Board

type Board struct {
	ID       int            `json:"id"`
	Name     string         `json:"name"`
	Type     string         `json:"type"` // scrum, kanban
	Location *BoardLocation `json:"location,omitempty"`
}

Board represents a Jira board.

type BoardLocation

type BoardLocation struct {
	ProjectID  int    `json:"projectId"`
	ProjectKey string `json:"projectKey"`
	Name       string `json:"displayName"`
}

BoardLocation represents the location of a board.

type BoardsResponse

type BoardsResponse struct {
	MaxResults int      `json:"maxResults"`
	StartAt    int      `json:"startAt"`
	IsLast     bool     `json:"isLast"`
	Values     []*Board `json:"values"`
}

BoardsResponse represents a paginated list of boards.

type BodyContent

type BodyContent struct {
	Value          string `json:"value"`
	Representation string `json:"representation"`
}

BodyContent represents body content in a specific format.

type ChangelogEntry

type ChangelogEntry struct {
	ID      string           `json:"id"`
	Author  *User            `json:"author,omitempty"`
	Created string           `json:"created"`
	Items   []*ChangelogItem `json:"items"`
}

ChangelogEntry represents a single changelog entry for an issue.

type ChangelogItem

type ChangelogItem struct {
	Field      string `json:"field"`
	FieldType  string `json:"fieldtype"`
	FieldID    string `json:"fieldId,omitempty"`
	From       string `json:"from,omitempty"`
	To         string `json:"to,omitempty"`
	FromString string `json:"fromString,omitempty"`
	ToString   string `json:"toString,omitempty"`
}

ChangelogItem represents a single field change within a changelog entry.

type ChangelogResponse

type ChangelogResponse struct {
	StartAt    int               `json:"startAt"`
	MaxResults int               `json:"maxResults"`
	Total      int               `json:"total"`
	IsLast     bool              `json:"isLast"`
	Values     []*ChangelogEntry `json:"values"`
}

ChangelogResponse represents a paginated list of changelog entries.

type ChildrenResponse

type ChildrenResponse struct {
	Results []*PageChild     `json:"results"`
	Links   *PaginationLinks `json:"_links,omitempty"`
}

ChildrenResponse represents a paginated list of child pages.

type Client

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

Client is an HTTP client for Atlassian APIs.

func NewClient

func NewClient(hostname string, opts ...ClientOption) (*Client, error)

NewClient creates a new API client for the given hostname.

func NewClientFromConfig

func NewClientFromConfig() (*Client, error)

NewClientFromConfig creates a new API client using the current host from config.

func (*Client) AgileBaseURL

func (c *Client) AgileBaseURL() string

AgileBaseURL returns the base URL for Jira Agile (Software) API requests.

func (*Client) CloudID

func (c *Client) CloudID() string

CloudID returns the cloud ID for the host.

func (*Client) ConfluenceBaseURL

func (c *Client) ConfluenceBaseURL() string

ConfluenceBaseURL returns the base URL for Confluence API requests. Defaults to v2 API which is used for most operations.

func (*Client) ConfluenceBaseURLV1

func (c *Client) ConfluenceBaseURLV1() string

ConfluenceBaseURLV1 returns the v1 API URL for Confluence. Used for endpoints that don't exist in v2 (archive, move).

func (*Client) ConfluenceBaseURLV2

func (c *Client) ConfluenceBaseURLV2() string

ConfluenceBaseURLV2 returns the v2 API URL for Confluence.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, path string) error

Delete makes a DELETE request.

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string, result interface{}) error

Get makes a GET request.

func (*Client) GetRaw

func (c *Client) GetRaw(ctx context.Context, path string) ([]byte, string, error)

GetRaw makes a GET request and returns raw bytes (for file downloads). Returns the content, content-type, and any error.

func (*Client) Hostname

func (c *Client) Hostname() string

Hostname returns the configured hostname.

func (*Client) JiraBaseURL

func (c *Client) JiraBaseURL() string

BaseURL returns the base URL for Jira API requests.

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, body interface{}, result interface{}) error

Post makes a POST request.

func (*Client) PostMultipart

func (c *Client) PostMultipart(ctx context.Context, urlPath, fieldName, filePath string, result interface{}) error

PostMultipart makes a multipart/form-data POST request for file uploads. The file at filePath is sent as the form field specified by fieldName.

func (*Client) Put

func (c *Client) Put(ctx context.Context, path string, body interface{}, result interface{}) error

Put makes a PUT request.

func (*Client) Request

func (c *Client) Request(ctx context.Context, method, path string, body interface{}, result interface{}) error

Request makes an HTTP request to the API. If the access token is expired, it will automatically attempt to refresh it. Automatically retries on transient failures (429, 5xx) with exponential backoff.

type ClientOption

type ClientOption func(*Client)

ClientOption configures the API client.

func WithTimeout

func WithTimeout(timeout time.Duration) ClientOption

WithTimeout sets the HTTP client timeout.

type Comment

type Comment struct {
	ID      string `json:"id"`
	Author  *User  `json:"author,omitempty"`
	Body    *ADF   `json:"body,omitempty"`
	Created string `json:"created,omitempty"`
	Updated string `json:"updated,omitempty"`
}

Comment represents a Jira comment.

type CommentOptions

type CommentOptions struct {
	Body           string
	VisibilityType string // "role" or "group"
	VisibilityName string // role name or group name
}

CommentOptions contains options for adding/editing comments.

type CommentVisibility

type CommentVisibility struct {
	Type       string `json:"type"`                 // "role" or "group"
	Value      string `json:"value"`                // role name or group name
	Identifier string `json:"identifier,omitempty"` // group ID (for group type)
}

CommentVisibility represents visibility restrictions for a comment.

type Comments

type Comments struct {
	Comments   []*Comment `json:"comments"`
	MaxResults int        `json:"maxResults"`
	Total      int        `json:"total"`
	StartAt    int        `json:"startAt"`
}

Comments represents the comment field on an issue.

type Component

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

Component represents a project component.

type ConfluenceSearchResponse

type ConfluenceSearchResponse struct {
	Results []*ConfluenceSearchResult `json:"results"`
}

ConfluenceSearchResponse represents a paginated search response.

type ConfluenceSearchResponseV1

type ConfluenceSearchResponseV1 struct {
	Results []*ConfluenceSearchResultV1 `json:"results"`
	Links   *PaginationLinks            `json:"_links,omitempty"`
	Start   int                         `json:"start"`
	Limit   int                         `json:"limit"`
	Size    int                         `json:"size"`
}

ConfluenceSearchResponseV1 represents the v1 search response.

type ConfluenceSearchResult

type ConfluenceSearchResult struct {
	ID       string `json:"id"`
	Type     string `json:"type"`
	Status   string `json:"status"`
	Title    string `json:"title"`
	SpaceKey string `json:"spaceKey,omitempty"`
	Excerpt  string `json:"excerpt,omitempty"`
}

ConfluenceSearchResult represents a normalized search result.

type ConfluenceSearchResultV1

type ConfluenceSearchResultV1 struct {
	Content struct {
		ID     string `json:"id"`
		Type   string `json:"type"`
		Status string `json:"status"`
		Title  string `json:"title"`
		Space  *struct {
			Key string `json:"key"`
		} `json:"space,omitempty"`
	} `json:"content"`
	Excerpt string `json:"excerpt,omitempty"`
	URL     string `json:"url,omitempty"`
}

ConfluenceSearchResultV1 represents a search result from v1 CQL search. The v1 API wraps content in a "content" field.

type ConfluenceService

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

ConfluenceService handles Confluence API operations.

API Version Strategy

This service uses a mix of Confluence REST API v1 and v2:

  • v2 API (/wiki/api/v2): Used for most operations (pages, spaces, children). Better performance, cleaner response format, and actively developed.

  • v1 API (/wiki/rest/api): Required for operations not yet in v2:

  • Search (CQL): No v2 equivalent exists (as of Dec 2024)

  • Archive/Unarchive: Only available in v1

  • Move page: Only available in v1

When Atlassian adds these endpoints to v2, we should migrate. Track progress: https://developer.atlassian.com/cloud/confluence/rest/v2/intro/

Required OAuth Scopes

Classic scopes (for v1 operations):

  • read:confluence-content.all
  • write:confluence-content
  • search:confluence (required for CQL search)

Granular scopes (for v2 operations):

  • read:page:confluence, write:page:confluence
  • read:space:confluence
  • read:content:confluence, write:content:confluence

func NewConfluenceService

func NewConfluenceService(client *Client) *ConfluenceService

NewConfluenceService creates a new Confluence service.

func (*ConfluenceService) ArchivePage

func (s *ConfluenceService) ArchivePage(ctx context.Context, pageID string) error

ArchivePage archives a page using the v1 API. Note: Archive endpoint only exists in v1 API.

func (*ConfluenceService) ArchivePages

func (s *ConfluenceService) ArchivePages(ctx context.Context, pageIDs []string) error

ArchivePages archives multiple pages using the v1 API.

func (*ConfluenceService) CreatePage

func (s *ConfluenceService) CreatePage(ctx context.Context, spaceID, title, content string, parentID string, status string) (*Page, error)

CreatePage creates a new page. status can be "current" or "draft". Empty defaults to "current".

func (*ConfluenceService) CreateTemplate

func (s *ConfluenceService) CreateTemplate(ctx context.Context, name, body, description, spaceKey string) (*Template, error)

CreateTemplate creates a new content template. If spaceKey is empty, creates a global template (requires Confluence Administrator permission). If spaceKey is provided, creates a space template (requires Space Admin permission). Uses v1 API as templates are not available in v2.

func (*ConfluenceService) DeleteContent

func (s *ConfluenceService) DeleteContent(ctx context.Context, id string, contentType string) error

DeleteContent deletes a page or folder. contentType can be "page", "folder", or empty (auto-detects by trying page then folder). Note: v1 /content/{id} DELETE is deprecated (410 Gone), so we only use v2 endpoints.

func (*ConfluenceService) GetPage

func (s *ConfluenceService) GetPage(ctx context.Context, pageID string) (*Page, error)

GetPage gets a page by ID. Requests both storage and atlas_doc_format to handle both old and new editor pages.

func (*ConfluenceService) GetPageChildren

func (s *ConfluenceService) GetPageChildren(ctx context.Context, pageID string, limit int, cursor string) (*ChildrenResponse, error)

GetPageChildren gets immediate children of a page.

func (*ConfluenceService) GetPageDescendants

func (s *ConfluenceService) GetPageDescendants(ctx context.Context, pageID string, limit int, cursor string) (*ChildrenResponse, error)

GetPageDescendants gets all descendants of a page (children, grandchildren, etc.).

func (*ConfluenceService) GetPageDescendantsAll

func (s *ConfluenceService) GetPageDescendantsAll(ctx context.Context, pageID string) ([]*PageChild, error)

GetPageDescendantsAll gets all descendants by following pagination.

func (*ConfluenceService) GetPages

func (s *ConfluenceService) GetPages(ctx context.Context, spaceID string, limit int, cursor string, status string) (*PagesResponse, error)

GetPages gets pages in a space. status can be: "current", "draft", "archived", or empty for current.

func (*ConfluenceService) GetPagesAll

func (s *ConfluenceService) GetPagesAll(ctx context.Context, spaceID string, status string) ([]*Page, error)

GetPagesAll gets all pages in a space. status can be "current", "draft", "archived", or empty for current.

func (*ConfluenceService) GetSpace

func (s *ConfluenceService) GetSpace(ctx context.Context, spaceID string) (*Space, error)

GetSpace gets a space by ID.

func (*ConfluenceService) GetSpaceByKey

func (s *ConfluenceService) GetSpaceByKey(ctx context.Context, key string) (*Space, error)

GetSpaceByKey gets a space by its key.

func (*ConfluenceService) GetSpaces

func (s *ConfluenceService) GetSpaces(ctx context.Context, limit int, cursor string) (*SpacesResponse, error)

GetSpaces gets a list of spaces.

func (*ConfluenceService) GetSpacesAll

func (s *ConfluenceService) GetSpacesAll(ctx context.Context) ([]*Space, error)

GetSpacesAll gets all spaces by following pagination.

func (*ConfluenceService) GetTemplate

func (s *ConfluenceService) GetTemplate(ctx context.Context, templateID string) (*Template, error)

GetTemplate gets a template by ID. Uses v1 API as templates are not available in v2.

func (*ConfluenceService) MovePage

func (s *ConfluenceService) MovePage(ctx context.Context, pageID string, position MovePosition, targetID string) error

MovePage moves a page to a new location. position can be: "before", "after", or "append" - "before": move page under same parent as target, before target in list - "after": move page under same parent as target, after target in list - "append": move page to be a child of the target Note: Uses v1 API as this endpoint doesn't exist in v2.

func (*ConfluenceService) MovePageToSpace

func (s *ConfluenceService) MovePageToSpace(ctx context.Context, pageID string, spaceKey string) error

MovePageToSpace moves a page to a different space (makes it a root page in that space). spaceKey is the key of the destination space.

func (*ConfluenceService) PublishPage

func (s *ConfluenceService) PublishPage(ctx context.Context, pageID string) (*Page, error)

PublishPage publishes a draft page by changing its status to current.

func (*ConfluenceService) SearchByTitle

func (s *ConfluenceService) SearchByTitle(ctx context.Context, title string, spaceKey string, limit int) (*ConfluenceSearchResponse, error)

SearchByTitle searches for pages by title using CQL contains match.

func (*ConfluenceService) SearchPages

func (s *ConfluenceService) SearchPages(ctx context.Context, query string, limit int) (*PagesResponse, error)

SearchPages searches for pages by title (exact match).

func (*ConfluenceService) SearchWithCQL

func (s *ConfluenceService) SearchWithCQL(ctx context.Context, cql string, limit int, cursor string) (*ConfluenceSearchResponse, error)

SearchWithCQL searches for content using CQL (Confluence Query Language).

Example CQL queries:

  • "title ~ 'keyword'" - search by title
  • "space = 'SPACEKEY' AND title ~ 'keyword'" - search in specific space
  • "type = page AND text ~ 'content'" - full-text search

Uses v1 API because search endpoint doesn't exist in v2 (as of Dec 2024). Requires OAuth scope: search:confluence (classic scope).

func (*ConfluenceService) UnarchivePage

func (s *ConfluenceService) UnarchivePage(ctx context.Context, pageID string) error

UnarchivePage restores an archived page. NOTE: Confluence Cloud has no REST API for unarchiving pages. The v1 workaround using PUT /content/{id} was deprecated (410 Gone). Users must restore archived pages via the Confluence web UI. Feature request: https://jira.atlassian.com/browse/CONFCLOUD-75065

func (*ConfluenceService) UpdatePage

func (s *ConfluenceService) UpdatePage(ctx context.Context, pageID, title, content string, version int, message string) (*Page, error)

UpdatePage updates an existing page.

func (*ConfluenceService) UpdateTemplate

func (s *ConfluenceService) UpdateTemplate(ctx context.Context, templateID, name, body, description string) (*Template, error)

UpdateTemplate updates an existing content template. Uses v1 API as templates are not available in v2.

type CreateIssueFields

type CreateIssueFields struct {
	Project      *ProjectID             `json:"project"`
	Summary      string                 `json:"summary"`
	Description  *ADF                   `json:"description,omitempty"`
	IssueType    *IssueTypeID           `json:"issuetype"`
	Assignee     *AccountID             `json:"assignee,omitempty"`
	Priority     *PriorityID            `json:"priority,omitempty"`
	Labels       []string               `json:"labels,omitempty"`
	Parent       *ParentID              `json:"parent,omitempty"`
	CustomFields map[string]interface{} `json:"-"` // Merged during marshaling
}

CreateIssueFields contains fields for creating an issue.

type CreateIssueLinkRequest

type CreateIssueLinkRequest struct {
	Type         *IssueLinkTypeID `json:"type"`
	InwardIssue  *IssueKeyID      `json:"inwardIssue"`
	OutwardIssue *IssueKeyID      `json:"outwardIssue"`
}

CreateIssueLinkRequest represents a request to create an issue link.

type CreateIssueRequest

type CreateIssueRequest struct {
	Fields CreateIssueFields `json:"fields"`
}

CreateIssueRequest represents a request to create an issue.

func (*CreateIssueRequest) MarshalJSON

func (r *CreateIssueRequest) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling to include custom fields.

type CreateIssueResponse

type CreateIssueResponse struct {
	ID   string `json:"id"`
	Key  string `json:"key"`
	Self string `json:"self"`
}

CreateIssueResponse represents the response from creating an issue.

type CreatePageRequest

type CreatePageRequest struct {
	SpaceID  string `json:"spaceId"`
	Title    string `json:"title"`
	ParentID string `json:"parentId,omitempty"`
	Status   string `json:"status,omitempty"`
	Body     struct {
		Representation string `json:"representation"`
		Value          string `json:"value"`
	} `json:"body"`
}

CreatePageRequest represents a request to create a page.

type CreateRemoteLinkRequest

type CreateRemoteLinkRequest struct {
	GlobalID     string            `json:"globalId,omitempty"`
	Application  *RemoteLinkApp    `json:"application,omitempty"`
	Relationship string            `json:"relationship,omitempty"`
	Object       *RemoteLinkObject `json:"object"`
}

CreateRemoteLinkRequest represents a request to create a remote link.

type CreateTemplateRequest

type CreateTemplateRequest struct {
	Name         string `json:"name"`
	TemplateType string `json:"templateType"` // "page"
	Description  string `json:"description,omitempty"`
	Body         struct {
		Storage struct {
			Value          string `json:"value"`
			Representation string `json:"representation"`
		} `json:"storage"`
	} `json:"body"`
	Space *struct {
		Key string `json:"key"`
	} `json:"space,omitempty"`
}

CreateTemplateRequest represents a request to create a template.

type Field

type Field struct {
	ID          string       `json:"id"`
	Key         string       `json:"key"`
	Name        string       `json:"name"`
	Custom      bool         `json:"custom"`
	Orderable   bool         `json:"orderable"`
	Navigable   bool         `json:"navigable"`
	Searchable  bool         `json:"searchable"`
	Schema      *FieldSchema `json:"schema,omitempty"`
	ClauseNames []string     `json:"clauseNames,omitempty"`
}

Field represents a Jira field definition.

type FieldMeta added in v1.1.0

type FieldMeta struct {
	Required      bool              `json:"required"`
	Schema        *FieldSchema      `json:"schema,omitempty"`
	Name          string            `json:"name"`
	Key           string            `json:"key"`
	FieldID       string            `json:"fieldId"`
	AllowedValues []json.RawMessage `json:"allowedValues,omitempty"`
}

FieldMeta represents metadata for a field from the createmeta endpoint.

type FieldMetaResponse added in v1.1.0

type FieldMetaResponse struct {
	MaxResults int          `json:"maxResults"`
	StartAt    int          `json:"startAt"`
	Total      int          `json:"total"`
	Values     []*FieldMeta `json:"values"`
}

FieldMetaResponse is the paginated response from the createmeta field endpoint.

type FieldSchema

type FieldSchema struct {
	Type     string `json:"type"`
	System   string `json:"system,omitempty"`
	Custom   string `json:"custom,omitempty"`
	CustomID int    `json:"customId,omitempty"`
}

FieldSchema describes the type of a field.

type Issue

type Issue struct {
	ID     string      `json:"id"`
	Key    string      `json:"key"`
	Self   string      `json:"self"`
	Fields IssueFields `json:"fields"`
}

Issue represents a Jira issue.

type IssueFields

type IssueFields struct {
	Summary     string        `json:"summary"`
	Description *ADF          `json:"description,omitempty"`
	Status      *Status       `json:"status,omitempty"`
	Priority    *Priority     `json:"priority,omitempty"`
	IssueType   *IssueType    `json:"issuetype,omitempty"`
	Assignee    *User         `json:"assignee,omitempty"`
	Reporter    *User         `json:"reporter,omitempty"`
	Project     *Project      `json:"project,omitempty"`
	Labels      []string      `json:"labels,omitempty"`
	Created     string        `json:"created,omitempty"`
	Updated     string        `json:"updated,omitempty"`
	Resolution  *Resolution   `json:"resolution,omitempty"`
	Components  []*Component  `json:"components,omitempty"`
	Comment     *Comments     `json:"comment,omitempty"`
	Parent      *Issue        `json:"parent,omitempty"`
	Attachment  []*Attachment `json:"attachment,omitempty"`

	// Extra holds custom field values not captured by the typed fields above.
	// Keys are field IDs like "customfield_10413", values are raw JSON.
	Extra map[string]json.RawMessage `json:"-"`
}

IssueFields contains the fields of a Jira issue.

func (*IssueFields) UnmarshalJSON added in v1.1.0

func (f *IssueFields) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom unmarshaling to capture both standard and custom fields. Standard fields are decoded into typed struct fields, while custom fields (customfield_*) are preserved as raw JSON in Extra.

type IssueKeyID

type IssueKeyID struct {
	Key string `json:"key"`
}

IssueKeyID identifies an issue by key.

type IssueLinkType

type IssueLinkType struct {
	ID      string `json:"id"`
	Name    string `json:"name"`
	Inward  string `json:"inward"`
	Outward string `json:"outward"`
}

IssueLinkType represents a type of issue link.

type IssueLinkTypeID

type IssueLinkTypeID struct {
	Name string `json:"name"`
}

IssueLinkTypeID identifies a link type by name.

type IssueLinkTypesResponse

type IssueLinkTypesResponse struct {
	IssueLinkTypes []*IssueLinkType `json:"issueLinkTypes"`
}

IssueLinkTypesResponse represents the response from getting link types.

type IssueType

type IssueType struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Subtask     bool   `json:"subtask"`
}

IssueType represents an issue type.

type IssueTypeID

type IssueTypeID struct {
	Name string `json:"name"`
}

IssueTypeID is used when creating issues.

type JiraService

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

JiraService handles Jira API operations.

func NewJiraService

func NewJiraService(client *Client) *JiraService

NewJiraService creates a new Jira service.

func (*JiraService) AddComment

func (s *JiraService) AddComment(ctx context.Context, key string, body string) (*Comment, error)

AddComment adds a comment to an issue.

func (*JiraService) AddCommentWithOptions

func (s *JiraService) AddCommentWithOptions(ctx context.Context, key string, opts *CommentOptions) (*Comment, error)

AddCommentWithOptions adds a comment with optional visibility restrictions.

func (*JiraService) AssignIssue

func (s *JiraService) AssignIssue(ctx context.Context, key string, accountID string) error

AssignIssue assigns an issue to a user.

func (*JiraService) CreateIssue

CreateIssue creates a new issue.

func (s *JiraService) CreateIssueLink(ctx context.Context, inwardKey, outwardKey, linkTypeName string) error

CreateIssueLink creates a link between two issues.

func (s *JiraService) CreateRemoteLink(ctx context.Context, issueKey, url, title, summary string) (*RemoteLink, error)

CreateRemoteLink creates a remote/web link on an issue.

func (*JiraService) DeleteComment

func (s *JiraService) DeleteComment(ctx context.Context, key string, commentID string) error

DeleteComment deletes a comment.

func (s *JiraService) DeleteRemoteLink(ctx context.Context, issueKey string, linkID int) error

DeleteRemoteLink deletes a remote/web link from an issue.

func (*JiraService) DownloadAttachment

func (s *JiraService) DownloadAttachment(ctx context.Context, attachmentID string) ([]byte, string, error)

DownloadAttachment downloads an attachment and returns its content.

func (*JiraService) FlagIssue

func (s *JiraService) FlagIssue(ctx context.Context, issueKey string) error

FlagIssue flags an issue (adds the Impediment flag).

func (*JiraService) GetAttachment

func (s *JiraService) GetAttachment(ctx context.Context, attachmentID string) (*Attachment, error)

GetAttachment gets attachment metadata by ID.

func (*JiraService) GetBoardIssues

func (s *JiraService) GetBoardIssues(ctx context.Context, boardID int, maxResults int) ([]*Issue, error)

GetBoardIssues gets issues on a board.

func (*JiraService) GetBoards

func (s *JiraService) GetBoards(ctx context.Context, projectKey string) ([]*Board, error)

GetBoards gets all boards, optionally filtered by project.

func (*JiraService) GetChangelog

func (s *JiraService) GetChangelog(ctx context.Context, issueKey string, startAt int) (*ChangelogResponse, error)

GetChangelog fetches the changelog for an issue. Use startAt for pagination (0-indexed). Returns up to 100 entries per call.

func (*JiraService) GetComment

func (s *JiraService) GetComment(ctx context.Context, key string, commentID string) (*Comment, error)

GetComment gets a single comment by ID.

func (*JiraService) GetComments

func (s *JiraService) GetComments(ctx context.Context, key string) ([]*Comment, error)

GetComments gets comments for an issue.

func (*JiraService) GetFieldByID

func (s *JiraService) GetFieldByID(ctx context.Context, id string) (*Field, error)

GetFieldByID finds a field by its ID (e.g., "customfield_10016") and returns it. Returns nil if not found.

func (*JiraService) GetFieldByName

func (s *JiraService) GetFieldByName(ctx context.Context, name string) (*Field, error)

GetFieldByName finds a field by name and returns it. Returns nil if not found.

func (*JiraService) GetFieldOptions added in v1.1.0

func (s *JiraService) GetFieldOptions(ctx context.Context, projectKey, issueTypeID string) ([]*FieldMeta, error)

GetFieldOptions gets field metadata (including allowed values) for a project/issue type. Uses the createmeta endpoint: /issue/createmeta/{projectKey}/issuetypes/{issueTypeId}

func (*JiraService) GetFields

func (s *JiraService) GetFields(ctx context.Context) ([]*Field, error)

GetFields gets all field definitions.

func (*JiraService) GetFlaggedField

func (s *JiraService) GetFlaggedField(ctx context.Context) (*Field, error)

GetFlaggedField finds the "Flagged" custom field. Returns the field or nil if not found.

func (*JiraService) GetIssue

func (s *JiraService) GetIssue(ctx context.Context, key string) (*Issue, error)

GetIssue fetches a single issue by key.

func (*JiraService) GetIssueLinkTypes

func (s *JiraService) GetIssueLinkTypes(ctx context.Context) ([]*IssueLinkType, error)

GetIssueLinkTypes gets all available issue link types.

func (*JiraService) GetMyself

func (s *JiraService) GetMyself(ctx context.Context) (*User, error)

GetMyself gets the current user.

func (*JiraService) GetPriorities

func (s *JiraService) GetPriorities(ctx context.Context) ([]*Priority, error)

GetPriorities gets all available priorities in the Jira instance.

func (*JiraService) GetProjectIssueTypes

func (s *JiraService) GetProjectIssueTypes(ctx context.Context, projectKey string) ([]*ProjectIssueType, error)

GetProjectIssueTypes gets the available issue types for a project.

func (s *JiraService) GetRemoteLinks(ctx context.Context, issueKey string) ([]*RemoteLink, error)

GetRemoteLinks gets all remote/web links for an issue.

func (*JiraService) GetSprints

func (s *JiraService) GetSprints(ctx context.Context, boardID int, state string) ([]*Sprint, error)

GetSprints gets sprints for a board.

func (*JiraService) GetSubtaskType

func (s *JiraService) GetSubtaskType(ctx context.Context, projectKey string) (*ProjectIssueType, error)

GetSubtaskType finds the subtask issue type for a project. Returns the first issue type where subtask=true.

func (*JiraService) GetTransitions

func (s *JiraService) GetTransitions(ctx context.Context, key string) ([]*Transition, error)

GetTransitions gets available transitions for an issue.

func (*JiraService) IsIssueFlagged

func (s *JiraService) IsIssueFlagged(ctx context.Context, issueKey string) (bool, error)

IsIssueFlagged checks if an issue is flagged.

func (*JiraService) MoveIssuesToSprint

func (s *JiraService) MoveIssuesToSprint(ctx context.Context, sprintID int, issueKeys []string) error

MoveIssuesToSprint moves issues to a sprint.

func (*JiraService) RankIssuesAfter

func (s *JiraService) RankIssuesAfter(ctx context.Context, issueKeys []string, rankAfterIssue string) error

RankIssuesAfter ranks issues after a target issue. The issues will be placed directly after rankAfterIssue in the backlog/board order.

func (*JiraService) RankIssuesBefore

func (s *JiraService) RankIssuesBefore(ctx context.Context, issueKeys []string, rankBeforeIssue string) error

RankIssuesBefore ranks issues before a target issue. The issues will be placed directly before rankBeforeIssue in the backlog/board order.

func (*JiraService) RankIssuesToTop

func (s *JiraService) RankIssuesToTop(ctx context.Context, issueKeys []string, boardID int) error

RankIssuesToTop ranks issues to the top of the backlog.

func (*JiraService) RemoveIssuesFromSprint

func (s *JiraService) RemoveIssuesFromSprint(ctx context.Context, issueKeys []string) error

RemoveIssuesFromSprint moves issues to the backlog (removes from sprint).

func (*JiraService) Search

func (s *JiraService) Search(ctx context.Context, opts SearchOptions) (*SearchResult, error)

Search searches for issues using JQL. Uses the new /search/jql endpoint which replaces the deprecated /search endpoint.

func (*JiraService) SearchUsers

func (s *JiraService) SearchUsers(ctx context.Context, query string) ([]*User, error)

SearchUsers searches for users.

func (*JiraService) TransitionIssue

func (s *JiraService) TransitionIssue(ctx context.Context, key string, transitionID string, fields map[string]interface{}) error

TransitionIssue transitions an issue to a new status. Optional fields can be set during the transition.

func (*JiraService) UnflagIssue

func (s *JiraService) UnflagIssue(ctx context.Context, issueKey string) error

UnflagIssue removes the flag from an issue.

func (*JiraService) UpdateComment

func (s *JiraService) UpdateComment(ctx context.Context, key string, commentID string, opts *CommentOptions) (*Comment, error)

UpdateComment updates an existing comment.

func (*JiraService) UpdateIssue

func (s *JiraService) UpdateIssue(ctx context.Context, key string, req *UpdateIssueRequest) error

UpdateIssue updates an existing issue.

func (*JiraService) UploadAttachment

func (s *JiraService) UploadAttachment(ctx context.Context, issueKey, filePath string) ([]*Attachment, error)

UploadAttachment uploads a file as an attachment to an issue. Returns the list of created attachments (Jira returns an array).

type Label

type Label struct {
	Name   string `json:"name"`
	Prefix string `json:"prefix,omitempty"`
}

Label represents a label on content.

type MovePosition

type MovePosition string

MovePosition represents the position for moving a page.

const (
	// MovePositionBefore moves the page before the target (same parent as target).
	MovePositionBefore MovePosition = "before"
	// MovePositionAfter moves the page after the target (same parent as target).
	MovePositionAfter MovePosition = "after"
	// MovePositionAppend moves the page to be a child of the target.
	MovePositionAppend MovePosition = "append"
)

type Page

type Page struct {
	ID        string       `json:"id"`
	Title     string       `json:"title"`
	SpaceID   string       `json:"spaceId,omitempty"`
	Status    string       `json:"status"`
	ParentID  string       `json:"parentId,omitempty"`
	AuthorID  string       `json:"authorId,omitempty"`
	CreatedAt string       `json:"createdAt,omitempty"`
	Version   *PageVersion `json:"version,omitempty"`
	Body      *PageBody    `json:"body,omitempty"`
	Links     *PageLinks   `json:"_links,omitempty"`
}

Page represents a Confluence page.

type PageBody

type PageBody struct {
	Storage        *BodyContent `json:"storage,omitempty"`
	AtlasDocFormat *BodyContent `json:"atlas_doc_format,omitempty"`
	View           *BodyContent `json:"view,omitempty"`
}

PageBody represents the body content of a page.

type PageChild

type PageChild struct {
	ID            string `json:"id"`
	Status        string `json:"status"`
	Title         string `json:"title"`
	ParentID      string `json:"parentId,omitempty"`
	Depth         int    `json:"depth,omitempty"`
	ChildPosition int    `json:"childPosition,omitempty"`
	Type          string `json:"type"` // "page" or "folder"
}

PageChild represents a child or descendant page.

type PageLinks struct {
	WebUI  string `json:"webui,omitempty"`
	EditUI string `json:"editui,omitempty"`
	TinyUI string `json:"tinyui,omitempty"`
}

PageLinks represents page links.

type PageVersion

type PageVersion struct {
	Number    int    `json:"number"`
	Message   string `json:"message,omitempty"`
	CreatedAt string `json:"createdAt,omitempty"`
	AuthorID  string `json:"authorId,omitempty"`
}

PageVersion represents page version information.

type PagesResponse

type PagesResponse struct {
	Results []*Page          `json:"results"`
	Links   *PaginationLinks `json:"_links,omitempty"`
}

PagesResponse represents a paginated list of pages.

type PaginationLinks struct {
	Next string `json:"next,omitempty"`
	Base string `json:"base,omitempty"`
}

PaginationLinks represents pagination links.

type ParentID

type ParentID struct {
	Key string `json:"key"`
}

ParentID is used when creating subtasks.

type PlainValue

type PlainValue struct {
	Value string `json:"value"`
}

PlainValue represents plain text content.

type Priority

type Priority struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	IconURL     string `json:"iconUrl,omitempty"`
	StatusColor string `json:"statusColor,omitempty"`
}

Priority represents an issue priority.

type PriorityID

type PriorityID struct {
	Name string `json:"name"`
}

PriorityID is used when setting priority.

type Project

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

Project represents a Jira project.

type ProjectID

type ProjectID struct {
	Key string `json:"key"`
}

ProjectID is used when creating issues.

type ProjectIssueType

type ProjectIssueType struct {
	ID             string `json:"id"`
	Name           string `json:"name"`
	Description    string `json:"description,omitempty"`
	Subtask        bool   `json:"subtask"`
	HierarchyLevel int    `json:"hierarchyLevel,omitempty"`
}

ProjectIssueType represents an issue type available in a project.

type ProjectIssueTypesResponse

type ProjectIssueTypesResponse struct {
	IssueTypes []*ProjectIssueType `json:"issueTypes"`
}

ProjectIssueTypesResponse represents the response from createmeta endpoint.

type RemoteLink struct {
	ID           int               `json:"id"`
	Self         string            `json:"self,omitempty"`
	GlobalID     string            `json:"globalId,omitempty"`
	Application  *RemoteLinkApp    `json:"application,omitempty"`
	Relationship string            `json:"relationship,omitempty"`
	Object       *RemoteLinkObject `json:"object"`
}

RemoteLink represents a remote/web link on an issue.

type RemoteLinkApp

type RemoteLinkApp struct {
	Type string `json:"type,omitempty"`
	Name string `json:"name,omitempty"`
}

RemoteLinkApp represents the application info for a remote link.

type RemoteLinkIcon

type RemoteLinkIcon struct {
	URL16x16 string `json:"url16x16,omitempty"`
	Title    string `json:"title,omitempty"`
}

RemoteLinkIcon represents an icon for a remote link.

type RemoteLinkObject

type RemoteLinkObject struct {
	URL     string            `json:"url"`
	Title   string            `json:"title"`
	Summary string            `json:"summary,omitempty"`
	Icon    *RemoteLinkIcon   `json:"icon,omitempty"`
	Status  *RemoteLinkStatus `json:"status,omitempty"`
}

RemoteLinkObject represents the linked object details.

type RemoteLinkStatus

type RemoteLinkStatus struct {
	Resolved bool            `json:"resolved,omitempty"`
	Icon     *RemoteLinkIcon `json:"icon,omitempty"`
}

RemoteLinkStatus represents the status of a remote link.

type Resolution

type Resolution struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
}

Resolution represents an issue resolution.

type SearchOptions

type SearchOptions struct {
	JQL           string
	MaxResults    int
	Fields        []string
	NextPageToken string // Token for pagination (replaces startAt)
}

SearchOptions contains options for searching issues.

type SearchResult

type SearchResult struct {
	Issues        []*Issue `json:"issues"`
	Total         int      `json:"total"`
	MaxResults    int      `json:"maxResults"`
	StartAt       int      `json:"startAt"`       // Deprecated: use NextPageToken
	NextPageToken string   `json:"nextPageToken"` // Token for fetching the next page
	IsLast        bool     `json:"isLast"`        // True if this is the last page
}

SearchResult represents the result of a JQL search. Note: The new /search/jql endpoint uses nextPageToken for pagination instead of startAt.

type Space

type Space struct {
	ID          string            `json:"id"`
	Key         string            `json:"key"`
	Name        string            `json:"name"`
	Type        string            `json:"type"`
	Description *SpaceDescription `json:"description,omitempty"`
	Status      string            `json:"status"`
	HomepageID  string            `json:"homepageId,omitempty"`
}

Space represents a Confluence space.

type SpaceDescription

type SpaceDescription struct {
	Plain *PlainValue `json:"plain,omitempty"`
	View  *ViewValue  `json:"view,omitempty"`
}

SpaceDescription represents a space description.

type SpaceRef

type SpaceRef struct {
	Key string `json:"key"`
}

SpaceRef is a reference to a space in template responses.

type SpacesResponse

type SpacesResponse struct {
	Results []*Space         `json:"results"`
	Links   *PaginationLinks `json:"_links,omitempty"`
}

SpacesResponse represents a paginated list of spaces.

type Sprint

type Sprint struct {
	ID            int    `json:"id"`
	Name          string `json:"name"`
	State         string `json:"state"` // future, active, closed
	StartDate     string `json:"startDate,omitempty"`
	EndDate       string `json:"endDate,omitempty"`
	OriginBoardID int    `json:"originBoardId,omitempty"`
	Goal          string `json:"goal,omitempty"`
}

Sprint represents a Jira sprint.

type SprintsResponse

type SprintsResponse struct {
	MaxResults int       `json:"maxResults"`
	StartAt    int       `json:"startAt"`
	IsLast     bool      `json:"isLast"`
	Values     []*Sprint `json:"values"`
}

SprintsResponse represents a paginated list of sprints.

type Status

type Status struct {
	ID             string          `json:"id"`
	Name           string          `json:"name"`
	Description    string          `json:"description,omitempty"`
	StatusCategory *StatusCategory `json:"statusCategory,omitempty"`
}

Status represents an issue status.

type StatusCategory

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

StatusCategory represents a status category.

type Template

type Template struct {
	TemplateID   string        `json:"templateId"`
	Name         string        `json:"name"`
	Description  string        `json:"description,omitempty"`
	TemplateType string        `json:"templateType"` // "page" or "blogpost"
	Body         *TemplateBody `json:"body,omitempty"`
	Space        *SpaceRef     `json:"space,omitempty"`
	Labels       []Label       `json:"labels,omitempty"`
}

Template represents a Confluence content template.

type TemplateBody

type TemplateBody struct {
	Storage *BodyContent `json:"storage,omitempty"`
	View    *BodyContent `json:"view,omitempty"`
}

TemplateBody represents the body of a template.

type Transition

type Transition struct {
	ID   string  `json:"id"`
	Name string  `json:"name"`
	To   *Status `json:"to,omitempty"`
}

Transition represents a workflow transition.

type TransitionID

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

TransitionID identifies a transition.

type TransitionRequest

type TransitionRequest struct {
	Transition TransitionID           `json:"transition"`
	Fields     map[string]interface{} `json:"fields,omitempty"`
}

TransitionRequest represents a request to transition an issue.

type TransitionsResponse

type TransitionsResponse struct {
	Transitions []*Transition `json:"transitions"`
}

TransitionsResponse represents available transitions for an issue.

type UpdateIssueRequest

type UpdateIssueRequest struct {
	Fields map[string]interface{} `json:"fields,omitempty"`
	Update map[string][]UpdateOp  `json:"update,omitempty"`
}

UpdateIssueRequest represents a request to update an issue.

type UpdateOp

type UpdateOp struct {
	Add    interface{} `json:"add,omitempty"`
	Remove interface{} `json:"remove,omitempty"`
	Set    interface{} `json:"set,omitempty"`
}

UpdateOp represents an update operation.

type UpdatePageRequest

type UpdatePageRequest struct {
	ID      string `json:"id"`
	Status  string `json:"status"`
	Title   string `json:"title"`
	Version struct {
		Number  int    `json:"number"`
		Message string `json:"message,omitempty"`
	} `json:"version"`
	Body struct {
		Representation string `json:"representation"`
		Value          string `json:"value"`
	} `json:"body"`
}

UpdatePageRequest represents a request to update a page.

type UpdateTemplateRequest

type UpdateTemplateRequest struct {
	TemplateID   string `json:"templateId"`
	Name         string `json:"name"`
	TemplateType string `json:"templateType"`
	Description  string `json:"description,omitempty"`
	Body         struct {
		Storage struct {
			Value          string `json:"value"`
			Representation string `json:"representation"`
		} `json:"storage"`
	} `json:"body"`
	Space *struct {
		Key string `json:"key"`
	} `json:"space,omitempty"`
}

UpdateTemplateRequest represents a request to update a template.

type User

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

User represents a Jira user.

type ViewValue

type ViewValue struct {
	Value string `json:"value"`
}

ViewValue represents rendered content.

Jump to

Keyboard shortcuts

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