Documentation
¶
Overview ¶
Package jira is a thin Jira REST API v3 transport: authentication, site and OAuth cloud resolution, error redaction and the raw read/write calls. It returns Jira's JSON as json.RawMessage; modelling it (ADF, issues, sync) is the caller's concern.
Index ¶
- type Client
- func (c *Client) Account(ctx context.Context) (string, error)
- func (c *Client) Attachments(ctx context.Context, key string) (json.RawMessage, error)
- func (c *Client) BaseURL() string
- func (c *Client) CloudID() string
- func (c *Client) Comments(ctx context.Context, key string) ([]json.RawMessage, error)
- func (c *Client) CreateComment(ctx context.Context, key string, body any) (json.RawMessage, error)
- func (c *Client) DeleteAttachment(ctx context.Context, id string) error
- func (c *Client) DownloadAttachment(ctx context.Context, id string, w io.Writer) (Download, error)
- func (c *Client) Fields(ctx context.Context) ([]FieldDefinition, error)
- func (c *Client) GetIssue(ctx context.Context, opts GetIssueOptions) (json.RawMessage, error)
- func (c *Client) JSON(ctx context.Context, opts RequestOptions, out any) error
- func (c *Client) Myself(ctx context.Context) (json.RawMessage, error)
- func (c *Client) OpenAttachment(ctx context.Context, id string) (*http.Response, error)
- func (c *Client) RemoteLinks(ctx context.Context, key string) ([]json.RawMessage, error)
- func (c *Client) Request(ctx context.Context, opts RequestOptions) (*http.Response, error)
- func (c *Client) SearchPage(ctx context.Context, opts SearchOptions) (SearchPage, error)
- func (c *Client) Site() string
- func (c *Client) UploadAttachments(ctx context.Context, key string, files []string) (json.RawMessage, error)
- type Download
- type FieldDefinition
- type GetIssueOptions
- type Identity
- type Option
- type RequestOptions
- type SearchOptions
- type SearchPage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client calls one Jira site.
func NewClient ¶
func NewClient(ctx context.Context, conn connection.JiraConnection, opts ...Option) (*Client, error)
NewClient validates conn, which must already be hydrated, and resolves the site: a bearer connection asks Atlassian which sites the token reaches.
func (*Client) Attachments ¶
Attachments is the raw attachment array of an issue.
func (*Client) BaseURL ¶
BaseURL is the URL the REST paths are appended to; it differs from Site when requests go through the Atlassian API gateway.
func (*Client) CloudID ¶
CloudID is the Atlassian cloud id requests are routed by, empty when they go straight to the site.
func (*Client) Comments ¶
Comments reads every raw comment of an issue, following Jira's offset paging.
func (*Client) CreateComment ¶
CreateComment posts body, an Atlassian Document Format document, as a comment and returns the raw created comment.
func (*Client) DeleteAttachment ¶
DeleteAttachment removes an attachment.
func (*Client) DownloadAttachment ¶
DownloadAttachment streams an attachment's content into w.
func (*Client) Fields ¶
func (c *Client) Fields(ctx context.Context) ([]FieldDefinition, error)
Fields is the site's field catalog: system fields and custom fields.
func (*Client) GetIssue ¶
func (c *Client) GetIssue(ctx context.Context, opts GetIssueOptions) (json.RawMessage, error)
GetIssue is the raw issue document. It does not record the read in the user's recently viewed list.
func (*Client) JSON ¶
JSON makes a call and decodes its JSON response into out; a nil out discards the body.
func (*Client) OpenAttachment ¶
OpenAttachment starts an attachment download. The caller streams and closes the response body, and reads its announced ContentLength for progress.
func (*Client) RemoteLinks ¶
RemoteLinks are the raw remote link documents of an issue.
func (*Client) Request ¶
Request makes an authenticated call and returns the response of a 2xx status; the caller closes its body. Any other status is an error carrying the truncated, redacted response body.
func (*Client) SearchPage ¶
func (c *Client) SearchPage(ctx context.Context, opts SearchOptions) (SearchPage, error)
SearchPage reads one page of a JQL search. Follow NextPageToken until IsLast.
func (*Client) Site ¶
Site is the site URL browse links hang off, such as https://acme.atlassian.net.
func (*Client) UploadAttachments ¶
func (c *Client) UploadAttachments(ctx context.Context, key string, files []string) (json.RawMessage, error)
UploadAttachments attaches the files to an issue and returns the raw array of created attachments.
type Download ¶
type Download struct {
SHA256 string
ETag string
Size int64
// ContentLength is the size Jira announced, -1 when it did not.
ContentLength int64
}
Download describes the content DownloadAttachment wrote.
type FieldDefinition ¶
type FieldDefinition struct {
ID string `json:"id"`
Name string `json:"name"`
Schema json.RawMessage `json:"schema,omitempty"`
Required *bool `json:"required,omitempty"`
Operations []string `json:"operations,omitempty"`
AllowedValues json.RawMessage `json:"allowedValues,omitempty"`
}
FieldDefinition is one entry of Jira's field catalog.
type GetIssueOptions ¶
GetIssueOptions selects an issue and the fields to return; "*all", Jira's own spelling of every field, is requested when Fields is empty.
type Identity ¶
type Identity struct {
AccountID string `json:"accountId"`
DisplayName string `json:"displayName"`
Email string `json:"emailAddress"`
// Site is the Jira site the connection reaches.
Site string `json:"-"`
}
Identity is who a connection authenticates as, read from /myself.
func Probe ¶
func Probe(ctx context.Context, resolver connection.ConnectionContext, model models.Connection) (Identity, error)
Probe tests a stored jira connection by calling GET /rest/api/3/myself. Its value references resolve through resolver in the connection's namespace.
type Option ¶
type Option func(*options)
Option customises NewClient.
func WithHTTPClient ¶
func WithHTTPClient(client *httpclient.Client) Option
WithHTTPClient makes the caller's client carry the requests. It is the caller that configures its logging, HAR capture and transport; NewClient still sets its timeout and refuses redirects.
type RequestOptions ¶
type RequestOptions struct {
Method string
Path string
URL string
Query url.Values
Body any
Headers map[string]string
}
RequestOptions describes one REST call. Path is relative to /rest/api/3 and ignored when URL is an absolute URL.
type SearchOptions ¶
SearchOptions is one page of a JQL search. After is the NextPageToken of the previous page; Limit 0 leaves Jira's default page size.
type SearchPage ¶
type SearchPage struct {
Issues []json.RawMessage `json:"issues"`
NextPageToken string `json:"nextPageToken"`
// IsLast is nil when Jira did not say.
IsLast *bool `json:"isLast"`
}
SearchPage is one page of /search/jql: the raw issues and the continuation.