Skip to content

Commit 56cb1dd

Browse files
bgpatgmlewis
authored andcommitted
Escape commit ref with percent encoding (#1099)
1 parent e740a68 commit 56cb1dd

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

github/checks.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package github
88
import (
99
"context"
1010
"fmt"
11+
"net/url"
1112
)
1213

1314
// ChecksService provides access to the Checks API in the
@@ -255,7 +256,7 @@ type ListCheckRunsResults struct {
255256
//
256257
// GitHub API docs: https://developer.github.com/v3/checks/runs/#list-check-runs-for-a-specific-ref
257258
func (s *ChecksService) ListCheckRunsForRef(ctx context.Context, owner, repo, ref string, opt *ListCheckRunsOptions) (*ListCheckRunsResults, *Response, error) {
258-
u := fmt.Sprintf("repos/%v/%v/commits/%v/check-runs", owner, repo, ref)
259+
u := fmt.Sprintf("repos/%v/%v/commits/%v/check-runs", owner, repo, url.QueryEscape(ref))
259260
u, err := addOptions(u, opt)
260261
if err != nil {
261262
return nil, nil, err
@@ -321,7 +322,7 @@ type ListCheckSuiteResults struct {
321322
//
322323
// GitHub API docs: https://developer.github.com/v3/checks/suites/#list-check-suites-for-a-specific-ref
323324
func (s *ChecksService) ListCheckSuitesForRef(ctx context.Context, owner, repo, ref string, opt *ListCheckSuiteOptions) (*ListCheckSuiteResults, *Response, error) {
324-
u := fmt.Sprintf("repos/%v/%v/commits/%v/check-suites", owner, repo, ref)
325+
u := fmt.Sprintf("repos/%v/%v/commits/%v/check-suites", owner, repo, url.QueryEscape(ref))
325326
u, err := addOptions(u, opt)
326327
if err != nil {
327328
return nil, nil, err

github/git_refs.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"encoding/json"
1111
"errors"
1212
"fmt"
13+
"net/url"
1314
"strings"
1415
)
1516

@@ -57,7 +58,7 @@ type updateRefRequest struct {
5758
// GitHub API docs: https://developer.github.com/v3/git/refs/#get-a-reference
5859
func (s *GitService) GetRef(ctx context.Context, owner string, repo string, ref string) (*Reference, *Response, error) {
5960
ref = strings.TrimPrefix(ref, "refs/")
60-
u := fmt.Sprintf("repos/%v/%v/git/refs/%v", owner, repo, ref)
61+
u := fmt.Sprintf("repos/%v/%v/git/refs/%v", owner, repo, url.QueryEscape(ref))
6162
req, err := s.client.NewRequest("GET", u, nil)
6263
if err != nil {
6364
return nil, nil, err
@@ -88,7 +89,7 @@ func (s *GitService) GetRef(ctx context.Context, owner string, repo string, ref
8889
// GitHub API docs: https://developer.github.com/v3/git/refs/#get-a-reference
8990
func (s *GitService) GetRefs(ctx context.Context, owner string, repo string, ref string) ([]*Reference, *Response, error) {
9091
ref = strings.TrimPrefix(ref, "refs/")
91-
u := fmt.Sprintf("repos/%v/%v/git/refs/%v", owner, repo, ref)
92+
u := fmt.Sprintf("repos/%v/%v/git/refs/%v", owner, repo, url.QueryEscape(ref))
9293
req, err := s.client.NewRequest("GET", u, nil)
9394
if err != nil {
9495
return nil, nil, err
@@ -208,7 +209,7 @@ func (s *GitService) UpdateRef(ctx context.Context, owner string, repo string, r
208209
// GitHub API docs: https://developer.github.com/v3/git/refs/#delete-a-reference
209210
func (s *GitService) DeleteRef(ctx context.Context, owner string, repo string, ref string) (*Response, error) {
210211
ref = strings.TrimPrefix(ref, "refs/")
211-
u := fmt.Sprintf("repos/%v/%v/git/refs/%v", owner, repo, ref)
212+
u := fmt.Sprintf("repos/%v/%v/git/refs/%v", owner, repo, url.QueryEscape(ref))
212213
req, err := s.client.NewRequest("DELETE", u, nil)
213214
if err != nil {
214215
return nil, err

github/repos_commits.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"bytes"
1010
"context"
1111
"fmt"
12+
"net/url"
1213
"time"
1314
)
1415

@@ -189,7 +190,7 @@ func (s *RepositoriesService) GetCommitRaw(ctx context.Context, owner string, re
189190
//
190191
// GitHub API docs: https://developer.github.com/v3/repos/commits/#get-the-sha-1-of-a-commit-reference
191192
func (s *RepositoriesService) GetCommitSHA1(ctx context.Context, owner, repo, ref, lastSHA string) (string, *Response, error) {
192-
u := fmt.Sprintf("repos/%v/%v/commits/%v", owner, repo, ref)
193+
u := fmt.Sprintf("repos/%v/%v/commits/%v", owner, repo, url.QueryEscape(ref))
193194

194195
req, err := s.client.NewRequest("GET", u, nil)
195196
if err != nil {

github/repos_statuses.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package github
88
import (
99
"context"
1010
"fmt"
11+
"net/url"
1112
"time"
1213
)
1314

@@ -44,7 +45,7 @@ func (r RepoStatus) String() string {
4445
//
4546
// GitHub API docs: https://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-ref
4647
func (s *RepositoriesService) ListStatuses(ctx context.Context, owner, repo, ref string, opt *ListOptions) ([]*RepoStatus, *Response, error) {
47-
u := fmt.Sprintf("repos/%v/%v/commits/%v/statuses", owner, repo, ref)
48+
u := fmt.Sprintf("repos/%v/%v/commits/%v/statuses", owner, repo, url.QueryEscape(ref))
4849
u, err := addOptions(u, opt)
4950
if err != nil {
5051
return nil, nil, err
@@ -69,7 +70,7 @@ func (s *RepositoriesService) ListStatuses(ctx context.Context, owner, repo, ref
6970
//
7071
// GitHub API docs: https://developer.github.com/v3/repos/statuses/#create-a-status
7172
func (s *RepositoriesService) CreateStatus(ctx context.Context, owner, repo, ref string, status *RepoStatus) (*RepoStatus, *Response, error) {
72-
u := fmt.Sprintf("repos/%v/%v/statuses/%v", owner, repo, ref)
73+
u := fmt.Sprintf("repos/%v/%v/statuses/%v", owner, repo, url.QueryEscape(ref))
7374
req, err := s.client.NewRequest("POST", u, status)
7475
if err != nil {
7576
return nil, nil, err
@@ -108,7 +109,7 @@ func (s CombinedStatus) String() string {
108109
//
109110
// GitHub API docs: https://developer.github.com/v3/repos/statuses/#get-the-combined-status-for-a-specific-ref
110111
func (s *RepositoriesService) GetCombinedStatus(ctx context.Context, owner, repo, ref string, opt *ListOptions) (*CombinedStatus, *Response, error) {
111-
u := fmt.Sprintf("repos/%v/%v/commits/%v/status", owner, repo, ref)
112+
u := fmt.Sprintf("repos/%v/%v/commits/%v/status", owner, repo, url.QueryEscape(ref))
112113
u, err := addOptions(u, opt)
113114
if err != nil {
114115
return nil, nil, err

0 commit comments

Comments
 (0)