224 lines
6.8 KiB
Go
224 lines
6.8 KiB
Go
package jira
|
|||
|
|
|
||
|
|
import "encoding/json"
|
||
|
|
|
||
|
|
// Project is a Jira project. Description, Lead and Components are only
|
||
|
|
// filled by Project (the single-project call), not by ListProjects.
|
||
|
|
type Project struct {
|
||
|
|
ID string `json:"id"`
|
||
|
|
Key string `json:"key"`
|
||
|
|
Name string `json:"name"`
|
||
|
|
ProjectTypeKey string `json:"projectTypeKey"`
|
||
|
|
Description string `json:"description,omitempty"`
|
||
|
|
Lead *User `json:"lead,omitempty"`
|
||
|
|
Components []Named `json:"components,omitempty"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// User is a Jira account: AccountID on Cloud, Name/Key on Server/Data
|
||
|
|
// Center.
|
||
|
|
type User struct {
|
||
|
|
AccountID string `json:"accountId"`
|
||
|
|
Name string `json:"name,omitempty"`
|
||
|
|
Key string `json:"key,omitempty"`
|
||
|
|
DisplayName string `json:"displayName"`
|
||
|
|
EmailAddress string `json:"emailAddress"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// Named is any Jira object identified by id/name (and sometimes key):
|
||
|
|
// components, issue types, priorities, link types.
|
||
|
|
type Named struct {
|
||
|
|
ID string `json:"id"`
|
||
|
|
Name string `json:"name"`
|
||
|
|
Key string `json:"key,omitempty"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// Version is a project version ("release").
|
||
|
|
type Version struct {
|
||
|
|
ID string `json:"id"`
|
||
|
|
Name string `json:"name"`
|
||
|
|
Description string `json:"description,omitempty"`
|
||
|
|
Released bool `json:"released"`
|
||
|
|
Archived bool `json:"archived"`
|
||
|
|
ReleaseDate string `json:"releaseDate,omitempty"`
|
||
|
|
StartDate string `json:"startDate,omitempty"`
|
||
|
|
ProjectID int `json:"projectId,omitempty"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// Field is one entry of the field list.
|
||
|
|
type Field struct {
|
||
|
|
ID string `json:"id"`
|
||
|
|
Key string `json:"key"`
|
||
|
|
Name string `json:"name"`
|
||
|
|
Custom bool `json:"custom"`
|
||
|
|
Schema *FieldSchema `json:"schema"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// FieldSchema describes a field's value shape.
|
||
|
|
type FieldSchema struct {
|
||
|
|
Type string `json:"type"`
|
||
|
|
Items string `json:"items,omitempty"`
|
||
|
|
Custom string `json:"custom,omitempty"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// Issue is a Jira issue. The standard fields are decoded into Fields;
|
||
|
|
// every field (standard and custom) also stays available raw in
|
||
|
|
// Fields.Raw, because custom field IDs differ per site and are only known
|
||
|
|
// at runtime.
|
||
|
|
type Issue struct {
|
||
|
|
ID string `json:"id"`
|
||
|
|
Key string `json:"key"`
|
||
|
|
Self string `json:"self,omitempty"`
|
||
|
|
Fields IssueFields `json:"fields"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// IssueFields are the standard fields. Description is ADF (a JSON
|
||
|
|
// object) on Cloud and a wiki-markup string on Server/Data Center.
|
||
|
|
type IssueFields struct {
|
||
|
|
Summary string `json:"summary"`
|
||
|
|
Status *Status `json:"status"`
|
||
|
|
IssueType *Named `json:"issuetype"`
|
||
|
|
Resolutiondate string `json:"resolutiondate"`
|
||
|
|
Created string `json:"created"`
|
||
|
|
Updated string `json:"updated"`
|
||
|
|
Reporter *User `json:"reporter"`
|
||
|
|
Assignee *User `json:"assignee"`
|
||
|
|
Priority *Named `json:"priority"`
|
||
|
|
Components []Named `json:"components"`
|
||
|
|
Versions []Version `json:"versions"` // affected versions
|
||
|
|
FixVersions []Version `json:"fixVersions"` // fix versions
|
||
|
|
Labels []string `json:"labels"`
|
||
|
|
Comment *CommentPage `json:"comment"`
|
||
|
|
Description json.RawMessage `json:"description"`
|
||
|
|
IssueLinks []IssueLink `json:"issuelinks"`
|
||
|
|
Parent *LinkedIssue `json:"parent"`
|
||
|
|
Subtasks []LinkedIssue `json:"subtasks"`
|
||
|
|
|
||
|
|
Raw map[string]json.RawMessage `json:"-"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// UnmarshalJSON decodes the standard fields and keeps all of them raw.
|
||
|
|
func (f *IssueFields) UnmarshalJSON(data []byte) error {
|
||
|
|
type plain IssueFields
|
||
|
|
var p plain
|
||
|
|
if err := json.Unmarshal(data, &p); err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
var raw map[string]json.RawMessage
|
||
|
|
if err := json.Unmarshal(data, &raw); err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
*f = IssueFields(p)
|
||
|
|
f.Raw = raw
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
// MarshalJSON writes the raw fields back, so an Issue round-trips.
|
||
|
|
func (f IssueFields) MarshalJSON() ([]byte, error) {
|
||
|
|
if f.Raw != nil {
|
||
|
|
return json.Marshal(f.Raw)
|
||
|
|
}
|
||
|
|
type plain IssueFields
|
||
|
|
return json.Marshal(plain(f))
|
||
|
|
}
|
||
|
|
|
||
|
|
// Status is an issue status with its category (new, indeterminate, done).
|
||
|
|
type Status struct {
|
||
|
|
Name string `json:"name"`
|
||
|
|
StatusCategory *struct {
|
||
|
|
Key string `json:"key"`
|
||
|
|
} `json:"statusCategory"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// CategoryKey is the status category key, "" if unknown.
|
||
|
|
func (s *Status) CategoryKey() string {
|
||
|
|
if s == nil || s.StatusCategory == nil {
|
||
|
|
return ""
|
||
|
|
}
|
||
|
|
return s.StatusCategory.Key
|
||
|
|
}
|
||
|
|
|
||
|
|
// StatusName is s.Name, "" for nil.
|
||
|
|
func (s *Status) StatusName() string {
|
||
|
|
if s == nil {
|
||
|
|
return ""
|
||
|
|
}
|
||
|
|
return s.Name
|
||
|
|
}
|
||
|
|
|
||
|
|
// CommentPage is one page of comments (also embedded in a search result
|
||
|
|
// when the comment field is requested).
|
||
|
|
type CommentPage struct {
|
||
|
|
Comments []Comment `json:"comments"`
|
||
|
|
Total int `json:"total"`
|
||
|
|
MaxResults int `json:"maxResults"`
|
||
|
|
StartAt int `json:"startAt"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// Comment is one issue comment. Body is ADF on Cloud, a string on
|
||
|
|
// Server/Data Center.
|
||
|
|
type Comment struct {
|
||
|
|
ID string `json:"id"`
|
||
|
|
Author *User `json:"author"`
|
||
|
|
Body json.RawMessage `json:"body"`
|
||
|
|
Created string `json:"created"`
|
||
|
|
Updated string `json:"updated"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// IssueLinkType names a link type in both directions.
|
||
|
|
type IssueLinkType struct {
|
||
|
|
Name string `json:"name"`
|
||
|
|
Inward string `json:"inward"`
|
||
|
|
Outward string `json:"outward"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// IssueLink links two issues; exactly one of InwardIssue/OutwardIssue is
|
||
|
|
// set, the other end is the issue the link belongs to.
|
||
|
|
type IssueLink struct {
|
||
|
|
Type *IssueLinkType `json:"type"`
|
||
|
|
InwardIssue *LinkedIssue `json:"inwardIssue"`
|
||
|
|
OutwardIssue *LinkedIssue `json:"outwardIssue"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// LinkedIssue is the short form of an issue inside a link, a parent or a
|
||
|
|
// subtask list.
|
||
|
|
type LinkedIssue struct {
|
||
|
|
ID string `json:"id,omitempty"`
|
||
|
|
Key string `json:"key"`
|
||
|
|
Fields struct {
|
||
|
|
Summary string `json:"summary"`
|
||
|
|
Status *Status `json:"status"`
|
||
|
|
} `json:"fields"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// ChangelogEntry is one change set of an issue's history.
|
||
|
|
type ChangelogEntry struct {
|
||
|
|
ID string `json:"id"`
|
||
|
|
Author *User `json:"author"`
|
||
|
|
Created string `json:"created"`
|
||
|
|
Items []ChangelogItem `json:"items"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// ChangelogItem is one changed field inside a ChangelogEntry.
|
||
|
|
type ChangelogItem struct {
|
||
|
|
Field string `json:"field"`
|
||
|
|
FieldID string `json:"fieldId"`
|
||
|
|
From string `json:"from"`
|
||
|
|
FromString string `json:"fromString"`
|
||
|
|
To string `json:"to"`
|
||
|
|
ToString string `json:"toString"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// Transition is a workflow transition currently available on an issue.
|
||
|
|
type Transition struct {
|
||
|
|
ID string `json:"id"`
|
||
|
|
Name string `json:"name"`
|
||
|
|
To *Status `json:"to"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// ServerInfo is /serverInfo.
|
||
|
|
type ServerInfo struct {
|
||
|
|
BaseURL string `json:"baseUrl"`
|
||
|
|
Version string `json:"version"`
|
||
|
|
DeploymentType string `json:"deploymentType"`
|
||
|
|
ServerTitle string `json:"serverTitle"`
|
||
|
|
}
|