Skip to content

Commit

Permalink
Preparing for release:
Browse files Browse the repository at this point in the history
  * Migrated requests to services
  * Corrected bug with attachment handling
  * Added StatsService
  • Loading branch information
theriverman committed May 18, 2020
1 parent af82bd4 commit 8ba4f05
Show file tree
Hide file tree
Showing 19 changed files with 449 additions and 347 deletions.
4 changes: 2 additions & 2 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (s *AuthService) PublicRegistry(credentials *Credentials) (*UserAuthenticat

credentials.Type = "public"
credentials.AcceptedTerms = true // Hardcoded for simplicity; otherwise this func would be useless
err := postRequest(s.client, &response, url, &credentials)
err := s.client.Request.PostRequest(url, &credentials, &response)
if err != nil {
return nil, err
}
Expand All @@ -35,7 +35,7 @@ func (s *AuthService) login(credentials *Credentials) (*UserAuthenticationDetail
url := s.client.APIURL + endpointAuth
response := UserAuthenticationDetail{}

err := postRequest(s.client, &response, url, &credentials)
err := s.client.Request.PostRequest(url, &credentials, &response)
if err != nil {
log.Println("Failed to authenticate to Taiga.")
return nil, err
Expand Down
9 changes: 8 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ type Client struct {
pagination *Pagination // Pagination details extracted from the LAST http response
paginationDisabled bool // indicates pagination status

// Services
// Core Services
Request *RequestService

// Taiga Services
Auth *AuthService
Epic *EpicService
Issue *IssueService
Milestone *MilestoneService
Project *ProjectService
Stats *StatsService
Task *TaskService
UserStory *UserStoryService
User *UserService
Expand Down Expand Up @@ -113,11 +117,14 @@ func (c *Client) Initialise(credentials *Credentials) error {
c.DisablePagination(true) // https://taigaio.github.io/taiga-doc/dist/api.html#_pagination

// Bootstrapping Services
c.Request = &RequestService{c}

c.Auth = &AuthService{c}
c.Epic = &EpicService{c}
c.Issue = &IssueService{c}
c.Milestone = &MilestoneService{c}
c.Project = &ProjectService{c}
c.Stats = &StatsService{c}
c.Task = &TaskService{c}
c.UserStory = &UserStoryService{c}
c.User = &UserService{c}
Expand Down
4 changes: 2 additions & 2 deletions common.functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func listAttachmentsForEndpoint(c *Client, queryParams *attachmentsQueryParams)
url := c.APIURL + queryParams.endpointURI + "/attachments?" + paramValues.Encode()
var attachmentsList []Attachment

err := getRequest(c, &attachmentsList, url)
err := c.Request.GetRequest(url, &attachmentsList)
if err != nil {
return nil, err
}
Expand All @@ -31,7 +31,7 @@ func getAttachmentForEndpoint(c *Client, attachment *Attachment, endpointURI str
url := c.APIURL + endpointURI + fmt.Sprintf("/attachments/%d", attachment.ID)
var a Attachment

err := getRequest(c, &a, url)
err := c.Request.GetRequest(url, &a)
if err != nil {
return nil, err
}
Expand Down
42 changes: 24 additions & 18 deletions epics.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (s *EpicService) List(queryParams *EpicsQueryParams) ([]Epic, error) {
url = url + s.client.GetDefaultProjectAsQueryParam()
}
var epics EpicDetailLIST
err := getRequest(s.client, &epics, url)
err := s.client.Request.GetRequest(url, &epics)
if err != nil {
return nil, err
}
Expand All @@ -41,20 +41,20 @@ func (s *EpicService) List(queryParams *EpicsQueryParams) ([]Epic, error) {
// Available Meta: *EpicDetail
func (s *EpicService) Create(epic Epic) (*Epic, error) {
url := s.client.APIURL + endpointEpics
var respEpic EpicDetail
var responseEpic EpicDetail

// Check for required fields
// project, subject
if isEmpty(epic.Project) || isEmpty(epic.Subject) {
return nil, errors.New("A mandatory field is missing. See API documentataion")
return nil, errors.New("A mandatory field(Project, Subject) is missing. See API documentataion")
}

err := postRequest(s.client, &respEpic, url, epic)
err := s.client.Request.PostRequest(url, &epic, &responseEpic)
if err != nil {
return nil, err
}

return respEpic.AsEpic()
return responseEpic.AsEpic()
}

// Get => https://taigaio.github.io/taiga-doc/dist/api.html#epics-get
Expand All @@ -63,7 +63,7 @@ func (s *EpicService) Create(epic Epic) (*Epic, error) {
func (s *EpicService) Get(epicID int) (*Epic, error) {
url := s.client.APIURL + fmt.Sprintf("%s/%d", endpointEpics, epicID)
var e EpicDetailGET
err := getRequest(s.client, &e, url)
err := s.client.Request.GetRequest(url, &e)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -95,7 +95,7 @@ func (s *EpicService) GetByRef(epicRef int, project *Project) (*Epic, error) {
return nil, errors.New("No ID or Ref defined in passed project struct")
}

err := getRequest(s.client, &e, url)
err := s.client.Request.GetRequest(url, &e)
if err != nil {
return nil, err
}
Expand All @@ -106,7 +106,7 @@ func (s *EpicService) GetByRef(epicRef int, project *Project) (*Epic, error) {
// Available Meta: EpicDetail
func (s *EpicService) Edit(epic Epic) (*Epic, error) {
url := s.client.APIURL + fmt.Sprintf("%s/%d", endpointEpics, epic.ID)
var epicDetail EpicDetail
var responseEpic EpicDetail

if epic.ID == 0 {
return nil, errors.New("Passed Epic does not have an ID yet. Does it exist?")
Expand All @@ -118,17 +118,17 @@ func (s *EpicService) Edit(epic Epic) (*Epic, error) {
return nil, err
}
epic.Version = remoteEpic.Version
err = patchRequest(s.client, &epicDetail, url, &epic)
err = s.client.Request.PatchRequest(url, &epic, &responseEpic)
if err != nil {
return nil, err
}
return epicDetail.AsEpic()
return responseEpic.AsEpic()
}

// Delete => https://taigaio.github.io/taiga-doc/dist/api.html#epics-delete
func (s *EpicService) Delete(epicID int) error {
url := s.client.APIURL + fmt.Sprintf("%s/%d", endpointEpics, epicID)
return deleteRequest(s.client, url)
return s.client.Request.DeleteRequest(url)
}

// BulkCreation => https://taigaio.github.io/taiga-doc/dist/api.html#epics-bulk-create
Expand All @@ -148,12 +148,12 @@ It seems to be pointless to implement this operation here. A for loop around `Cr
// ListRelatedUserStories => https://taigaio.github.io/taiga-doc/dist/api.html#epics-related-user-stories-list
func (s *EpicService) ListRelatedUserStories(epicID int) ([]EpicRelatedUserStoryDetail, error) {
url := s.client.APIURL + fmt.Sprintf("%s/%d/related_userstories", endpointEpics, epicID)
var resp []EpicRelatedUserStoryDetail
err := getRequest(s.client, &resp, url)
var responseEpic []EpicRelatedUserStoryDetail
err := s.client.Request.GetRequest(url, &responseEpic)
if err != nil {
return nil, err
}
return resp, nil
return responseEpic, nil
}

// CreateRelatedUserStory => https://taigaio.github.io/taiga-doc/dist/api.html#epics-related-user-stories-create
Expand All @@ -162,22 +162,28 @@ func (s *EpicService) ListRelatedUserStories(epicID int) ([]EpicRelatedUserStory
// Accepted UserStory values: `UserStory.ID`
func (s *EpicService) CreateRelatedUserStory(epicRelatedUSDetail *EpicRelatedUserStoryDetail) (*EpicRelatedUserStoryDetail, error) {
url := s.client.APIURL + fmt.Sprintf("%s/%d/related_userstories", endpointEpics, epicRelatedUSDetail.EpicID)
var resp EpicRelatedUserStoryDetail
var responseEpic EpicRelatedUserStoryDetail

err := postRequest(s.client, &resp, url, epicRelatedUSDetail)
err := s.client.Request.PostRequest(url, epicRelatedUSDetail, &responseEpic)
if err != nil {
return nil, err
}
return &resp, nil
return &responseEpic, nil
}

// CreateAttachment creates a new Epic attachment => https://taigaio.github.io/taiga-doc/dist/api.html#epics-create-attachment
//
// Mandatory parameters: `ObjectID`; `ProjectID`;
// **Note**: Set ObjectID to epic.ID
func (s *EpicService) CreateAttachment(attachment *Attachment, filePath string) (*Attachment, error) {
func (s *EpicService) CreateAttachment(attachment *Attachment, epic *Epic, filePath string) (*Attachment, error) {
url := s.client.APIURL + endpointEpics + "/attachments"
attachment.filePath = filePath
attachment.ObjectID = epic.ID
if attachment.Project == 0 && epic.Project > 0 {
attachment.Project = epic.Project
} else {
return nil, fmt.Errorf("Project.ID could not be fetched from any possible sources")
}
return newfileUploadRequest(s.client, url, attachment)
}

Expand Down
2 changes: 1 addition & 1 deletion epics.models.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ type EpicRelatedUserStoryDetail struct {

// GetUserStory returns the UserStory referred in the EpicRelatedUserStoryDetail
func (e *EpicRelatedUserStoryDetail) GetUserStory(c *Client) (*UserStory, error) {
return c.UserStory.GetUserStory(e.UserStoryID)
return c.UserStory.Get(e.UserStoryID)
}

// GetEpic returns the Epic referred in the EpicRelatedUserStoryDetail
Expand Down
15 changes: 0 additions & 15 deletions errors.go

This file was deleted.

14 changes: 8 additions & 6 deletions issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (s *IssueService) List(queryParams *IssueQueryParams) ([]Issue, error) {
}
// execute requests
var issues IssueDetailLIST
err := getRequest(s.client, &issues, url)
err := s.client.Request.GetRequest(url, &issues)
if err != nil {
return nil, err
}
Expand All @@ -34,12 +34,14 @@ func (s *IssueService) List(queryParams *IssueQueryParams) ([]Issue, error) {
}

// CreateAttachment creates a new Issue attachment => https://taigaio.github.io/taiga-doc/dist/api.html#issues-create-attachment
func (s *IssueService) CreateAttachment(attachment *Attachment, filePath string) (*Attachment, error) {
func (s *IssueService) CreateAttachment(attachment *Attachment, issue *Issue, filePath string) (*Attachment, error) {
url := s.client.APIURL + endpointIssues + "/attachments"
attachment.filePath = filePath
attachment, err := newfileUploadRequest(s.client, url, attachment)
if err != nil {
return nil, err
attachment.ObjectID = issue.ID
if attachment.Project == 0 && issue.Project > 0 {
attachment.Project = issue.Project
} else {
return nil, fmt.Errorf("Project.ID could not be fetched from any possible sources")
}
return attachment, nil
return newfileUploadRequest(s.client, url, attachment)
}
32 changes: 17 additions & 15 deletions milestones.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ type MilestoneService struct {
client *Client
}

// ListMilestones => https://taigaio.github.io/taiga-doc/dist/api.html#Milestones-list
func (s *MilestoneService) ListMilestones(queryParams *MilestonesQueryParams) ([]Milestone, error) {
// List => https://taigaio.github.io/taiga-doc/dist/api.html#Milestones-list
func (s *MilestoneService) List(queryParams *MilestonesQueryParams) ([]Milestone, error) {
// prepare url & parameters
url := s.client.APIURL + endpointMilestones
if queryParams != nil {
Expand All @@ -28,16 +28,18 @@ func (s *MilestoneService) ListMilestones(queryParams *MilestonesQueryParams) ([
}
// execute requests
var Milestones []Milestone
err := getRequest(s.client, &Milestones, url)
err := s.client.Request.GetRequest(url, &Milestones)
if err != nil {
return nil, err
}

return Milestones, nil
}

// CreateMilestone => https://taigaio.github.io/taiga-doc/dist/api.html#milestones-create
func (s *MilestoneService) CreateMilestone(milestone Milestone) (*Milestone, error) {
// Create => https://taigaio.github.io/taiga-doc/dist/api.html#milestones-create
//
// Mandatory fields: Project, Name, EstimatedStart, EstimatedFinish
func (s *MilestoneService) Create(milestone Milestone) (*Milestone, error) {
url := s.client.APIURL + endpointMilestones
var respMilestone Milestone

Expand All @@ -50,46 +52,46 @@ func (s *MilestoneService) CreateMilestone(milestone Milestone) (*Milestone, err
return nil, errors.New("A mandatory field is missing. See API documentataion")
}

err := postRequest(s.client, &respMilestone, url, milestone)
err := s.client.Request.PostRequest(url, &milestone, &respMilestone)
if err != nil {
return nil, err
}

return &respMilestone, nil
}

// GetMilestone => https://taigaio.github.io/taiga-doc/dist/api.html#Milestones-get
func (s *MilestoneService) GetMilestone(milestoneID int) (*Milestone, error) {
// Get => https://taigaio.github.io/taiga-doc/dist/api.html#Milestones-get
func (s *MilestoneService) Get(milestoneID int) (*Milestone, error) {
url := s.client.APIURL + fmt.Sprintf("%s/%d", endpointMilestones, milestoneID)
var m Milestone
err := getRequest(s.client, &m, url)
err := s.client.Request.GetRequest(url, &m)
if err != nil {
return nil, err
}
return &m, nil
}

// EditMilestone edits an Milestone via a PATCH request => https://taigaio.github.io/taiga-doc/dist/api.html#milestones-edit
// Edit edits an Milestone via a PATCH request => https://taigaio.github.io/taiga-doc/dist/api.html#milestones-edit
// Available Meta: MilestoneDetail
func (s *MilestoneService) EditMilestone(milestone Milestone) (*Milestone, error) {
func (s *MilestoneService) Edit(milestone Milestone) (*Milestone, error) {
url := s.client.APIURL + fmt.Sprintf("%s/%d", endpointMilestones, milestone.ID)
var M Milestone

if milestone.ID == 0 {
return nil, errors.New("Passed Milestone does not have an ID yet. Does it exist?")
}

err := patchRequest(s.client, &M, url, &milestone)
err := s.client.Request.PatchRequest(url, &milestone, &M)
if err != nil {
return nil, err
}
return &M, nil
}

// DeleteMilestone => https://taigaio.github.io/taiga-doc/dist/api.html#milestones-delete
func (s *MilestoneService) DeleteMilestone(milestoneID int) error {
// Delete => https://taigaio.github.io/taiga-doc/dist/api.html#milestones-delete
func (s *MilestoneService) Delete(milestoneID int) error {
url := s.client.APIURL + fmt.Sprintf("%s/%d", endpointMilestones, milestoneID)
return deleteRequest(s.client, url)
return s.client.Request.DeleteRequest(url)
}

// Stats
Expand Down
26 changes: 13 additions & 13 deletions milestones.models.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ import "time"
//
// https://taigaio.github.io/taiga-doc/dist/api.html#object-milestone-detail
type Milestone struct {
Closed bool `json:"closed"`
ClosedPoints int `json:"closed_points"`
CreatedDate time.Time `json:"created_date"`
Disponibility float64 `json:"disponibility"`
ID int `json:"id,omitempty"`
Slug string `json:"slug,omitempty"`
Name string `json:"name"`
EstimatedFinish string `json:"estimated_finish"`
EstimatedStart string `json:"estimated_start"`
ID int `json:"id"`
ModifiedDate time.Time `json:"modified_date"`
Name string `json:"name"`
Order int `json:"order"`
Owner int `json:"owner"`
Closed bool `json:"closed,omitempty"`
ClosedPoints int `json:"closed_points,omitempty"`
CreatedDate time.Time `json:"created_date,omitempty"`
Disponibility float64 `json:"disponibility,omitempty"`
ModifiedDate time.Time `json:"modified_date,omitempty"`
Order int `json:"order,omitempty"`
Owner int `json:"owner,omitempty"`
Project int `json:"project"`
ProjectExtraInfo ProjectExtraInfo `json:"project_extra_info"`
Slug string `json:"slug"`
TotalPoints float64 `json:"total_points"`
UserStories []UserStory `json:"user_stories"`
ProjectExtraInfo ProjectExtraInfo `json:"project_extra_info,omitempty"`
TotalPoints float64 `json:"total_points,omitempty"`
UserStories []UserStory `json:"user_stories,omitempty"`
}

// MilestonesQueryParams holds fields to be used as URL query parameters to filter the queried objects
Expand Down
Loading

0 comments on commit 8ba4f05

Please sign in to comment.