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

Side by Side Diff: common/api/gitiles/gitiles.go

Issue 2983153002: Make gitiles calls as Self instead of Anon (Closed)
Patch Set: WithScope Created 3 years, 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The LUCI Authors. 1 // Copyright 2016 The LUCI Authors.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 77
78 // Log returns a list of commits based on a repo and treeish (usually 78 // Log returns a list of commits based on a repo and treeish (usually
79 // a branch). This should be equivilent of a "git log <treeish>" call in 79 // a branch). This should be equivilent of a "git log <treeish>" call in
80 // that repository. 80 // that repository.
81 func Log(c context.Context, repoURL, treeish string, limit int) ([]Commit, error ) { 81 func Log(c context.Context, repoURL, treeish string, limit int) ([]Commit, error ) {
82 // TODO(hinoka): Respect the limit. 82 // TODO(hinoka): Respect the limit.
83 URL, err := fixURL(repoURL, treeish) 83 URL, err := fixURL(repoURL, treeish)
84 if err != nil { 84 if err != nil {
85 return nil, err 85 return nil, err
86 } 86 }
87 » t, err := auth.GetRPCTransport(c, auth.NoAuth) 87 » t, err := auth.GetRPCTransport(c, auth.AsSelf, auth.WithScopes(
88 » » "https://www.googleapis.com/auth/gerritcodereview",
89 » ))
88 if err != nil { 90 if err != nil {
89 return nil, err 91 return nil, err
90 } 92 }
91 client := http.Client{Transport: t} 93 client := http.Client{Transport: t}
92 r, err := client.Get(URL) 94 r, err := client.Get(URL)
93 if err != nil { 95 if err != nil {
94 return nil, err 96 return nil, err
95 } 97 }
96 if r.StatusCode != 200 { 98 if r.StatusCode != 200 {
97 return nil, fmt.Errorf("Failed to fetch %s, status code %d", URL , r.StatusCode) 99 return nil, fmt.Errorf("Failed to fetch %s, status code %d", URL , r.StatusCode)
98 } 100 }
99 defer r.Body.Close() 101 defer r.Body.Close()
100 // Strip out the jsonp header, which is ")]}'" 102 // Strip out the jsonp header, which is ")]}'"
101 trash := make([]byte, 4) 103 trash := make([]byte, 4)
102 r.Body.Read(trash) // Read the jsonp header 104 r.Body.Read(trash) // Read the jsonp header
103 commits := LogResponse{} 105 commits := LogResponse{}
104 if err := json.NewDecoder(r.Body).Decode(&commits); err != nil { 106 if err := json.NewDecoder(r.Body).Decode(&commits); err != nil {
105 return nil, err 107 return nil, err
106 } 108 }
107 // TODO(hinoka): If there is a page and we have gotten less than the lim it, 109 // TODO(hinoka): If there is a page and we have gotten less than the lim it,
108 // keep making requests for the next page until we have enough commits. 110 // keep making requests for the next page until we have enough commits.
109 return commits.Log, nil 111 return commits.Log, nil
110 } 112 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698