Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Unified Diff: go/src/infra/monorail/endpoints.go

Issue 2056603002: [monorail go api] add IssuesList rpc (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: lowering test coverage Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | go/src/infra/monorail/monorail.infra_testing » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: go/src/infra/monorail/endpoints.go
diff --git a/go/src/infra/monorail/endpoints.go b/go/src/infra/monorail/endpoints.go
index fffac476a774b97aacd7a92689db71aea2a3ed1f..76a9910f6ef52e9d6f34dd5cceacb0a83c1f948c 100644
--- a/go/src/infra/monorail/endpoints.go
+++ b/go/src/infra/monorail/endpoints.go
@@ -11,6 +11,7 @@ import (
"io"
"io/ioutil"
"net/http"
+ "net/url"
"strings"
"golang.org/x/net/context"
@@ -46,7 +47,7 @@ func NewEndpointsClient(client *http.Client, url string) MonorailClient {
return &epClient{HTTP: client, url: strings.TrimSuffix(url, "/")}
}
-func (c *epClient) call(ctx context.Context, urlSuffix string, request, response interface{}) error {
+func (c *epClient) call(ctx context.Context, method, urlSuffix string, request, response interface{}) error {
client := c.HTTP
if client == nil {
client = http.DefaultClient
@@ -69,7 +70,7 @@ func (c *epClient) call(ctx context.Context, urlSuffix string, request, response
}
// Make an HTTP request.
- req, err := http.NewRequest("POST", c.url + urlSuffix, reqBuf)
+ req, err := http.NewRequest(method, c.url+urlSuffix, reqBuf)
if err != nil {
return fmt.Errorf("could not make a request to %s: %s", req.URL, err)
}
@@ -77,7 +78,7 @@ func (c *epClient) call(ctx context.Context, urlSuffix string, request, response
req.Header.Set("Accept", "application/json")
// Send the request.
- logging.Debugf(ctx, "POST %s %s", req.URL, reqBuf.Bytes())
+ logging.Debugf(ctx, "%s %s %s", method, req.URL, reqBuf.Bytes())
res, err := ctxhttp.Do(ctx, client, req)
if err != nil {
return errors.WrapTransient(err)
@@ -111,7 +112,7 @@ func (c *epClient) InsertIssue(ctx context.Context, req *InsertIssueRequest, opt
}
url := fmt.Sprintf("/projects/%s/issues?sendEmail=%v", req.ProjectId, req.SendEmail)
res := &InsertIssueResponse{&Issue{}}
- return res, c.call(ctx, url, &req.Issue, res.Issue)
+ return res, c.call(ctx, "POST", url, &req.Issue, res.Issue)
}
func (c *epClient) InsertComment(ctx context.Context, req *InsertCommentRequest, options ...grpc.CallOption) (*InsertCommentResponse, error) {
@@ -119,7 +120,35 @@ func (c *epClient) InsertComment(ctx context.Context, req *InsertCommentRequest,
return nil, err
}
url := fmt.Sprintf("/projects/%s/issues/%d/comments", req.Issue.ProjectId, req.Issue.IssueId)
- return &InsertCommentResponse{}, c.call(ctx, url, req.Comment, nil)
+ return &InsertCommentResponse{}, c.call(ctx, "POST", url, req.Comment, nil)
+}
+
+func (c *epClient) IssuesList(ctx context.Context, req *IssuesListRequest, options ...grpc.CallOption) (*IssuesListResponse, error) {
+ if err := checkOptions(options); err != nil {
+ return nil, err
+ }
+
+ args := url.Values{}
+ args.Set("can", strings.ToLower(req.Can.String()))
+ args.Set("q", req.Q)
+ args.Set("label", req.Label)
+ args.Set("maxResults", fmt.Sprintf("%d", req.MaxResults))
+ args.Set("owner", req.Owner)
+ args.Set("publishedMax", fmt.Sprintf("%d", req.PublishedMax))
+ args.Set("publishedMin", fmt.Sprintf("%d", req.PublishedMin))
+ args.Set("sort", req.Sort)
+ args.Set("startIndex", fmt.Sprintf("%d", req.StartIndex))
+ args.Set("status", req.Status)
+ args.Set("updatedMax", fmt.Sprintf("%d", req.UpdatedMax))
+ args.Set("updatedMin", fmt.Sprintf("%d", req.UpdatedMin))
+
+ url := fmt.Sprintf("/projects/%s/issues?%s", req.ProjectId, args.Encode())
+ res := &IssuesListResponse{}
+ err := c.call(ctx, "GET", url, nil, res)
+ if err != nil {
+ return nil, err
+ }
+ return res, nil
}
func checkOptions(options []grpc.CallOption) error {
« no previous file with comments | « no previous file | go/src/infra/monorail/monorail.infra_testing » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698