Skip to content

Commit

Permalink
added issue accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
q-uint committed Feb 10, 2020
1 parent bc1ccff commit e1b2e46
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 16 deletions.
50 changes: 45 additions & 5 deletions epics.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,30 @@ type EpicIssue struct {
IssueURL *string `json:"issue_url,omitempty"`
}

// GetIssueNumber returns the IssueNumber field if it's non-nil, zero value otherwise.
func (issue *EpicIssue) GetIssueNumber() int {
if issue == nil || issue.IssueNumber == nil {
return 0
}
return *issue.IssueNumber
}

// GetRepositoryID returns the RepositoryID field if it's non-nil, zero value otherwise.
func (issue *EpicIssue) GetRepositoryID() int {
if issue == nil || issue.RepositoryID == nil {
return 0
}
return *issue.RepositoryID
}

// GetIssueURL returns the IssueURL field if it's non-nil, zero value otherwise.
func (issue *EpicIssue) GetIssueURL() string {
if issue == nil || issue.IssueURL == nil {
return ""
}
return *issue.IssueURL
}

func (c *Client) GetEpics(repositoryID int) (*[]EpicIssue, *http.Response, error) {
u := fmt.Sprintf("p1/repositories/%d/epics", repositoryID)
req, err := c.NewRequest(http.MethodGet, u, nil)
Expand All @@ -27,11 +51,27 @@ func (c *Client) GetEpics(repositoryID int) (*[]EpicIssue, *http.Response, error
}

type EpicData struct {
TotalEpicEstimates *Estimate `json:"total_epic_estimates,omitempty"`
Estimate *Estimate `json:"estimate,omitempty"`
Pipeline *Pipeline `json:"pipeline,omitempty"`
Pipelines []Pipeline `json:"pipelines,omitempty"`
Issues []IssueData `json:"issues,omitempty"`
TotalEpicEstimates *Estimate `json:"total_epic_estimates,omitempty"`
Estimate *Estimate `json:"estimate,omitempty"`
Pipeline *Pipeline `json:"pipeline,omitempty"`
Pipelines []*Pipeline `json:"pipelines,omitempty"`
Issues []*IssueData `json:"issues,omitempty"`
}

// GetTotalEpicEstimates returns the TotalEpicEstimates field if it's non-nil, zero value otherwise.
func (data *EpicData) GetTotalEpicEstimates() int {
if data == nil {
return 0
}
return data.TotalEpicEstimates.GetValue()
}

// GetEstimate returns the Estimate field if it's non-nil, zero value otherwise.
func (data *EpicData) GetEstimate() int {
if data == nil {
return 0
}
return data.Estimate.GetValue()
}

func (c *Client) GetEpic(repositoryID, epicID int) (*EpicData, *http.Response, error) {
Expand Down
111 changes: 101 additions & 10 deletions issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,48 @@ import (
)

type IssueData struct {
IssueNumber *int `json:"issue_number,omitempty"`
RepositoryID *int `json:"repo_id,omitempty"`
Estimate *Estimate `json:"estimate,omitempty"`
PlusOnes []EventType `json:"plus_ones,omitempty"`
Pipeline *Pipeline `json:"pipeline,omitempty"`
Pipelines []Pipeline `json:"pipelines,omitempty"`
IsEpic *bool `json:"is_epic,omitempty"`
Estimate *Estimate `json:"estimate,omitempty"`
PlusOnes []*PlusOne `json:"plus_ones,omitempty"`
Pipeline *Pipeline `json:"pipeline,omitempty"`
Pipelines []*Pipeline `json:"pipelines,omitempty"`
IsEpic *bool `json:"is_epic,omitempty"`
}

// GetEstimate returns the Estimate.Value field if it's non-nil, zero value otherwise.
func (data *IssueData) GetEstimate() int {
if data == nil || data.Estimate == nil || data.Estimate.Value == nil {
return 0
}
return *data.Estimate.Value
}

type PlusOne struct {
UserID *int `json:"user_id"`
CreatedAt *string `json:"created_at"`
}

// GetUserID returns the UserID field if it's non-nil, zero value otherwise.
func (plus *PlusOne) GetUserID() int {
if plus == nil && plus.UserID == nil {
return 0
}
return *plus.UserID
}

// GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise.
func (plus *PlusOne) GetCreatedAt() string {
if plus == nil && plus.UserID == nil {
return ""
}
return *plus.CreatedAt
}

// GetIsEpic returns the IsEpic field if it's non-nil, zero value otherwise.
func (data *IssueData) GetIsEpic() bool {
if data == nil && data.IsEpic == nil {
return false
}
return *data.IsEpic
}

func (c *Client) GetIssue(repositoryID, issueNumber int) (*IssueData, *http.Response, error) {
Expand Down Expand Up @@ -41,22 +76,70 @@ type IssueEvent struct {
WorkspaceID *string `json:"workspace_id,omitempty"`
}

// GetUserID returns the UserID field if it's non-nil, zero value otherwise.
func (event *IssueEvent) GetUserID() int {
if event == nil || event.UserID == nil {
return 0
}
return *event.UserID
}

// GetType returns the Type field if it's non-nil, zero value otherwise.
func (event *IssueEvent) GetType() IssuesEventType {
if event == nil || event.Type == nil {
return ""
}
return *event.Type
}

// GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise.
func (event *IssueEvent) GetCreatedAt() string {
if event == nil || event.CreatedAt == nil {
return ""
}
return *event.CreatedAt
}

// GetFromEstimate returns the FromEstimate field if it's non-nil, zero value otherwise.
func (event *IssueEvent) GetFromEstimate() int {
if event == nil {
return 0
}
return event.FromEstimate.GetValue()
}

// GetToEstimate returns the ToEstimate field if it's non-nil, zero value otherwise.
func (event *IssueEvent) GetToEstimate() int {
if event == nil {
return 0
}
return event.ToEstimate.GetValue()
}

// GetWorkspaceID returns the WorkspaceID field if it's non-nil, zero value otherwise.
func (event *IssueEvent) GetWorkspaceID() string {
if event == nil && event.WorkspaceID == nil {
return ""
}
return *event.WorkspaceID
}

type IssuesEventType string

const (
EstimateIssue IssuesEventType = "estimateIssue"
TransferIssue IssuesEventType = "transferIssue"
)

func (c *Client) GetIssueEvents(repositoryID, issueNumber int) (*[]IssueEvent, *http.Response, error) {
func (c *Client) GetIssueEvents(repositoryID, issueNumber int) ([]*IssueEvent, *http.Response, error) {
u := fmt.Sprintf("p1/repositories/%d/issues/%d/events", repositoryID, issueNumber)
req, err := c.NewRequest(http.MethodGet, u, nil)
if err != nil {
return nil, nil, err
}

events := new([]IssueEvent)
resp, err := c.Do(req, events)
var events []*IssueEvent
resp, err := c.Do(req, &events)
if err != nil {
return nil, resp, err
}
Expand Down Expand Up @@ -136,6 +219,14 @@ type Estimate struct {
Value *int `json:"estimate,omitempty"`
}

// GetValue returns the Value field if it's non-nil, zero value otherwise.
func (e *Estimate) GetValue() int {
if e == nil || e.Value == nil {
return 0
}
return *e.Value
}

func (c *Client) SetEstimate(repositoryID, issueNumber, estimate Estimate) (*Estimate, *http.Response, error) {
u := fmt.Sprintf("p1/repositories/%d/issues%d/estimate", repositoryID, issueNumber)
req, err := c.NewRequest(http.MethodPut, u, estimate)
Expand Down
25 changes: 24 additions & 1 deletion pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,28 @@ type Pipeline struct {
Name *string `json:"name,omitempty"`
PipelineID *string `json:"pipeline_id,omitempty"`
WorkspaceID *string `json:"workspace_id,omitempty"`
Issues []IssueData `json:"issues,omitempty"`
}

// GetName returns the Name field if it's non-nil, zero value otherwise.
func (pipe *Pipeline) GetName() string {
if pipe == nil && pipe.Name == nil {
return ""
}
return *pipe.Name
}

// GetPipelineID returns the PipelineID field if it's non-nil, zero value otherwise.
func (pipe *Pipeline) GetPipelineID() string {
if pipe == nil && pipe.PipelineID == nil {
return ""
}
return *pipe.PipelineID
}

// GetWorkspaceID returns the WorkspaceID field if it's non-nil, zero value otherwise.
func (pipe *Pipeline) GetWorkspaceID() string {
if pipe == nil && pipe.WorkspaceID == nil {
return ""
}
return *pipe.WorkspaceID
}

0 comments on commit e1b2e46

Please sign in to comment.