From 28e0f3e5fc72ad9c699ec4813f01e0aa13b5b2a1 Mon Sep 17 00:00:00 2001 From: bgpat Date: Wed, 16 Jan 2019 17:11:18 +0900 Subject: [PATCH 1/2] Escape commit ref with percent encoding --- github/repos_commits.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/github/repos_commits.go b/github/repos_commits.go index 0dcfe62cb47..a4c62159685 100644 --- a/github/repos_commits.go +++ b/github/repos_commits.go @@ -9,6 +9,7 @@ import ( "bytes" "context" "fmt" + "net/url" "time" ) @@ -189,7 +190,7 @@ func (s *RepositoriesService) GetCommitRaw(ctx context.Context, owner string, re // // GitHub API docs: https://developer.github.com/v3/repos/commits/#get-the-sha-1-of-a-commit-reference func (s *RepositoriesService) GetCommitSHA1(ctx context.Context, owner, repo, ref, lastSHA string) (string, *Response, error) { - u := fmt.Sprintf("repos/%v/%v/commits/%v", owner, repo, ref) + u := fmt.Sprintf("repos/%v/%v/commits/%v", owner, repo, url.QueryEscape(ref)) req, err := s.client.NewRequest("GET", u, nil) if err != nil { From 493cd165db7fbe7ed0cba8e7663cb6cb75a62958 Mon Sep 17 00:00:00 2001 From: bgpat Date: Thu, 17 Jan 2019 20:27:06 +0900 Subject: [PATCH 2/2] Escape ref path --- github/checks.go | 5 +++-- github/git_refs.go | 7 ++++--- github/repos_statuses.go | 7 ++++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/github/checks.go b/github/checks.go index f27d40d4d33..8aaed8a56ad 100644 --- a/github/checks.go +++ b/github/checks.go @@ -8,6 +8,7 @@ package github import ( "context" "fmt" + "net/url" ) // ChecksService provides access to the Checks API in the @@ -255,7 +256,7 @@ type ListCheckRunsResults struct { // // GitHub API docs: https://developer.github.com/v3/checks/runs/#list-check-runs-for-a-specific-ref func (s *ChecksService) ListCheckRunsForRef(ctx context.Context, owner, repo, ref string, opt *ListCheckRunsOptions) (*ListCheckRunsResults, *Response, error) { - u := fmt.Sprintf("repos/%v/%v/commits/%v/check-runs", owner, repo, ref) + u := fmt.Sprintf("repos/%v/%v/commits/%v/check-runs", owner, repo, url.QueryEscape(ref)) u, err := addOptions(u, opt) if err != nil { return nil, nil, err @@ -321,7 +322,7 @@ type ListCheckSuiteResults struct { // // GitHub API docs: https://developer.github.com/v3/checks/suites/#list-check-suites-for-a-specific-ref func (s *ChecksService) ListCheckSuitesForRef(ctx context.Context, owner, repo, ref string, opt *ListCheckSuiteOptions) (*ListCheckSuiteResults, *Response, error) { - u := fmt.Sprintf("repos/%v/%v/commits/%v/check-suites", owner, repo, ref) + u := fmt.Sprintf("repos/%v/%v/commits/%v/check-suites", owner, repo, url.QueryEscape(ref)) u, err := addOptions(u, opt) if err != nil { return nil, nil, err diff --git a/github/git_refs.go b/github/git_refs.go index 3b2ced2333a..3f381d5f2b6 100644 --- a/github/git_refs.go +++ b/github/git_refs.go @@ -10,6 +10,7 @@ import ( "encoding/json" "errors" "fmt" + "net/url" "strings" ) @@ -57,7 +58,7 @@ type updateRefRequest struct { // GitHub API docs: https://developer.github.com/v3/git/refs/#get-a-reference func (s *GitService) GetRef(ctx context.Context, owner string, repo string, ref string) (*Reference, *Response, error) { ref = strings.TrimPrefix(ref, "refs/") - u := fmt.Sprintf("repos/%v/%v/git/refs/%v", owner, repo, ref) + u := fmt.Sprintf("repos/%v/%v/git/refs/%v", owner, repo, url.QueryEscape(ref)) req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err @@ -88,7 +89,7 @@ func (s *GitService) GetRef(ctx context.Context, owner string, repo string, ref // GitHub API docs: https://developer.github.com/v3/git/refs/#get-a-reference func (s *GitService) GetRefs(ctx context.Context, owner string, repo string, ref string) ([]*Reference, *Response, error) { ref = strings.TrimPrefix(ref, "refs/") - u := fmt.Sprintf("repos/%v/%v/git/refs/%v", owner, repo, ref) + u := fmt.Sprintf("repos/%v/%v/git/refs/%v", owner, repo, url.QueryEscape(ref)) req, err := s.client.NewRequest("GET", u, nil) if err != nil { return nil, nil, err @@ -208,7 +209,7 @@ func (s *GitService) UpdateRef(ctx context.Context, owner string, repo string, r // GitHub API docs: https://developer.github.com/v3/git/refs/#delete-a-reference func (s *GitService) DeleteRef(ctx context.Context, owner string, repo string, ref string) (*Response, error) { ref = strings.TrimPrefix(ref, "refs/") - u := fmt.Sprintf("repos/%v/%v/git/refs/%v", owner, repo, ref) + u := fmt.Sprintf("repos/%v/%v/git/refs/%v", owner, repo, url.QueryEscape(ref)) req, err := s.client.NewRequest("DELETE", u, nil) if err != nil { return nil, err diff --git a/github/repos_statuses.go b/github/repos_statuses.go index f94fdc858b8..c889b31dd77 100644 --- a/github/repos_statuses.go +++ b/github/repos_statuses.go @@ -8,6 +8,7 @@ package github import ( "context" "fmt" + "net/url" "time" ) @@ -44,7 +45,7 @@ func (r RepoStatus) String() string { // // GitHub API docs: https://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-ref func (s *RepositoriesService) ListStatuses(ctx context.Context, owner, repo, ref string, opt *ListOptions) ([]*RepoStatus, *Response, error) { - u := fmt.Sprintf("repos/%v/%v/commits/%v/statuses", owner, repo, ref) + u := fmt.Sprintf("repos/%v/%v/commits/%v/statuses", owner, repo, url.QueryEscape(ref)) u, err := addOptions(u, opt) if err != nil { return nil, nil, err @@ -69,7 +70,7 @@ func (s *RepositoriesService) ListStatuses(ctx context.Context, owner, repo, ref // // GitHub API docs: https://developer.github.com/v3/repos/statuses/#create-a-status func (s *RepositoriesService) CreateStatus(ctx context.Context, owner, repo, ref string, status *RepoStatus) (*RepoStatus, *Response, error) { - u := fmt.Sprintf("repos/%v/%v/statuses/%v", owner, repo, ref) + u := fmt.Sprintf("repos/%v/%v/statuses/%v", owner, repo, url.QueryEscape(ref)) req, err := s.client.NewRequest("POST", u, status) if err != nil { return nil, nil, err @@ -108,7 +109,7 @@ func (s CombinedStatus) String() string { // // GitHub API docs: https://developer.github.com/v3/repos/statuses/#get-the-combined-status-for-a-specific-ref func (s *RepositoriesService) GetCombinedStatus(ctx context.Context, owner, repo, ref string, opt *ListOptions) (*CombinedStatus, *Response, error) { - u := fmt.Sprintf("repos/%v/%v/commits/%v/status", owner, repo, ref) + u := fmt.Sprintf("repos/%v/%v/commits/%v/status", owner, repo, url.QueryEscape(ref)) u, err := addOptions(u, opt) if err != nil { return nil, nil, err