Skip to content
Snippets Groups Projects
Commit 46c8fa61 authored by Sander van Harmelen's avatar Sander van Harmelen
Browse files

Make a few small changes to keep things consistent

parent 320d11c6
Branches
Tags
No related merge requests found
......@@ -10,3 +10,5 @@ require (
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f // indirect
google.golang.org/appengine v1.3.0 // indirect
)
go 1.13
......@@ -7,8 +7,6 @@ github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
......@@ -21,6 +19,7 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
google.golang.org/appengine v1.3.0 h1:FBSsiFRMz3LBeXIomRnVzrQwSDj4ibvcRexLG0LZGQk=
google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
......@@ -34,42 +34,42 @@ type MergeRequestsService struct {
//
// GitLab API docs: https://docs.gitlab.com/ce/api/merge_requests.html
type MergeRequest struct {
ID int `json:"id"`
IID int `json:"iid"`
TargetBranch string `json:"target_branch"`
SourceBranch string `json:"source_branch"`
ProjectID int `json:"project_id"`
Title string `json:"title"`
State MergeRequestState `json:"state"`
CreatedAt *time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at"`
Upvotes int `json:"upvotes"`
Downvotes int `json:"downvotes"`
Author *MergeRequestUser `json:"author"`
Assignee *MergeRequestUser `json:"assignee"`
Assignees []*MergeRequestUser `json:"assignees"`
SourceProjectID int `json:"source_project_id"`
TargetProjectID int `json:"target_project_id"`
Labels []string `json:"labels"`
Description string `json:"description"`
WorkInProgress bool `json:"work_in_progress"`
Milestone *Milestone `json:"milestone"`
MergeWhenPipelineSucceeds bool `json:"merge_when_pipeline_succeeds"`
MergeStatus string `json:"merge_status"`
MergeError string `json:"merge_error"`
MergedBy *MergeRequestUser `json:"merged_by"`
MergedAt *time.Time `json:"merged_at"`
ClosedBy *MergeRequestUser `json:"closed_by"`
ClosedAt *time.Time `json:"closed_at"`
Subscribed bool `json:"subscribed"`
SHA string `json:"sha"`
MergeCommitSHA string `json:"merge_commit_sha"`
UserNotesCount int `json:"user_notes_count"`
ChangesCount string `json:"changes_count"`
ShouldRemoveSourceBranch bool `json:"should_remove_source_branch"`
ForceRemoveSourceBranch bool `json:"force_remove_source_branch"`
WebURL string `json:"web_url"`
DiscussionLocked bool `json:"discussion_locked"`
ID int `json:"id"`
IID int `json:"iid"`
TargetBranch string `json:"target_branch"`
SourceBranch string `json:"source_branch"`
ProjectID int `json:"project_id"`
Title string `json:"title"`
State string `json:"state"`
CreatedAt *time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at"`
Upvotes int `json:"upvotes"`
Downvotes int `json:"downvotes"`
Author *BasicUser `json:"author"`
Assignee *BasicUser `json:"assignee"`
Assignees []*BasicUser `json:"assignees"`
SourceProjectID int `json:"source_project_id"`
TargetProjectID int `json:"target_project_id"`
Labels []string `json:"labels"`
Description string `json:"description"`
WorkInProgress bool `json:"work_in_progress"`
Milestone *Milestone `json:"milestone"`
MergeWhenPipelineSucceeds bool `json:"merge_when_pipeline_succeeds"`
MergeStatus string `json:"merge_status"`
MergeError string `json:"merge_error"`
MergedBy *BasicUser `json:"merged_by"`
MergedAt *time.Time `json:"merged_at"`
ClosedBy *BasicUser `json:"closed_by"`
ClosedAt *time.Time `json:"closed_at"`
Subscribed bool `json:"subscribed"`
SHA string `json:"sha"`
MergeCommitSHA string `json:"merge_commit_sha"`
UserNotesCount int `json:"user_notes_count"`
ChangesCount string `json:"changes_count"`
ShouldRemoveSourceBranch bool `json:"should_remove_source_branch"`
ForceRemoveSourceBranch bool `json:"force_remove_source_branch"`
WebURL string `json:"web_url"`
DiscussionLocked bool `json:"discussion_locked"`
Changes []struct {
OldPath string `json:"old_path"`
NewPath string `json:"new_path"`
......@@ -99,11 +99,6 @@ type MergeRequest struct {
} `json:"task_completion_status"`
}
// MergeRequestUser represents a GitLab User record within a MergeRequest
//
// GitLab API docs: https://docs.gitlab.com/ce/api/merge_requests.html
type MergeRequestUser = BasicUser
func (m MergeRequest) String() string {
return Stringify(m)
}
......@@ -136,57 +131,26 @@ func (m MergeRequestDiffVersion) String() string {
// https://docs.gitlab.com/ce/api/merge_requests.html#list-merge-requests
type ListMergeRequestsOptions struct {
ListOptions
State *MergeRequestState `url:"state,omitempty" json:"state,omitempty"`
OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
Sort *SortDirection `url:"sort,omitempty" json:"sort,omitempty"`
Milestone *string `url:"milestone,omitempty" json:"milestone,omitempty"`
View *MergeRequestView `url:"view,omitempty" json:"view,omitempty"`
Labels Labels `url:"labels,omitempty" json:"labels,omitempty"`
CreatedAfter *time.Time `url:"created_after,omitempty" json:"created_after,omitempty"`
CreatedBefore *time.Time `url:"created_before,omitempty" json:"created_before,omitempty"`
UpdatedAfter *time.Time `url:"updated_after,omitempty" json:"updated_after,omitempty"`
UpdatedBefore *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"`
Scope *Scope `url:"scope,omitempty" json:"scope,omitempty"`
AuthorID *int `url:"author_id,omitempty" json:"author_id,omitempty"`
AssigneeID *int `url:"assignee_id,omitempty" json:"assignee_id,omitempty"`
MyReactionEmoji *string `url:"my_reaction_emoji,omitempty" json:"my_reaction_emoji,omitempty"`
SourceBranch *string `url:"source_branch,omitempty" json:"source_branch,omitempty"`
TargetBranch *string `url:"target_branch,omitempty" json:"target_branch,omitempty"`
Search *string `url:"search,omitempty" json:"search,omitempty"`
In *SearchDomain `url:"in,omitempty" json:"in,omitempty"`
WIP *YesNo `url:"wip,omitempty" json:"wip,omitempty"`
}
type MergeRequestView = string
type Scope = string
type SortDirection = string
type MergeRequestState = string
type SearchDomain = string
type YesNo = string
// The values options that take known strings
const (
AssignedToMe Scope = "assigned_to_me"
CreatedByMe Scope = "created_by_me"
All Scope = "all"
SimpleView MergeRequestView = "simple"
Asc SortDirection = "asc"
Desc SortDirection = "desc"
Opened MergeRequestState = "opened"
Closed MergeRequestState = "closed"
Locked MergeRequestState = "locked"
Merged MergeRequestState = "merged"
InTitle SearchDomain = "title"
InDescription SearchDomain = "description"
InTitleOrDescription SearchDomain = "title,description"
Yes YesNo = "yes"
No YesNo = "no"
)
State *string `url:"state,omitempty" json:"state,omitempty"`
OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
Milestone *string `url:"milestone,omitempty" json:"milestone,omitempty"`
View *string `url:"view,omitempty" json:"view,omitempty"`
Labels Labels `url:"labels,omitempty" json:"labels,omitempty"`
CreatedAfter *time.Time `url:"created_after,omitempty" json:"created_after,omitempty"`
CreatedBefore *time.Time `url:"created_before,omitempty" json:"created_before,omitempty"`
UpdatedAfter *time.Time `url:"updated_after,omitempty" json:"updated_after,omitempty"`
UpdatedBefore *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"`
Scope *string `url:"scope,omitempty" json:"scope,omitempty"`
AuthorID *int `url:"author_id,omitempty" json:"author_id,omitempty"`
AssigneeID *int `url:"assignee_id,omitempty" json:"assignee_id,omitempty"`
MyReactionEmoji *string `url:"my_reaction_emoji,omitempty" json:"my_reaction_emoji,omitempty"`
SourceBranch *string `url:"source_branch,omitempty" json:"source_branch,omitempty"`
TargetBranch *string `url:"target_branch,omitempty" json:"target_branch,omitempty"`
Search *string `url:"search,omitempty" json:"search,omitempty"`
In *string `url:"in,omitempty" json:"in,omitempty"`
WIP *string `url:"wip,omitempty" json:"wip,omitempty"`
}
// ListMergeRequests gets all merge requests. The state parameter can be used
// to get only merge requests with a given state (opened, closed, or merged)
......@@ -268,25 +232,25 @@ func (s *MergeRequestsService) ListGroupMergeRequests(gid interface{}, opt *List
// https://docs.gitlab.com/ce/api/merge_requests.html#list-project-merge-requests
type ListProjectMergeRequestsOptions struct {
ListOptions
IIDs []int `url:"iids[],omitempty" json:"iids,omitempty"`
State *MergeRequestState `url:"state,omitempty" json:"state,omitempty"`
OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
Sort *SortDirection `url:"sort,omitempty" json:"sort,omitempty"`
Milestone *string `url:"milestone,omitempty" json:"milestone,omitempty"`
View *MergeRequestView `url:"view,omitempty" json:"view,omitempty"`
Labels Labels `url:"labels,omitempty" json:"labels,omitempty"`
CreatedAfter *time.Time `url:"created_after,omitempty" json:"created_after,omitempty"`
CreatedBefore *time.Time `url:"created_before,omitempty" json:"created_before,omitempty"`
UpdatedAfter *time.Time `url:"updated_after,omitempty" json:"updated_after,omitempty"`
UpdatedBefore *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"`
Scope *Scope `url:"scope,omitempty" json:"scope,omitempty"`
AuthorID *int `url:"author_id,omitempty" json:"author_id,omitempty"`
AssigneeID *int `url:"assignee_id,omitempty" json:"assignee_id,omitempty"`
MyReactionEmoji *string `url:"my_reaction_emoji,omitempty" json:"my_reaction_emoji,omitempty"`
SourceBranch *string `url:"source_branch,omitempty" json:"source_branch,omitempty"`
TargetBranch *string `url:"target_branch,omitempty" json:"target_branch,omitempty"`
Search *SearchDomain `url:"search,omitempty" json:"search,omitempty"`
WIP *YesNo `url:"wip,omitempty" json:"wip,omitempty"`
IIDs []int `url:"iids[],omitempty" json:"iids,omitempty"`
State *string `url:"state,omitempty" json:"state,omitempty"`
OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
Milestone *string `url:"milestone,omitempty" json:"milestone,omitempty"`
View *string `url:"view,omitempty" json:"view,omitempty"`
Labels Labels `url:"labels,omitempty" json:"labels,omitempty"`
CreatedAfter *time.Time `url:"created_after,omitempty" json:"created_after,omitempty"`
CreatedBefore *time.Time `url:"created_before,omitempty" json:"created_before,omitempty"`
UpdatedAfter *time.Time `url:"updated_after,omitempty" json:"updated_after,omitempty"`
UpdatedBefore *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"`
Scope *string `url:"scope,omitempty" json:"scope,omitempty"`
AuthorID *int `url:"author_id,omitempty" json:"author_id,omitempty"`
AssigneeID *int `url:"assignee_id,omitempty" json:"assignee_id,omitempty"`
MyReactionEmoji *string `url:"my_reaction_emoji,omitempty" json:"my_reaction_emoji,omitempty"`
SourceBranch *string `url:"source_branch,omitempty" json:"source_branch,omitempty"`
TargetBranch *string `url:"target_branch,omitempty" json:"target_branch,omitempty"`
Search *string `url:"search,omitempty" json:"search,omitempty"`
WIP *string `url:"wip,omitempty" json:"wip,omitempty"`
}
// ListProjectMergeRequests gets all merge requests for this project.
......@@ -437,7 +401,7 @@ func (s *MergeRequestsService) GetMergeRequestChanges(pid interface{}, mergeRequ
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/merge_requests.html#list-mr-pipelines
func (s *MergeRequestsService) ListMergeRequestPipelines(pid interface{}, mergeRequest int, options ...OptionFunc) (PipelineList, *Response, error) {
func (s *MergeRequestsService) ListMergeRequestPipelines(pid interface{}, mergeRequest int, options ...OptionFunc) ([]*PipelineInfo, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
......@@ -449,7 +413,7 @@ func (s *MergeRequestsService) ListMergeRequestPipelines(pid interface{}, mergeR
return nil, nil, err
}
var p PipelineList
var p []*PipelineInfo
resp, err := s.client.Do(req, &p)
if err != nil {
return nil, resp, err
......
......@@ -10,7 +10,7 @@ import (
)
var (
ajk = MergeRequestUser{
ajk = BasicUser{
ID: 3614858,
Name: "Alex Kalderimis",
Username: "alexkalderimis",
......@@ -18,7 +18,7 @@ var (
AvatarURL: "https://assets.gitlab-static.net/uploads/-/system/user/avatar/3614858/avatar.png",
WebURL: "https://gitlab.com/alexkalderimis",
}
tk = MergeRequestUser{
tk = BasicUser{
ID: 2535118,
Name: "Thong Kuah",
Username: "tkuah",
......@@ -108,7 +108,7 @@ func TestGetMergeRequest(t *testing.T) {
require.Equal(t, mergeRequest.MergeStatus, "can_be_merged")
require.Equal(t, mergeRequest.Author, &ajk)
require.Equal(t, mergeRequest.Assignee, &tk)
require.Equal(t, mergeRequest.Assignees, []*MergeRequestUser{&tk})
require.Equal(t, mergeRequest.Assignees, []*BasicUser{&tk})
require.Equal(t, mergeRequest.Labels, labels)
require.Equal(t, mergeRequest.Squash, true)
require.Equal(t, mergeRequest.UserNotesCount, 245)
......@@ -137,7 +137,7 @@ func TestListProjectMergeRequests(t *testing.T) {
require.NoError(t, err)
require.Equal(t, 20, len(mergeRequests))
validStates := []MergeRequestState{Opened, Closed, Locked, Merged}
validStates := []string{"opened", "closed", "locked", "merged"}
mergeStatuses := []string{"can_be_merged", "cannot_be_merged"}
allCreatedBefore := time.Date(2019, 8, 21, 0, 0, 0, 0, time.UTC)
allCreatedAfter := time.Date(2019, 8, 17, 0, 0, 0, 0, time.UTC)
......
......@@ -75,15 +75,10 @@ type DetailedStatus struct {
Favicon string `json:"favicon"`
}
func (i Pipeline) String() string {
return Stringify(i)
func (p Pipeline) String() string {
return Stringify(p)
}
// PipelineList represents a GitLab list project pipelines
//
// GitLab API docs: https://docs.gitlab.com/ce/api/pipelines.html#list-project-pipelines
type PipelineList []*PipelineInfo
// PipelineInfo shows the basic entities of a pipeline, mostly used as fields
// on other assets, like Commit.
type PipelineInfo struct {
......@@ -94,8 +89,8 @@ type PipelineInfo struct {
WebURL string `json:"web_url"`
}
func (i PipelineList) String() string {
return Stringify(i)
func (p PipelineInfo) String() string {
return Stringify(p)
}
// ListProjectPipelinesOptions represents the available ListProjectPipelines() options.
......@@ -117,7 +112,7 @@ type ListProjectPipelinesOptions struct {
// ListProjectPipelines gets a list of project piplines.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/pipelines.html#list-project-pipelines
func (s *PipelinesService) ListProjectPipelines(pid interface{}, opt *ListProjectPipelinesOptions, options ...OptionFunc) (PipelineList, *Response, error) {
func (s *PipelinesService) ListProjectPipelines(pid interface{}, opt *ListProjectPipelinesOptions, options ...OptionFunc) ([]*PipelineInfo, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
......@@ -129,11 +124,12 @@ func (s *PipelinesService) ListProjectPipelines(pid interface{}, opt *ListProjec
return nil, nil, err
}
var p PipelineList
var p []*PipelineInfo
resp, err := s.client.Do(req, &p)
if err != nil {
return nil, resp, err
}
return p, resp, err
}
......
......@@ -22,7 +22,7 @@ func TestListProjectPipelines(t *testing.T) {
t.Errorf("Pipelines.ListProjectPipelines returned error: %v", err)
}
want := PipelineList{{ID: 1}, {ID: 2}}
want := []*PipelineInfo{{ID: 1}, {ID: 2}}
if !reflect.DeepEqual(want, piplines) {
t.Errorf("Pipelines.ListProjectPipelines returned %+v, want %+v", piplines, want)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment