Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid panics due to Github and Gitlab API error results #237

Merged
merged 1 commit into from
Jan 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/provider/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ func (p *GithubProvider) getRate(i *github.Rate) Rate {
}

func (p *GithubProvider) getResponse(i *github.Response) *Response {
if i == nil {
return nil
}
r := Response{
NextPage: i.NextPage,
PrevPage: i.PrevPage,
Expand Down
45 changes: 45 additions & 0 deletions pkg/provider/github_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package provider

import (
"testing"
)

func TestGithub_GetResponse(t *testing.T) {
p := GithubProvider{}
p.getResponse(nil)
}

func TestGithub_GetIssues(t *testing.T) {
p := GithubProvider{}
p.getIssues(nil)
}

func TestGithub_GetIssueComments(t *testing.T) {
p := GithubProvider{}
p.getIssueComments(nil)
}

func TestGithub_GetIssueTimeline(t *testing.T) {
p := GithubProvider{}
p.getIssueTimeline(nil)
}

func TestGithub_GetPullRequestsList(t *testing.T) {
p := GithubProvider{}
p.getPullRequestsList(nil)
}

func TestGithub_GetPullRequest(t *testing.T) {
p := GithubProvider{}
p.getPullRequest(nil)
}

func TestGithub_GetPullRequestListComments(t *testing.T) {
p := GithubProvider{}
p.getPullRequestListComments(nil)
}

func TestGithub_GetPullRequestsListReviews(t *testing.T) {
p := GithubProvider{}
p.getPullRequestsListReviews(nil)
}
9 changes: 9 additions & 0 deletions pkg/provider/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ func (p *GitlabProvider) getRate(i *gitlab.Response) Rate {
}

func (p *GitlabProvider) getResponse(i *gitlab.Response) *Response {
if i == nil {
return nil
}
r := Response{
NextPage: i.NextPage,
Rate: p.getRate(i),
Expand Down Expand Up @@ -252,6 +255,9 @@ func (p *GitlabProvider) getMilestone(i *gitlab.Milestone) *Milestone {
}

func (p *GitlabProvider) getPullRequest(v *gitlab.MergeRequest) *PullRequest {
if v == nil {
return nil
}
id := int64(v.ID)
m := &PullRequest{
Assignee: p.getUserFromBasicUser(v.Assignee, true),
Expand Down Expand Up @@ -323,6 +329,9 @@ func (p *GitlabProvider) PullRequestsListComments(ctx context.Context, sp Search
}

func (p *GitlabProvider) getPullRequestReviews(i *gitlab.MergeRequestApprovals) []*PullRequestReview {
if i == nil {
return nil
}
r := make([]*PullRequestReview, len(i.ApprovedBy))
state := "APPROVED"
for k, v := range i.ApprovedBy {
Expand Down
40 changes: 40 additions & 0 deletions pkg/provider/gitlab_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package provider

import (
"testing"
)

func TestGitlab_GetResponse(t *testing.T) {
p := GitlabProvider{}
p.getResponse(nil)
}

func TestGitlab_GetIssues(t *testing.T) {
p := GitlabProvider{}
p.getIssues(nil)
}

func TestGitlab_GetIssueComments(t *testing.T) {
p := GitlabProvider{}
p.getIssueComments(nil)
}

func TestGitlab_GetPullRequests(t *testing.T) {
p := GitlabProvider{}
p.getPullRequests(nil)
}

func TestGitlab_GetPullRequest(t *testing.T) {
p := GitlabProvider{}
p.getPullRequest(nil)
}

func TestGitlab_GetPullRequestComments(t *testing.T) {
p := GitlabProvider{}
p.getPullRequestComments(nil)
}

func TestGitlab_GetPullRequestReviews(t *testing.T) {
p := GitlabProvider{}
p.getPullRequestReviews(nil)
}