Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 44 additions & 4 deletions examples/projects/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,24 @@ func main() {
var method string
flag.StringVar(&method, "m", "", "Specify method to retrieve projects infos, available methods:\n"+
" > -m projects\n"+
" > -m project -id PROJECT_ID\n"+
" > -m hooks -id PROJECT_ID\n"+
" > -m branches -id PROJECT_ID\n"+
" > -m team -id PROJECT_ID")
" > -m project -id PROJECT_ID\n"+
" > -m hooks -id PROJECT_ID\n"+
" > -m branches -id PROJECT_ID\n"+
" > -m team -id PROJECT_ID\n"+
" > -m merge_requests -id PROJECT_ID [-state <all|merged|opened|closed>] [-order <created_at|updated_at>] [-sort <asc|desc>]")

var id string
flag.StringVar(&id, "id", "", "Specify repository id")

var state string
flag.StringVar(&state, "state", "", "Specify merge request state")

var order string
flag.StringVar(&order, "order", "", "Specify merge request order")

var sort string
flag.StringVar(&sort, "sort", "", "Specify merge request sort")

flag.Usage = func() {
fmt.Printf("Usage:\n")
flag.PrintDefaults()
Expand Down Expand Up @@ -158,5 +168,35 @@ func main() {
for _, member := range members {
fmt.Printf("> [%d] %s (%s) since %s\n", member.Id, member.Username, member.Name, member.CreatedAt)
}

case "merge_requests":
fmt.Println("Fetching project merge requests...")

if id == "" {
flag.Usage()
return
}

var params map[string]string = make(map[string]string)
if state != "" {
params["state"] = state
}
if order != "" {
params["order_by"] = order
}
if sort != "" {
params["sort"] = sort
}

mrs, err := gitlab.ProjectMergeRequests(id, params)
if err != nil {
fmt.Println(err.Error())
return
}

for _, mr := range mrs {
fmt.Printf("> [%d] %s (+%d) by %s on %s.\n", mr.Id, mr.Title, mr.Upvotes, mr.Author.Name, mr.CreatedAt)
}

}
}
2 changes: 2 additions & 0 deletions merge_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type MergeRequest struct {
ProjectId int `json:"project_id,omitempty"`
Title string `json:"title,omitempty"`
State string `json:"state,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
Upvotes int `json:"upvotes,omitempty"`
Downvotes int `json:"downvotes,omitempty"`
Author *User `json:"author,omitempty"`
Expand Down
2 changes: 2 additions & 0 deletions stubs/merge_requests/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"project_id": 3,
"title": "test1",
"state": "opened",
"created_at": "2016-05-20T13:58:19.283Z",
"updated_at": "2016-05-20T13:58:19.283Z",
"upvotes": 0,
"downvotes": 0,
"author": {
Expand Down
2 changes: 2 additions & 0 deletions stubs/merge_requests/show.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"project_id": 3,
"title": "test1",
"state": "merged",
"created_at": "2016-05-20T13:58:19.283Z",
"updated_at": "2016-05-20T13:58:19.283Z",
"upvotes": 0,
"downvotes": 0,
"author": {
Expand Down