Skip to content

Commit

Permalink
Address various code flow and renaming comments
Browse files Browse the repository at this point in the history
  • Loading branch information
holger-wg2 committed Jul 16, 2019
1 parent 339e4fe commit 2798f37
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 97 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ generate notifications over the webhook. So if you have a repository with little

#### `get`

| Parameter | Required | Example | Description |
|-------------------------------|----------|----------|------------------------------------------------------------------------------------|
| `skip_download` | No | `true` | Use with `get_params` in a `put` step to do nothing on the implicit get. |
| `integration_tool` | No | `rebase` | The integration tool to use, `merge`, `rebase` or `checkout`. Defaults to `merge`. |
| `git_depth` | No | `1` | Shallow clone the repository using the `--depth` Git option |
| `generate_changed_file_list` | No | `true` | Generate a list of changed files and save alongside metadata |
| Parameter | Required | Example | Description |
|-----------------------|----------|----------|------------------------------------------------------------------------------------|
| `skip_download` | No | `true` | Use with `get_params` in a `put` step to do nothing on the implicit get. |
| `integration_tool` | No | `rebase` | The integration tool to use, `merge`, `rebase` or `checkout`. Defaults to `merge`. |
| `git_depth` | No | `1` | Shallow clone the repository using the `--depth` Git option |
| `list_changed_files` | No | `true` | Generate a list of changed files and save alongside metadata |

Clones the base (e.g. `master` branch) at the latest commit, and merges the pull request at the specified commit
into master. This ensures that we are both testing and setting status on the exact commit that was requested in
Expand All @@ -74,7 +74,7 @@ input. Because the base of the PR is not locked to a specific commit in versions
requested version and the metadata emitted by `get` are available to your tasks as JSON:
- `.git/resource/version.json`
- `.git/resource/metadata.json`
- `.git/resource/changed_files` (if enabled by `generate_changed_file_list`)
- `.git/resource/changed_files` (if enabled by `list_changed_files`)

The information in `metadata.json` is also available as individual files in the `.git/resource` directory, e.g. the `base_sha`
is available as `.git/resource/base_sha`. For a complete list of available (individual) metadata files, please check the code
Expand Down
14 changes: 7 additions & 7 deletions check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (

var (
testPullRequests = []*resource.PullRequest{
createTestPR(1, "master", true, false, false),
createTestPR(2, "master", false, false, false),
createTestPR(3, "master", false, false, false),
createTestPR(4, "master", false, false, false),
createTestPR(5, "master", false, true, false),
createTestPR(6, "master", false, false, false),
createTestPR(7, "develop", false, false, false),
createTestPR(1, "master", true, false),
createTestPR(2, "master", false, false),
createTestPR(3, "master", false, false),
createTestPR(4, "master", false, false),
createTestPR(5, "master", false, true),
createTestPR(6, "master", false, false),
createTestPR(7, "develop", false, false),
}
)

Expand Down
18 changes: 8 additions & 10 deletions fakes/fake_github.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 9 additions & 16 deletions github.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Github interface {
ListOpenPullRequests() ([]*PullRequest, error)
ListModifiedFiles(int) ([]string, error)
PostComment(string, string) error
GetPullRequest(string, string, bool) (*PullRequest, error)
GetPullRequest(string, string) (*PullRequest, error)
GetChangedFiles(string, string) ([]ChangedFileObject, error)
UpdateCommitStatus(string, string, string, string, string, string) error
}
Expand Down Expand Up @@ -218,17 +218,17 @@ func (m *GithubClient) GetChangedFiles(prNumber string, commitRef string) ([]Cha
}
} `graphql:"edges"`
PageInfo struct {
PageInfoObject
EndCursor githubv4.String
HasNextPage bool
} `graphql:"pageInfo"`
} `graphql:"files(first:$changedFilesFirst, after: $changedFilesEndCursor)"`
} `graphql:"pullRequest(number:$prNumber)"`
} `graphql:"repository(owner:$repositoryOwner,name:$repositoryName)"`
}

offset := ""
fetch := true

for fetch {
for {
vars := map[string]interface{}{
"repositoryOwner": githubv4.String(m.Owner),
"repositoryName": githubv4.String(m.Repository),
Expand All @@ -245,20 +245,18 @@ func (m *GithubClient) GetChangedFiles(prNumber string, commitRef string) ([]Cha
cfo = append(cfo, ChangedFileObject{Path: f.Node.Path})
}

if filequery.Repository.PullRequest.Files.PageInfo.HasNextPage {
fetch = true
offset = filequery.Repository.PullRequest.Files.PageInfo.EndCursor
} else {
fetch = false
if !filequery.Repository.PullRequest.Files.PageInfo.HasNextPage {
break
}

offset = string(filequery.Repository.PullRequest.Files.PageInfo.EndCursor)
}

return cfo, nil
}

// GetPullRequest ...
func (m *GithubClient) GetPullRequest(prNumber, commitRef string, changedFileQuery bool) (*PullRequest, error) {
func (m *GithubClient) GetPullRequest(prNumber, commitRef string) (*PullRequest, error) {
pr, err := strconv.Atoi(prNumber)
if err != nil {
return nil, fmt.Errorf("failed to convert pull request number to int: %s", err)
Expand All @@ -283,7 +281,7 @@ func (m *GithubClient) GetPullRequest(prNumber, commitRef string, changedFileQue
"repositoryOwner": githubv4.String(m.Owner),
"repositoryName": githubv4.String(m.Repository),
"prNumber": githubv4.Int(pr),
"commitsLast": githubv4.Int(100),
"commitsLast": githubv4.Int(1),
}

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

if c.Node.Commit.OID == commitRef {
if changedFileQuery {
fl, _ := m.GetChangedFiles(prNumber, commitRef)

prObj.ChangedFiles = fl
}
// Return as soon as we find the correct ref.
return &prObj, nil
}
Expand Down
19 changes: 12 additions & 7 deletions in.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func Get(request GetRequest, github Github, git Git, outputDir string) (*GetResp
return &GetResponse{Version: request.Version}, nil
}

pull, err := github.GetPullRequest(request.Version.PR, request.Version.Commit, request.Params.ChangedFilesQuery)
pull, err := github.GetPullRequest(request.Version.PR, request.Version.Commit)
if err != nil {
return nil, fmt.Errorf("failed to retrieve pull request: %s", err)
}
Expand Down Expand Up @@ -102,10 +102,15 @@ func Get(request GetRequest, github Github, git Git, outputDir string) (*GetResp

}

if len(pull.ChangedFiles) != 0 {
if request.Params.GenerateChangedFileList {
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)
}

var fl []byte

for _, v := range pull.ChangedFiles {
for _, v := range cfol {
fl = append(fl, []byte(v.Path+"\n")...)
}

Expand All @@ -123,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"`
ChangedFilesQuery bool `json:"generate_changed_file_list"`
SkipDownload bool `json:"skip_download"`
IntegrationTool string `json:"integration_tool"`
GitDepth int `json:"git_depth"`
GenerateChangedFileList bool `json:"list_changed_files"`
}

// GetRequest ...
Expand Down
Loading

0 comments on commit 2798f37

Please sign in to comment.