-
Notifications
You must be signed in to change notification settings - Fork 74
Improve api support #26
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,15 @@ | ||
| language: go | ||
|
|
||
| sudo: false | ||
|
|
||
| go: | ||
| - 1.1 | ||
| - 1.2 | ||
| - 1.3 | ||
| - 1.4 | ||
| install: | ||
| - go get github.com/stretchr/testify/assert | ||
| script: | ||
| - go test -v | ||
| - 1.5 | ||
| - 1.6 | ||
|
|
||
| install: make install | ||
|
|
||
| script: make test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| .PHONY: test run update format install | ||
|
|
||
| install: | ||
| go get github.com/stretchr/testify/assert | ||
| go list -f '{{range .Imports}}{{.}} {{end}}' ./... | xargs go get -v | ||
| go list -f '{{range .TestImports}}{{.}} {{end}}' ./... | xargs go get -v | ||
|
|
||
| update: | ||
| go get -u all | ||
|
|
||
| format: | ||
| gofmt -l -w -s . | ||
| go fix ./... | ||
|
|
||
| test: | ||
| go test -v ./... | ||
| go vet ./... | ||
| exit `gofmt -l -s -e . | wc -l` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| package gogitlab | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "io" | ||
| ) | ||
|
|
||
| const ( | ||
| project_builds = "/projects/:id/builds" // List project builds | ||
| project_build = "/projects/:id/builds/:build_id" // Get a single build | ||
| project_commit_builds = "/projects/:id/repository/commits/:sha/builds" // List commit builds | ||
| project_build_artifacts = "/projects/:id/builds/:build_id/artifacts" // Get build artifacts | ||
| project_build_cancel = "/projects/:id/builds/:build_id/cancel" // Cancel a build | ||
| project_build_retry = "/projects/:id/builds/:build_id/retry" // Retry a build | ||
| project_build_erase = "/projects/:id/builds/:build_id/erase" // Erase a build | ||
| ) | ||
|
|
||
| type ArtifactsFile struct { | ||
| Filename string `json:"filename"` | ||
| Size int `json:"size"` | ||
| } | ||
|
|
||
| type Build struct { | ||
| Id int `json:"id"` | ||
| ArtifactsFile ArtifactsFile `json:"artifacts_file"` | ||
| Commit Commit `json:"commit"` | ||
| CreatedAt string `json:"created_at"` | ||
| DownloadURL string `json:"download_url"` | ||
| FinishedAt string `json:"finished_at"` | ||
| Name string `json:"name"` | ||
| Ref string `json:"ref"` | ||
| Stage string `json:"stage"` | ||
| StartedAt string `json:"started_at"` | ||
| Status string `json:"status"` | ||
| Tag bool `json:"tag"` | ||
| User User `json:"user"` | ||
| } | ||
|
|
||
| func (g *Gitlab) ProjectBuilds(id string) ([]*Build, error) { | ||
| url, opaque := g.ResourceUrlRaw(project_builds, map[string]string{ | ||
| ":id": id, | ||
| }) | ||
|
|
||
| builds := make([]*Build, 0) | ||
|
|
||
| contents, err := g.buildAndExecRequestRaw("GET", url, opaque, nil) | ||
| if err != nil { | ||
| return builds, err | ||
| } | ||
|
|
||
| err = json.Unmarshal(contents, &builds) | ||
|
|
||
| return builds, err | ||
| } | ||
|
|
||
| func (g *Gitlab) ProjectCommitBuilds(id, sha1 string) ([]*Build, error) { | ||
| url, opaque := g.ResourceUrlRaw(project_commit_builds, map[string]string{ | ||
| ":id": id, | ||
| ":sha": sha1, | ||
| }) | ||
|
|
||
| builds := make([]*Build, 0) | ||
|
|
||
| contents, err := g.buildAndExecRequestRaw("GET", url, opaque, nil) | ||
| if err != nil { | ||
| return builds, err | ||
| } | ||
|
|
||
| err = json.Unmarshal(contents, &builds) | ||
|
|
||
| return builds, err | ||
| } | ||
|
|
||
| func (g *Gitlab) ProjectBuild(id, buildId string) (*Build, error) { | ||
| url, opaque := g.ResourceUrlRaw(project_build, map[string]string{ | ||
| ":id": id, | ||
| ":build_id": buildId, | ||
| }) | ||
|
|
||
| build := &Build{} | ||
|
|
||
| contents, err := g.buildAndExecRequestRaw("GET", url, opaque, nil) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| err = json.Unmarshal(contents, &build) | ||
|
|
||
| return build, err | ||
| } | ||
|
|
||
| func (g *Gitlab) ProjectBuildArtifacts(id, buildId string) (io.ReadCloser, error) { | ||
| url, _ := g.ResourceUrlRaw(project_build_artifacts, map[string]string{ | ||
| ":id": id, | ||
| ":build_id": buildId, | ||
| }) | ||
|
|
||
| resp, err := g.execRequest("GET", url, nil) | ||
|
|
||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return resp.Body, nil | ||
| } | ||
|
|
||
| func (g *Gitlab) ProjectCancelBuild(id, buildId string) (*Build, error) { | ||
| url, opaque := g.ResourceUrlRaw(project_build_cancel, map[string]string{ | ||
| ":id": id, | ||
| ":build_id": buildId, | ||
| }) | ||
|
|
||
| build := &Build{} | ||
|
|
||
| contents, err := g.buildAndExecRequestRaw("POST", url, opaque, nil) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| err = json.Unmarshal(contents, &build) | ||
|
|
||
| return build, err | ||
| } | ||
|
|
||
| func (g *Gitlab) ProjectRetryBuild(id, buildId string) (*Build, error) { | ||
| url, opaque := g.ResourceUrlRaw(project_build_retry, map[string]string{ | ||
| ":id": id, | ||
| ":build_id": buildId, | ||
| }) | ||
|
|
||
| build := &Build{} | ||
|
|
||
| contents, err := g.buildAndExecRequestRaw("POST", url, opaque, nil) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| err = json.Unmarshal(contents, &build) | ||
|
|
||
| return build, err | ||
| } | ||
|
|
||
| func (g *Gitlab) ProjectEraseBuild(id, buildId string) (*Build, error) { | ||
| url, opaque := g.ResourceUrlRaw(project_build_erase, map[string]string{ | ||
| ":id": id, | ||
| ":build_id": buildId, | ||
| }) | ||
|
|
||
| build := &Build{} | ||
|
|
||
| contents, err := g.buildAndExecRequestRaw("POST", url, opaque, nil) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| err = json.Unmarshal(contents, &build) | ||
|
|
||
| return build, err | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| package gogitlab | ||
|
|
||
| import ( | ||
| "github.com/stretchr/testify/assert" | ||
| "io/ioutil" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestProjectBuilds(t *testing.T) { | ||
| ts, gitlab := Stub("stubs/builds/list.json") | ||
| defer ts.Close() | ||
|
|
||
| builds, err := gitlab.ProjectBuilds("3") | ||
|
|
||
| assert.Nil(t, err) | ||
| assert.Equal(t, len(builds), 2) | ||
| assert.Equal(t, builds[0].ArtifactsFile.Filename, "artifacts.zip") | ||
| } | ||
|
|
||
| func TestProjectCommitBuilds(t *testing.T) { | ||
| ts, gitlab := Stub("stubs/builds/commit_builds_list.json") | ||
| defer ts.Close() | ||
|
|
||
| builds, err := gitlab.ProjectBuilds("3") | ||
|
|
||
| assert.Nil(t, err) | ||
| assert.Equal(t, len(builds), 2) | ||
| assert.Equal(t, builds[1].User.AvatarUrl, "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon") | ||
| } | ||
|
|
||
| func TestProjectBuild(t *testing.T) { | ||
| ts, gitlab := Stub("stubs/builds/build.json") | ||
| defer ts.Close() | ||
|
|
||
| build, err := gitlab.ProjectBuild("3", "12") | ||
|
|
||
| assert.Nil(t, err) | ||
| assert.Equal(t, build.Commit.Id, "0ff3ae198f8601a285adcf5c0fff204ee6fba5fd") | ||
| } | ||
|
|
||
| func TestProjectCancelBuild(t *testing.T) { | ||
| ts, gitlab := Stub("stubs/builds/cancel.json") | ||
| defer ts.Close() | ||
|
|
||
| build, err := gitlab.ProjectBuild("3", "12") | ||
|
|
||
| assert.Nil(t, err) | ||
| assert.Equal(t, build.Status, "canceled") | ||
| } | ||
|
|
||
| func TestProjectRetryBuild(t *testing.T) { | ||
| ts, gitlab := Stub("stubs/builds/retry.json") | ||
| defer ts.Close() | ||
|
|
||
| build, err := gitlab.ProjectBuild("3", "12") | ||
|
|
||
| assert.Nil(t, err) | ||
| assert.Equal(t, build.Status, "pending") | ||
| } | ||
|
|
||
| func TestProjectEraseBuild(t *testing.T) { | ||
| ts, gitlab := Stub("stubs/builds/erase.json") | ||
| defer ts.Close() | ||
|
|
||
| build, err := gitlab.ProjectBuild("3", "12") | ||
|
|
||
| assert.Nil(t, err) | ||
| assert.Equal(t, build.Status, "failed") | ||
| } | ||
|
|
||
| func TestProjectArtifact(t *testing.T) { | ||
| ts, gitlab := Stub("stubs/builds/content.txt") | ||
| defer ts.Close() | ||
|
|
||
| r, err := gitlab.ProjectBuildArtifacts("3", "12") | ||
|
|
||
| assert.Nil(t, err) | ||
|
|
||
| defer r.Close() | ||
|
|
||
| contents, err := ioutil.ReadAll(r) | ||
|
|
||
| assert.Equal(t, string(contents), "a content") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
runnerandcoverageare reallyinterface{}? i only seenullin tests. what types can they be in real world 😃 ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know ;) the documentation is not explicit about their values ... I can remove those fields in the mean time. So the lib will be BC when those types will be defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed