Skip to content

Commit

Permalink
Address more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
holger-wg2 committed Jul 16, 2019
1 parent 2798f37 commit 14ecb63
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 27 deletions.
14 changes: 6 additions & 8 deletions github.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (m *GithubClient) ListOpenPullRequests() ([]*PullRequest, error) {
"prFirst": githubv4.Int(100),
"prStates": []githubv4.PullRequestState{githubv4.PullRequestStateOpen},
"prCursor": (*githubv4.String)(nil),
"commitsLast": githubv4.Int(100),
"commitsLast": githubv4.Int(1),
}

var response []*PullRequest
Expand Down Expand Up @@ -281,7 +281,7 @@ func (m *GithubClient) GetPullRequest(prNumber, commitRef string) (*PullRequest,
"repositoryOwner": githubv4.String(m.Owner),
"repositoryName": githubv4.String(m.Repository),
"prNumber": githubv4.Int(pr),
"commitsLast": githubv4.Int(1),
"commitsLast": githubv4.Int(100),
}

// TODO: Pagination - in case someone pushes > 100 commits before the build has time to start :p
Expand All @@ -290,14 +290,12 @@ func (m *GithubClient) GetPullRequest(prNumber, commitRef string) (*PullRequest,
}

for _, c := range query.Repository.PullRequest.Commits.Edges {
prObj := PullRequest{
PullRequestObject: query.Repository.PullRequest.PullRequestObject,
Tip: c.Node.Commit,
}

if c.Node.Commit.OID == commitRef {
// Return as soon as we find the correct ref.
return &prObj, nil
return &PullRequest{
PullRequestObject: query.Repository.PullRequest.PullRequestObject,
Tip: c.Node.Commit,
}, nil
}
}

Expand Down
10 changes: 5 additions & 5 deletions in.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func Get(request GetRequest, github Github, git Git, outputDir string) (*GetResp

}

if request.Params.GenerateChangedFileList {
if request.Params.ListChangedFiles {
cfol, err := github.GetChangedFiles(request.Version.PR, request.Version.Commit)
if err != nil {
return nil, fmt.Errorf("failed to fetch list of changed files: %s", err)
Expand All @@ -128,10 +128,10 @@ func Get(request GetRequest, github Github, git Git, outputDir string) (*GetResp

// GetParameters ...
type GetParameters struct {
SkipDownload bool `json:"skip_download"`
IntegrationTool string `json:"integration_tool"`
GitDepth int `json:"git_depth"`
GenerateChangedFileList bool `json:"list_changed_files"`
SkipDownload bool `json:"skip_download"`
IntegrationTool string `json:"integration_tool"`
GitDepth int `json:"git_depth"`
ListChangedFiles bool `json:"list_changed_files"`
}

// GetRequest ...
Expand Down
22 changes: 10 additions & 12 deletions in_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestGet(t *testing.T) {
CommittedDate: time.Time{},
},
parameters: resource.GetParameters{
GenerateChangedFileList: true,
ListChangedFiles: true,
},
pullRequest: createTestPR(1, "master", false, false),
versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z"}`,
Expand Down Expand Up @@ -68,7 +68,7 @@ func TestGet(t *testing.T) {
CommittedDate: time.Time{},
},
parameters: resource.GetParameters{
GenerateChangedFileList: true,
ListChangedFiles: true,
},
pullRequest: createTestPR(1, "master", false, false),
versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z"}`,
Expand All @@ -95,8 +95,8 @@ func TestGet(t *testing.T) {
CommittedDate: time.Time{},
},
parameters: resource.GetParameters{
IntegrationTool: "rebase",
GenerateChangedFileList: true,
IntegrationTool: "rebase",
ListChangedFiles: true,
},
pullRequest: createTestPR(1, "master", false, false),
versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z"}`,
Expand All @@ -123,8 +123,8 @@ func TestGet(t *testing.T) {
CommittedDate: time.Time{},
},
parameters: resource.GetParameters{
IntegrationTool: "checkout",
GenerateChangedFileList: true,
IntegrationTool: "checkout",
ListChangedFiles: true,
},
pullRequest: createTestPR(1, "master", false, false),
versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z"}`,
Expand All @@ -151,8 +151,8 @@ func TestGet(t *testing.T) {
CommittedDate: time.Time{},
},
parameters: resource.GetParameters{
GitDepth: 2,
GenerateChangedFileList: true,
GitDepth: 2,
ListChangedFiles: true,
},
pullRequest: createTestPR(1, "master", false, false),
versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z"}`,
Expand All @@ -179,7 +179,7 @@ func TestGet(t *testing.T) {
CommittedDate: time.Time{},
},
parameters: resource.GetParameters{
GenerateChangedFileList: false,
ListChangedFiles: false,
},
pullRequest: createTestPR(1, "master", false, false),
versionString: `{"pr":"pr1","commit":"commit1","committed":"0001-01-01T00:00:00Z"}`,
Expand Down Expand Up @@ -349,7 +349,7 @@ func createTestPR(count int, baseName string, skipCI bool, isCrossRepo bool) *re
m = "[skip ci]" + m
}

retpr := resource.PullRequest{
return &resource.PullRequest{
PullRequestObject: resource.PullRequestObject{
ID: fmt.Sprintf("pr%s", n),
Number: count,
Expand All @@ -374,8 +374,6 @@ func createTestPR(count int, baseName string, skipCI bool, isCrossRepo bool) *re
},
},
}

return &retpr
}

func createTestDirectory(t *testing.T) string {
Expand Down
4 changes: 2 additions & 2 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func NewVersion(p *PullRequest) Version {
// PullRequest represents a pull request and includes the tip (commit).
type PullRequest struct {
PullRequestObject
Tip CommitObject
Tip CommitObject
}

// PullRequestObject represents the GraphQL commit node.
Expand Down Expand Up @@ -109,4 +109,4 @@ type CommitObject struct {
// https://developer.github.com/v4/object/pullrequestchangedfile/
type ChangedFileObject struct {
Path string
}
}

0 comments on commit 14ecb63

Please sign in to comment.