From aa6515cf1e6f5a9f4f248a32347f65e09f110101 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Jan 24 2017 19:05:56 +0000 Subject: [PATCH 1/5] *: `gofmt -s -w .` Signed-off-by: Vincent Batts --- diff --git a/implementation.go b/implementation.go index fc13c34..bd8be80 100644 --- a/implementation.go +++ b/implementation.go @@ -1,4 +1,4 @@ -/** +/** * Copyright (c) 2016, Patrick Uiterwijk * All rights reserved. * @@ -21,84 +21,84 @@ package gopagure import ( - "strings" - "bytes" - "net/url" - "net/http" - "io/ioutil" - "encoding/json" + "bytes" + "encoding/json" + "io/ioutil" + "net/http" + "net/url" + "strings" ) func (e *PagureError) Error() string { - if e.Internal { - return "GoPagure: " + e.What - } else { - return "Pagure: " + e.What - } + if e.Internal { + return "GoPagure: " + e.What + } else { + return "Pagure: " + e.What + } } func (p *Pagure) call(anonymous bool, - urlParts []string, - post bool, - arguments map[string]string) ([]byte, error) { + urlParts []string, + post bool, + arguments map[string]string) ([]byte, error) { - if !anonymous && p.anonymous { - return nil, &PagureError{ - true, - "Non-anonymous session required", - } - } + if !anonymous && p.anonymous { + return nil, &PagureError{ + true, + "Non-anonymous session required", + } + } - u, _ := url.Parse(p.instanceUrl) - u.Path = "api/0/" + u, _ := url.Parse(p.instanceUrl) + u.Path = "api/0/" - if !anonymous { - u.Path += p.project + "/" - } + if !anonymous { + u.Path += p.project + "/" + } - u.Path += strings.Join(urlParts, "/") - q := url.Values{} - for k, v := range arguments { - if v != "" { - q.Add(k, v) - } - } - if !post { - u.RawQuery = q.Encode() - } + u.Path += strings.Join(urlParts, "/") + q := url.Values{} + for k, v := range arguments { + if v != "" { + q.Add(k, v) + } + } + if !post { + u.RawQuery = q.Encode() + } - var req *http.Request - var err error - if post { - req, err = http.NewRequest("POST", u.String(), bytes.NewReader([]byte(q.Encode()))) - req.Header.Add("Content-Type", "application/x-www-form-urlencoded") - } else { - req, err = http.NewRequest("GET", u.String(), nil) - } - if err != nil { - return nil, err - } - if !anonymous { - req.Header.Set("Authorization", "token " + p.apikey) - } + var req *http.Request + var err error + if post { + req, err = http.NewRequest("POST", u.String(), bytes.NewReader([]byte(q.Encode()))) + req.Header.Add("Content-Type", "application/x-www-form-urlencoded") + } else { + req, err = http.NewRequest("GET", u.String(), nil) + } + if err != nil { + return nil, err + } + if !anonymous { + req.Header.Set("Authorization", "token "+p.apikey) + } - res, err := http.DefaultClient.Do(req) - if err != nil { - return nil, err - } - body, err := ioutil.ReadAll(res.Body) - if err != nil { - return nil, err - } + res, err := http.DefaultClient.Do(req) + if err != nil { + return nil, err + } + body, err := ioutil.ReadAll(res.Body) + if err != nil { + return nil, err + } - var errorResult errorResponse - err = json.Unmarshal(body, &errorResult) - if err != nil { - return nil, err - } - if errorResult.Error != "" { - return nil, &PagureError{false, errorResult.Error} - } + var errorResult errorResponse + err = json.Unmarshal(body, &errorResult) + if err != nil { + return nil, err + } + if errorResult.Error != "" { + return nil, &PagureError{false, errorResult.Error} + } - return body, nil + return body, nil } diff --git a/public-issues.go b/public-issues.go index d10c48d..66cb062 100644 --- a/public-issues.go +++ b/public-issues.go @@ -1,4 +1,4 @@ -/** +/** * Copyright (c) 2016, Patrick Uiterwijk * All rights reserved. * @@ -21,102 +21,102 @@ package gopagure import ( - "encoding/json" - "strconv" + "encoding/json" + "strconv" ) func (p *Pagure) IssueCreate(title string, - content string, - private bool) error { + content string, + private bool) error { - arguments := make(map[string]string) - arguments["title"] = title - arguments["issue_content"] = content - arguments["private"] = strconv.FormatBool(private) + arguments := make(map[string]string) + arguments["title"] = title + arguments["issue_content"] = content + arguments["private"] = strconv.FormatBool(private) - _, err := p.call(false, []string{"new_issue"}, true, arguments) - if err != nil { - return err - } - return nil + _, err := p.call(false, []string{"new_issue"}, true, arguments) + if err != nil { + return err + } + return nil } func (p *Pagure) IssueList(status string, - tags string, - assignee string, - author string) ([]Issue, error) { + tags string, + assignee string, + author string) ([]Issue, error) { - arguments := make(map[string]string) - if status != "" { - arguments["status"] = status - } - if tags != "" { - arguments["tags"] = tags - } - if assignee != "" { - arguments["assignee"] = assignee - } - if author != "" { - arguments["author"] = author - } + arguments := make(map[string]string) + if status != "" { + arguments["status"] = status + } + if tags != "" { + arguments["tags"] = tags + } + if assignee != "" { + arguments["assignee"] = assignee + } + if author != "" { + arguments["author"] = author + } - resp, err := p.call(false, []string{"issues"}, false, arguments) - if err != nil { - return nil, err - } - var result issueListResponse - err = json.Unmarshal(resp, &result) - if err != nil { - return nil, err - } - return result.Issues, nil + resp, err := p.call(false, []string{"issues"}, false, arguments) + if err != nil { + return nil, err + } + var result issueListResponse + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, err + } + return result.Issues, nil } func (p *Pagure) IssueInfo(issue int) (Issue, error) { - arguments := make(map[string]string) - resp, err := p.call(false, []string{"issue", strconv.Itoa(issue)}, false, arguments) - if err != nil { - return Issue{}, err - } - var result Issue - err = json.Unmarshal(resp, &result) - if err != nil { - return Issue{}, err - } - return result, nil + arguments := make(map[string]string) + resp, err := p.call(false, []string{"issue", strconv.Itoa(issue)}, false, arguments) + if err != nil { + return Issue{}, err + } + var result Issue + err = json.Unmarshal(resp, &result) + if err != nil { + return Issue{}, err + } + return result, nil } func (p *Pagure) IssueCommentInfo(issue int, comment int) (Comment, error) { - arguments := make(map[string]string) - resp, err := p.call(false, - []string{"issue", - strconv.Itoa(issue), - "comment", - strconv.Itoa(comment)}, - false, - arguments) - if err != nil { - return Comment{}, err - } - var result Comment - err = json.Unmarshal(resp, &result) - if err != nil { - return Comment{}, err - } - return result, nil + arguments := make(map[string]string) + resp, err := p.call(false, + []string{"issue", + strconv.Itoa(issue), + "comment", + strconv.Itoa(comment)}, + false, + arguments) + if err != nil { + return Comment{}, err + } + var result Comment + err = json.Unmarshal(resp, &result) + if err != nil { + return Comment{}, err + } + return result, nil } func (p *Pagure) IssueComment(issue int, - comment string) error { + comment string) error { - arguments := make(map[string]string) - arguments["comment"] = comment + arguments := make(map[string]string) + arguments["comment"] = comment - _, err := p.call(false, []string{"issue", strconv.Itoa(issue), "comment"}, true, arguments) - if err != nil { - return err - } - return nil + _, err := p.call(false, []string{"issue", strconv.Itoa(issue), "comment"}, true, arguments) + if err != nil { + return err + } + return nil } diff --git a/public-projects.go b/public-projects.go index 331f92c..355a084 100644 --- a/public-projects.go +++ b/public-projects.go @@ -1,4 +1,4 @@ -/** +/** * Copyright (c) 2016, Patrick Uiterwijk * All rights reserved. * @@ -21,73 +21,73 @@ package gopagure import ( - "encoding/json" - "strconv" + "encoding/json" + "strconv" ) func (p *Pagure) ProjectCreate(projectname string, - description string, - namespace string, - url string, - avatar_email string, - create_readme bool) error { + description string, + namespace string, + url string, + avatar_email string, + create_readme bool) error { - arguments := make(map[string]string) - arguments["projectname"] = projectname - arguments["description"] = description - if namespace != "" { - arguments["namespace"] = namespace - } - if url != "" { - arguments["url"] = url - } - if avatar_email != "" { - arguments["avatar_email"] = avatar_email - } - arguments["create_readme"] = strconv.FormatBool(create_readme) + arguments := make(map[string]string) + arguments["projectname"] = projectname + arguments["description"] = description + if namespace != "" { + arguments["namespace"] = namespace + } + if url != "" { + arguments["url"] = url + } + if avatar_email != "" { + arguments["avatar_email"] = avatar_email + } + arguments["create_readme"] = strconv.FormatBool(create_readme) - _, err := p.call(true, []string{"projects"}, false, arguments) - if err != nil { - return err - } - return nil + _, err := p.call(true, []string{"projects"}, false, arguments) + if err != nil { + return err + } + return nil } func (p *Pagure) ProjectListTags() ([]string, error) { - resp, err := p.call(false, []string{"git", "tags"}, false, nil) - if err != nil { - return nil, err - } - var result projectListTagsResponse - err = json.Unmarshal(resp, &result) - if err != nil { - return nil, err - } - return result.Tags, nil + resp, err := p.call(false, []string{"git", "tags"}, false, nil) + if err != nil { + return nil, err + } + var result projectListTagsResponse + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, err + } + return result.Tags, nil } func (p *Pagure) ProjectList(tags string, - pattern string, - username string, - fork bool) ([]Project, error) { - arguments := make(map[string]string) - if tags != "" { - arguments["tags"] = tags - } - if pattern != "" { - arguments["pattern"] = pattern - } - if username != "" { - arguments["username"] = username - } - resp, err := p.call(true, []string{"projects"}, false, arguments) - if err != nil { - return nil, err - } - var result projectListResponse - err = json.Unmarshal(resp, &result) - if err != nil { - return nil, err - } - return result.Projects, nil + pattern string, + username string, + fork bool) ([]Project, error) { + arguments := make(map[string]string) + if tags != "" { + arguments["tags"] = tags + } + if pattern != "" { + arguments["pattern"] = pattern + } + if username != "" { + arguments["username"] = username + } + resp, err := p.call(true, []string{"projects"}, false, arguments) + if err != nil { + return nil, err + } + var result projectListResponse + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, err + } + return result.Projects, nil } diff --git a/public-pullrequests.go b/public-pullrequests.go index 7152e3e..84e2e68 100644 --- a/public-pullrequests.go +++ b/public-pullrequests.go @@ -1,4 +1,4 @@ -/** +/** * Copyright (c) 2016, Patrick Uiterwijk * All rights reserved. * @@ -21,127 +21,127 @@ package gopagure import ( - "encoding/json" - "strconv" + "encoding/json" + "strconv" ) func (p *Pagure) PullRequestList(status string, - assignee string, - author string) ([]PullRequest, error) { - - arguments := make(map[string]string) - if status != "" { - arguments["status"] = status - } - if assignee != "" { - arguments["assignee"] = assignee - } - if author != "" { - arguments["author"] = author - } - - resp, err := p.call(false, []string{"pull-requests"}, false, arguments) - if err != nil { - return nil, err - } - var result pullRequestListResponse - err = json.Unmarshal(resp, &result) - if err != nil { - return nil, err - } - return result.Requests, nil + assignee string, + author string) ([]PullRequest, error) { + + arguments := make(map[string]string) + if status != "" { + arguments["status"] = status + } + if assignee != "" { + arguments["assignee"] = assignee + } + if author != "" { + arguments["author"] = author + } + + resp, err := p.call(false, []string{"pull-requests"}, false, arguments) + if err != nil { + return nil, err + } + var result pullRequestListResponse + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, err + } + return result.Requests, nil } func (p *Pagure) PullRequestInfo(id int) (PullRequest, error) { - arguments := make(map[string]string) - - resp, err := p.call(false, []string{"pull-request", strconv.Itoa(id)}, false, arguments) - if err != nil { - return PullRequest{}, err - } - var result PullRequest - err = json.Unmarshal(resp, &result) - if err != nil { - return PullRequest{}, err - } - return result, nil + arguments := make(map[string]string) + + resp, err := p.call(false, []string{"pull-request", strconv.Itoa(id)}, false, arguments) + if err != nil { + return PullRequest{}, err + } + var result PullRequest + err = json.Unmarshal(resp, &result) + if err != nil { + return PullRequest{}, err + } + return result, nil } func (p *Pagure) PullRequestMerge(id int) error { - arguments := make(map[string]string) + arguments := make(map[string]string) - _, err := p.call(false, []string{"pull-request", strconv.Itoa(id), "merge"}, true, arguments) - if err != nil { - return err - } - return nil + _, err := p.call(false, []string{"pull-request", strconv.Itoa(id), "merge"}, true, arguments) + if err != nil { + return err + } + return nil } func (p *Pagure) PullRequestClose(id int) error { - arguments := make(map[string]string) + arguments := make(map[string]string) - _, err := p.call(false, []string{"pull-request", strconv.Itoa(id), "close"}, true, arguments) - if err != nil { - return err - } - return nil + _, err := p.call(false, []string{"pull-request", strconv.Itoa(id), "close"}, true, arguments) + if err != nil { + return err + } + return nil } func (p *Pagure) PullRequestComment(id int, - comment string, - commit string, - filename string, - row int, - tree_id string) error { - - arguments := make(map[string]string) - arguments["comment"] = comment - if commit != "" { - arguments["commit"] = commit - } - if filename != "" { - arguments["filename"] = filename - } - if row != 0 { - arguments["row"] = strconv.Itoa(row) - } - if tree_id != "" { - arguments["tree_id"] = tree_id - } - - _, err := p.call(false, []string{"pull-request", strconv.Itoa(id), "comment"}, true, arguments) - if err != nil { - return err - } - return nil + comment string, + commit string, + filename string, + row int, + tree_id string) error { + + arguments := make(map[string]string) + arguments["comment"] = comment + if commit != "" { + arguments["commit"] = commit + } + if filename != "" { + arguments["filename"] = filename + } + if row != 0 { + arguments["row"] = strconv.Itoa(row) + } + if tree_id != "" { + arguments["tree_id"] = tree_id + } + + _, err := p.call(false, []string{"pull-request", strconv.Itoa(id), "comment"}, true, arguments) + if err != nil { + return err + } + return nil } func (p *Pagure) PullRequestFlag(id int, - username string, - percent int, - comment string, - url string, - uid string, - commit string) error { - - arguments := make(map[string]string) - arguments["username"] = username - arguments["percent"] = strconv.Itoa(percent) - arguments["comment"] = comment - arguments["url"] = url - if uid != "" { - arguments["uid"] = uid - } - if commit != "" { - arguments["commit"] = commit - } - - _, err := p.call(false, []string{"pull-request", strconv.Itoa(id), "flag"}, true, arguments) - if err != nil { - return err - } - return nil + username string, + percent int, + comment string, + url string, + uid string, + commit string) error { + + arguments := make(map[string]string) + arguments["username"] = username + arguments["percent"] = strconv.Itoa(percent) + arguments["comment"] = comment + arguments["url"] = url + if uid != "" { + arguments["uid"] = uid + } + if commit != "" { + arguments["commit"] = commit + } + + _, err := p.call(false, []string{"pull-request", strconv.Itoa(id), "flag"}, true, arguments) + if err != nil { + return err + } + return nil } diff --git a/public-types.go b/public-types.go index 3e770cc..64e92fd 100644 --- a/public-types.go +++ b/public-types.go @@ -1,4 +1,4 @@ -/** +/** * Copyright (c) 2016, Patrick Uiterwijk * All rights reserved. * @@ -21,79 +21,79 @@ package gopagure type Pagure struct { - instanceUrl string - anonymous bool - project string - apikey string + instanceUrl string + anonymous bool + project string + apikey string } type PagureError struct { - Internal bool - What string + Internal bool + What string } type User struct { - Fullname string - Name string + Fullname string + Name string } type Comment struct { - Comment string - Date_Created string - Edited_On string - Editor User - Id int - Notifications bool - Parent Project - User User + Comment string + Date_Created string + Edited_On string + Editor User + Id int + Notifications bool + Parent Project + User User } type Project struct { - Date_Created string - Description string - Id int - Name string - Parent *Project - User User + Date_Created string + Description string + Id int + Name string + Parent *Project + User User } type Issue struct { - Assignee User - Blocks []string - Comments []Comment - Content string - Date_Created string - Depends []int - Id int - Private bool - Status string - Tags []string - Title string - User User + Assignee User + Blocks []string + Comments []Comment + Content string + Date_Created string + Depends []int + Id int + Private bool + Status string + Tags []string + Title string + User User } type UserInfo struct { - Forks []Project - Repos []Project - User User + Forks []Project + Repos []Project + User User } type PullRequest struct { - Assignee User - Branch string - Branch_From string - Closed_At string - Closed_By User - Comments []Comment - Commit_Start string - Commit_Stop string - Date_Created string - Id int - Project Project - Repo_From Project - Status string - Title string - Uid string - Updated_On string - User User + Assignee User + Branch string + Branch_From string + Closed_At string + Closed_By User + Comments []Comment + Commit_Start string + Commit_Stop string + Date_Created string + Id int + Project Project + Repo_From Project + Status string + Title string + Uid string + Updated_On string + User User } diff --git a/public-users.go b/public-users.go index 08f6dc0..73c505b 100644 --- a/public-users.go +++ b/public-users.go @@ -1,4 +1,4 @@ -/** +/** * Copyright (c) 2016, Patrick Uiterwijk * All rights reserved. * @@ -21,59 +21,59 @@ package gopagure import ( - "encoding/json" + "encoding/json" ) func (p *Pagure) UserList(pattern string) ([]string, error) { - arguments := make(map[string]string) - if pattern != "" { - arguments["pattern"] = pattern - } + arguments := make(map[string]string) + if pattern != "" { + arguments["pattern"] = pattern + } - resp, err := p.call(true, []string{"users"}, false, arguments) - if err != nil { - return nil, err - } - var result userListResponse - err = json.Unmarshal(resp, &result) - if err != nil { - return nil, err - } - return result.Users, nil + resp, err := p.call(true, []string{"users"}, false, arguments) + if err != nil { + return nil, err + } + var result userListResponse + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, err + } + return result.Users, nil } func (p *Pagure) UserInfo(username string) (UserInfo, error) { - arguments := make(map[string]string) + arguments := make(map[string]string) - resp, err := p.call(true, []string{"user", username}, false, arguments) - if err != nil { - return UserInfo{}, err - } - var result UserInfo - err = json.Unmarshal(resp, &result) - if err != nil { - return UserInfo{}, err - } - return result, nil + resp, err := p.call(true, []string{"user", username}, false, arguments) + if err != nil { + return UserInfo{}, err + } + var result UserInfo + err = json.Unmarshal(resp, &result) + if err != nil { + return UserInfo{}, err + } + return result, nil } func (p *Pagure) UserListGroups(pattern string) ([]string, error) { - arguments := make(map[string]string) - if pattern != "" { - arguments["pattern"] = pattern - } + arguments := make(map[string]string) + if pattern != "" { + arguments["pattern"] = pattern + } - resp, err := p.call(true, []string{"groups"}, false, arguments) - if err != nil { - return nil, err - } - var result userListGroupsResponse - err = json.Unmarshal(resp, &result) - if err != nil { - return nil, err - } - return result.Groups, nil + resp, err := p.call(true, []string{"groups"}, false, arguments) + if err != nil { + return nil, err + } + var result userListGroupsResponse + err = json.Unmarshal(resp, &result) + if err != nil { + return nil, err + } + return result.Groups, nil } diff --git a/public.go b/public.go index 4de770c..b274fb3 100644 --- a/public.go +++ b/public.go @@ -1,4 +1,4 @@ -/** +/** * Copyright (c) 2016, Patrick Uiterwijk * All rights reserved. * @@ -21,21 +21,21 @@ package gopagure import ( - "net/url" + "net/url" ) func CreateInstance(instanceUrl string, project string, apikey string) (Pagure, error) { - _, err := url.Parse(instanceUrl) - if err != nil { - return Pagure{}, err - } - return Pagure{instanceUrl, false, project, apikey}, nil + _, err := url.Parse(instanceUrl) + if err != nil { + return Pagure{}, err + } + return Pagure{instanceUrl, false, project, apikey}, nil } func CreateAnonymousInstance(instanceUrl string) (Pagure, error) { - _, err := url.Parse(instanceUrl) - if err != nil { - return Pagure{}, err - } - return Pagure{instanceUrl, true, "", ""}, nil + _, err := url.Parse(instanceUrl) + if err != nil { + return Pagure{}, err + } + return Pagure{instanceUrl, true, "", ""}, nil } diff --git a/responsetypes.go b/responsetypes.go index 187d2aa..d9ebe07 100644 --- a/responsetypes.go +++ b/responsetypes.go @@ -1,4 +1,4 @@ -/** +/** * Copyright (c) 2016, Patrick Uiterwijk * All rights reserved. * @@ -21,35 +21,35 @@ package gopagure type errorResponse struct { - Error string + Error string } type projectListTagsResponse struct { - Total_tags int - Tags []string + Total_tags int + Tags []string } type projectListResponse struct { - Total_projects int - Projects []Project + Total_projects int + Projects []Project } type issueListResponse struct { - Total_issues int - Issues []Issue + Total_issues int + Issues []Issue } type userListResponse struct { - Total_Users int - Users []string + Total_Users int + Users []string } type userListGroupsResponse struct { - Total_Groups int - Groups []string + Total_Groups int + Groups []string } type pullRequestListResponse struct { - Total_Requests int - Requests []PullRequest + Total_Requests int + Requests []PullRequest } From f64da2748314aff828f7736345867bd3b4eae893 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Jan 24 2017 19:07:02 +0000 Subject: [PATCH 2/5] implementation: golint if block ends with a return statement, so drop this else and outdent its block Signed-off-by: Vincent Batts --- diff --git a/implementation.go b/implementation.go index bd8be80..e776e9b 100644 --- a/implementation.go +++ b/implementation.go @@ -32,9 +32,8 @@ import ( func (e *PagureError) Error() string { if e.Internal { return "GoPagure: " + e.What - } else { - return "Pagure: " + e.What } + return "Pagure: " + e.What } func (p *Pagure) call(anonymous bool, From 6ea672802a09b80313cf796bdec587fd5cb0de93 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Jan 24 2017 19:18:16 +0000 Subject: [PATCH 3/5] *: camelCase instead of underscores golang have made a norm of not using underscores in variable or field names. This switches over underscores to camelCase and fixes where this affects json marshalling. Signed-off-by: Vincent Batts --- diff --git a/public-projects.go b/public-projects.go index 355a084..ffad08f 100644 --- a/public-projects.go +++ b/public-projects.go @@ -29,8 +29,8 @@ func (p *Pagure) ProjectCreate(projectname string, description string, namespace string, url string, - avatar_email string, - create_readme bool) error { + avatarEmail string, + createReadme bool) error { arguments := make(map[string]string) arguments["projectname"] = projectname @@ -41,10 +41,10 @@ func (p *Pagure) ProjectCreate(projectname string, if url != "" { arguments["url"] = url } - if avatar_email != "" { - arguments["avatar_email"] = avatar_email + if avatarEmail != "" { + arguments["avatar_email"] = avatarEmail } - arguments["create_readme"] = strconv.FormatBool(create_readme) + arguments["create_readme"] = strconv.FormatBool(createReadme) _, err := p.call(true, []string{"projects"}, false, arguments) if err != nil { diff --git a/public-pullrequests.go b/public-pullrequests.go index 84e2e68..c8345df 100644 --- a/public-pullrequests.go +++ b/public-pullrequests.go @@ -95,7 +95,7 @@ func (p *Pagure) PullRequestComment(id int, commit string, filename string, row int, - tree_id string) error { + treeID string) error { arguments := make(map[string]string) arguments["comment"] = comment @@ -108,8 +108,8 @@ func (p *Pagure) PullRequestComment(id int, if row != 0 { arguments["row"] = strconv.Itoa(row) } - if tree_id != "" { - arguments["tree_id"] = tree_id + if treeID != "" { + arguments["tree_id"] = treeID } _, err := p.call(false, []string{"pull-request", strconv.Itoa(id), "comment"}, true, arguments) diff --git a/public-types.go b/public-types.go index 64e92fd..b59eee4 100644 --- a/public-types.go +++ b/public-types.go @@ -39,8 +39,8 @@ type User struct { type Comment struct { Comment string - Date_Created string - Edited_On string + DateCreated string `json:"date_created"` + EditedOn string `json:"edited_on"` Editor User Id int Notifications bool @@ -49,27 +49,27 @@ type Comment struct { } type Project struct { - Date_Created string - Description string - Id int - Name string - Parent *Project - User User + DateCreated string `json:"date_created"` + Description string + Id int + Name string + Parent *Project + User User } type Issue struct { - Assignee User - Blocks []string - Comments []Comment - Content string - Date_Created string - Depends []int - Id int - Private bool - Status string - Tags []string - Title string - User User + Assignee User + Blocks []string + Comments []Comment + Content string + DateCreated string `json:"date_created"` + Depends []int + Id int + Private bool + Status string + Tags []string + Title string + User User } type UserInfo struct { @@ -79,21 +79,21 @@ type UserInfo struct { } type PullRequest struct { - Assignee User - Branch string - Branch_From string - Closed_At string - Closed_By User - Comments []Comment - Commit_Start string - Commit_Stop string - Date_Created string - Id int - Project Project - Repo_From Project - Status string - Title string - Uid string - Updated_On string - User User + Assignee User + Branch string + BranchFrom string `json:"branch_from"` + ClosedAt string `json:"closed_at"` + ClosedBy User `json:"closed_by"` + Comments []Comment + CommitStart string `json:"commit_start"` + CommitStop string `json:"commit_stop"` + DateCreated string `json:"date_created"` + Id int + Project Project + RepoFrom Project `json:"repo_from"` + Status string + Title string + Uid string + UpdatedOn string `json:"updated_on"` + User User } diff --git a/responsetypes.go b/responsetypes.go index d9ebe07..b61635b 100644 --- a/responsetypes.go +++ b/responsetypes.go @@ -25,31 +25,31 @@ type errorResponse struct { } type projectListTagsResponse struct { - Total_tags int - Tags []string + TotalTags int `json:"total_tags"` + Tags []string } type projectListResponse struct { - Total_projects int - Projects []Project + TotalProjects int `json:"total_projects"` + Projects []Project } type issueListResponse struct { - Total_issues int - Issues []Issue + TotalIssues int `json:"total_issues"` + Issues []Issue } type userListResponse struct { - Total_Users int - Users []string + TotalUsers int `json:"total_users"` + Users []string } type userListGroupsResponse struct { - Total_Groups int - Groups []string + TotalGroups int `json:"total_groups"` + Groups []string } type pullRequestListResponse struct { - Total_Requests int - Requests []PullRequest + TotalRequests int `json:"total_requests"` + Requests []PullRequest } From 85cd0c09647e50f360e5c5f5d026567f8503fdb8 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Jan 24 2017 19:19:32 +0000 Subject: [PATCH 4/5] *: capitalizations Url -> URL Id -> ID Uid -> UID Signed-off-by: Vincent Batts --- diff --git a/implementation.go b/implementation.go index e776e9b..17c147b 100644 --- a/implementation.go +++ b/implementation.go @@ -48,7 +48,7 @@ func (p *Pagure) call(anonymous bool, } } - u, _ := url.Parse(p.instanceUrl) + u, _ := url.Parse(p.instanceURL) u.Path = "api/0/" if !anonymous { diff --git a/public-types.go b/public-types.go index b59eee4..35f855a 100644 --- a/public-types.go +++ b/public-types.go @@ -21,7 +21,7 @@ package gopagure type Pagure struct { - instanceUrl string + instanceURL string anonymous bool project string apikey string @@ -42,7 +42,7 @@ type Comment struct { DateCreated string `json:"date_created"` EditedOn string `json:"edited_on"` Editor User - Id int + ID int Notifications bool Parent Project User User @@ -51,7 +51,7 @@ type Comment struct { type Project struct { DateCreated string `json:"date_created"` Description string - Id int + ID int Name string Parent *Project User User @@ -64,7 +64,7 @@ type Issue struct { Content string DateCreated string `json:"date_created"` Depends []int - Id int + ID int Private bool Status string Tags []string @@ -88,12 +88,12 @@ type PullRequest struct { CommitStart string `json:"commit_start"` CommitStop string `json:"commit_stop"` DateCreated string `json:"date_created"` - Id int + ID int Project Project RepoFrom Project `json:"repo_from"` Status string Title string - Uid string + UID string UpdatedOn string `json:"updated_on"` User User } diff --git a/public.go b/public.go index b274fb3..a60d3d1 100644 --- a/public.go +++ b/public.go @@ -24,18 +24,18 @@ import ( "net/url" ) -func CreateInstance(instanceUrl string, project string, apikey string) (Pagure, error) { - _, err := url.Parse(instanceUrl) +func CreateInstance(instanceURL string, project string, apikey string) (Pagure, error) { + _, err := url.Parse(instanceURL) if err != nil { return Pagure{}, err } - return Pagure{instanceUrl, false, project, apikey}, nil + return Pagure{instanceURL, false, project, apikey}, nil } -func CreateAnonymousInstance(instanceUrl string) (Pagure, error) { - _, err := url.Parse(instanceUrl) +func CreateAnonymousInstance(instanceURL string) (Pagure, error) { + _, err := url.Parse(instanceURL) if err != nil { return Pagure{}, err } - return Pagure{instanceUrl, true, "", ""}, nil + return Pagure{instanceURL, true, "", ""}, nil } From 1ca187f955f11526fac1157b59ce19dfbb46fd1a Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Jan 24 2017 19:52:23 +0000 Subject: [PATCH 5/5] *: about half documented still half to go. If you just run `golint .` you'll see it. Signed-off-by: Vincent Batts --- diff --git a/README.md b/README.md index de260bd..0917877 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,5 @@ GoPagure ======== This is a Go API client for Pagure. + +View the docs at https://godoc.org/pagure.io/gopagure.git diff --git a/implementation.go b/implementation.go index 17c147b..b168774 100644 --- a/implementation.go +++ b/implementation.go @@ -29,6 +29,7 @@ import ( "strings" ) +// Error reports the error message (and satisfies the error interface) func (e *PagureError) Error() string { if e.Internal { return "GoPagure: " + e.What diff --git a/public-issues.go b/public-issues.go index 66cb062..291b931 100644 --- a/public-issues.go +++ b/public-issues.go @@ -25,10 +25,8 @@ import ( "strconv" ) -func (p *Pagure) IssueCreate(title string, - content string, - private bool) error { - +// IssueCreate opens a new issue for on this project session, on the pagure instance +func (p *Pagure) IssueCreate(title string, content string, private bool) error { arguments := make(map[string]string) arguments["title"] = title arguments["issue_content"] = content @@ -41,6 +39,11 @@ func (p *Pagure) IssueCreate(title string, return nil } +// IssueList fetches the issues for this project session, on the pagure instance. +// - `status` is the status of the issue (string can be empty) +// - `tags` for issue groups (string can be empty) +// - `assignee` is who issue is assigned to (string can be empty) +// - `author` of the issue (string can be empty) func (p *Pagure) IssueList(status string, tags string, assignee string, @@ -73,7 +76,6 @@ func (p *Pagure) IssueList(status string, } func (p *Pagure) IssueInfo(issue int) (Issue, error) { - arguments := make(map[string]string) resp, err := p.call(false, []string{"issue", strconv.Itoa(issue)}, false, arguments) if err != nil { @@ -88,7 +90,6 @@ func (p *Pagure) IssueInfo(issue int) (Issue, error) { } func (p *Pagure) IssueCommentInfo(issue int, comment int) (Comment, error) { - arguments := make(map[string]string) resp, err := p.call(false, []string{"issue", @@ -108,9 +109,8 @@ func (p *Pagure) IssueCommentInfo(issue int, comment int) (Comment, error) { return result, nil } -func (p *Pagure) IssueComment(issue int, - comment string) error { - +// IssueComment comments on the issue +func (p *Pagure) IssueComment(issue int, comment string) error { arguments := make(map[string]string) arguments["comment"] = comment diff --git a/public-projects.go b/public-projects.go index ffad08f..9a4beb7 100644 --- a/public-projects.go +++ b/public-projects.go @@ -25,6 +25,7 @@ import ( "strconv" ) +// ProjectCreate establishes a new project on the pagure instance func (p *Pagure) ProjectCreate(projectname string, description string, namespace string, @@ -53,6 +54,7 @@ func (p *Pagure) ProjectCreate(projectname string, return nil } +// ProjectListTags fetches the tags/releases for the project func (p *Pagure) ProjectListTags() ([]string, error) { resp, err := p.call(false, []string{"git", "tags"}, false, nil) if err != nil { @@ -66,6 +68,11 @@ func (p *Pagure) ProjectListTags() ([]string, error) { return result.Tags, nil } +// ProjectList fetches projects from the pagure instance that match provided criteria. +// - `tags` is the git tag (string can be empty) +// - `pattern` is the project name pattern (string can be empty) +// - `username` is the user that owns the proejct (string can be empty) +// - `fork` is whether to include forks of original projects in the list func (p *Pagure) ProjectList(tags string, pattern string, username string, diff --git a/public-users.go b/public-users.go index 73c505b..8f6d22e 100644 --- a/public-users.go +++ b/public-users.go @@ -24,8 +24,8 @@ import ( "encoding/json" ) +// UserList fetches the of users that matches the provided pattern func (p *Pagure) UserList(pattern string) ([]string, error) { - arguments := make(map[string]string) if pattern != "" { arguments["pattern"] = pattern @@ -43,8 +43,8 @@ func (p *Pagure) UserList(pattern string) ([]string, error) { return result.Users, nil } +// UserInfo fetches the information on the provided username func (p *Pagure) UserInfo(username string) (UserInfo, error) { - arguments := make(map[string]string) resp, err := p.call(true, []string{"user", username}, false, arguments) @@ -59,8 +59,8 @@ func (p *Pagure) UserInfo(username string) (UserInfo, error) { return result, nil } +// UserListGroups fetches the groups that match the provided pattern func (p *Pagure) UserListGroups(pattern string) ([]string, error) { - arguments := make(map[string]string) if pattern != "" { arguments["pattern"] = pattern diff --git a/public.go b/public.go index a60d3d1..89972fb 100644 --- a/public.go +++ b/public.go @@ -24,6 +24,7 @@ import ( "net/url" ) +// CreateInstance provides an authenitcated session to a Pagure instance, for a particular project func CreateInstance(instanceURL string, project string, apikey string) (Pagure, error) { _, err := url.Parse(instanceURL) if err != nil { @@ -32,6 +33,7 @@ func CreateInstance(instanceURL string, project string, apikey string) (Pagure, return Pagure{instanceURL, false, project, apikey}, nil } +// CreateAnonymousInstance provides an anonymous session to a Pagure instance func CreateAnonymousInstance(instanceURL string) (Pagure, error) { _, err := url.Parse(instanceURL) if err != nil {