From a14016225da2ece7487ec7703b158c9c3ac73411 Mon Sep 17 00:00:00 2001 From: Dave Protasowski Date: Wed, 24 Jul 2019 21:35:55 -0400 Subject: [PATCH 1/4] Update git_refs.go Fix a segfault when fetching refs from github returns an error (say due to connectivity) --- github/git_refs.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/github/git_refs.go b/github/git_refs.go index fe16880e7b0..4bcd9c711e3 100644 --- a/github/git_refs.go +++ b/github/git_refs.go @@ -69,11 +69,11 @@ func (s *GitService) GetRef(ctx context.Context, owner string, repo string, ref if _, ok := err.(*json.UnmarshalTypeError); ok { // Multiple refs, means there wasn't an exact match. return nil, resp, errors.New("multiple matches found for this ref") + } else if err != nil { + return nil, nil, err } else if resp.StatusCode == 404 { // No ref, there was no match for the ref return nil, resp, errors.New("no match found for this ref") - } else if err != nil { - return nil, resp, err } return r, resp, nil From b2207b3a9664ed060b93b05750e29e312a819cb2 Mon Sep 17 00:00:00 2001 From: Dave Protasowski Date: Wed, 24 Jul 2019 22:02:45 -0400 Subject: [PATCH 2/4] Update git_refs.go github client returns a response _and_ error when the status code is 404 (in contrast to the standard http.Client) --- github/git_refs.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/github/git_refs.go b/github/git_refs.go index 4bcd9c711e3..a60a1640129 100644 --- a/github/git_refs.go +++ b/github/git_refs.go @@ -69,11 +69,11 @@ func (s *GitService) GetRef(ctx context.Context, owner string, repo string, ref if _, ok := err.(*json.UnmarshalTypeError); ok { // Multiple refs, means there wasn't an exact match. return nil, resp, errors.New("multiple matches found for this ref") + } else if _, ok; err.(*ErrorResponse); ok && resp.StatusCode == 404 { + // No ref, there was no match for the ref + return nil, nil, errors.New("no match found for this ref") } else if err != nil { return nil, nil, err - } else if resp.StatusCode == 404 { - // No ref, there was no match for the ref - return nil, resp, errors.New("no match found for this ref") } return r, resp, nil From 42681371ece8dba1a4aea9b39051ad6f5b5ad6ce Mon Sep 17 00:00:00 2001 From: Dave Protasowski Date: Wed, 24 Jul 2019 22:05:01 -0400 Subject: [PATCH 3/4] Update git_refs.go be consistent with other parts of the github client returning the response && error --- github/git_refs.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/github/git_refs.go b/github/git_refs.go index a60a1640129..13faa83d264 100644 --- a/github/git_refs.go +++ b/github/git_refs.go @@ -71,9 +71,9 @@ func (s *GitService) GetRef(ctx context.Context, owner string, repo string, ref return nil, resp, errors.New("multiple matches found for this ref") } else if _, ok; err.(*ErrorResponse); ok && resp.StatusCode == 404 { // No ref, there was no match for the ref - return nil, nil, errors.New("no match found for this ref") + return nil, resp, errors.New("no match found for this ref") } else if err != nil { - return nil, nil, err + return nil, resp, err } return r, resp, nil From a19f69f33f002be5b381daab6aa94edb19d71a5c Mon Sep 17 00:00:00 2001 From: Dave Protasowski Date: Wed, 24 Jul 2019 23:20:02 -0400 Subject: [PATCH 4/4] Update git_refs.go Fix syntax error and remind self to stop using GitHub editor --- github/git_refs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/git_refs.go b/github/git_refs.go index 13faa83d264..b51bcbf1deb 100644 --- a/github/git_refs.go +++ b/github/git_refs.go @@ -69,7 +69,7 @@ func (s *GitService) GetRef(ctx context.Context, owner string, repo string, ref if _, ok := err.(*json.UnmarshalTypeError); ok { // Multiple refs, means there wasn't an exact match. return nil, resp, errors.New("multiple matches found for this ref") - } else if _, ok; err.(*ErrorResponse); ok && resp.StatusCode == 404 { + } else if _, ok := err.(*ErrorResponse); ok && resp.StatusCode == 404 { // No ref, there was no match for the ref return nil, resp, errors.New("no match found for this ref") } else if err != nil {