Unverified Commit c3d3bd6a authored by Sander van Harmelen's avatar Sander van Harmelen Committed by GitHub

Merge pull request #599 from ZJvandeWeg/zj-get-commit-fields

Update GetCommit entity fields
parents 1b3cf95a 127bf660
...@@ -48,6 +48,8 @@ type Commit struct { ...@@ -48,6 +48,8 @@ type Commit struct {
ParentIDs []string `json:"parent_ids"` ParentIDs []string `json:"parent_ids"`
Stats *CommitStats `json:"stats"` Stats *CommitStats `json:"stats"`
Status *BuildStateValue `json:"status"` Status *BuildStateValue `json:"status"`
LastPipeline *PipelineInfo `json:"last_pipeline"`
ProjectID int `json:"project_id"`
} }
// CommitStats represents the number of added and deleted files in a commit. // CommitStats represents the number of added and deleted files in a commit.
......
...@@ -5,8 +5,49 @@ import ( ...@@ -5,8 +5,49 @@ import (
"net/http" "net/http"
"reflect" "reflect"
"testing" "testing"
"github.com/stretchr/testify/assert"
) )
func TestGetCommit(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/api/v4/projects/1/repository/commits/b0b3a907f41409829b307a28b82fdbd552ee5a27", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
mustWriteHTTPResponse(t, w, "testdata/get_commit.json")
})
commit, resp, err := client.Commits.GetCommit("1", "b0b3a907f41409829b307a28b82fdbd552ee5a27", nil)
if err != nil {
t.Fatalf("Commits.GetCommit returned error: %v, response: %v", err, resp)
}
want := &Commit{
ID: "6104942438c14ec7bd21c6cd5bd995272b3faff6",
ShortID: "6104942438c",
Title: "Sanitize for network graph",
AuthorName: "randx",
AuthorEmail: "dmitriy.zaporozhets@gmail.com",
CommitterName: "Dmitriy",
CommitterEmail: "dmitriy.zaporozhets@gmail.com",
Message: "Sanitize for network graph",
ParentIDs: []string{"ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba"},
Stats: &CommitStats{Additions: 15, Deletions: 10, Total: 25},
Status: BuildState(Running),
LastPipeline: &PipelineInfo{
ID: 8,
Ref: "master",
SHA: "2dc6aa325a317eda67812f05600bdf0fcdc70ab0",
Status: "created",
WebURL: "https://gitlab.com/gitlab-org/gitlab-ce/pipelines/54268416",
},
ProjectID: 13083,
}
assert.Equal(t, want, commit)
}
func TestGetCommitStatuses(t *testing.T) { func TestGetCommitStatuses(t *testing.T) {
mux, server, client := setup() mux, server, client := setup()
defer teardown(server) defer teardown(server)
......
...@@ -5,9 +5,11 @@ import ( ...@@ -5,9 +5,11 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"errors" "errors"
"io"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"os"
"strings" "strings"
"testing" "testing"
) )
...@@ -59,6 +61,17 @@ func testBody(t *testing.T, r *http.Request, want string) { ...@@ -59,6 +61,17 @@ func testBody(t *testing.T, r *http.Request, want string) {
} }
} }
func mustWriteHTTPResponse(t *testing.T, w io.Writer, fixturePath string) {
f, err := os.Open(fixturePath)
if err != nil {
t.Fatalf("error opening fixture file: %v", err)
}
if _, err = io.Copy(w, f); err != nil {
t.Fatalf("error writing response: %v", err)
}
}
func errorOption(*http.Request) error { func errorOption(*http.Request) error {
return errors.New("OptionFunc returns an error") return errors.New("OptionFunc returns an error")
} }
......
...@@ -74,7 +74,11 @@ func (i Pipeline) String() string { ...@@ -74,7 +74,11 @@ func (i Pipeline) String() string {
// PipelineList represents a GitLab list project pipelines // PipelineList represents a GitLab list project pipelines
// //
// GitLab API docs: https://docs.gitlab.com/ce/api/pipelines.html#list-project-pipelines // GitLab API docs: https://docs.gitlab.com/ce/api/pipelines.html#list-project-pipelines
type PipelineList []struct { type PipelineList []*PipelineInfo
// PipelineInfo shows the basic entities of a pipeline, mostly used as fields
// on other assets, like Commit.
type PipelineInfo struct {
ID int `json:"id"` ID int `json:"id"`
Status string `json:"status"` Status string `json:"status"`
Ref string `json:"ref"` Ref string `json:"ref"`
......
{
"id": "6104942438c14ec7bd21c6cd5bd995272b3faff6",
"short_id": "6104942438c",
"title": "Sanitize for network graph",
"author_name": "randx",
"author_email": "dmitriy.zaporozhets@gmail.com",
"committer_name": "Dmitriy",
"committer_email": "dmitriy.zaporozhets@gmail.com",
"message": "Sanitize for network graph",
"parent_ids": [
"ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba"
],
"last_pipeline" : {
"id": 8,
"ref": "master",
"sha": "2dc6aa325a317eda67812f05600bdf0fcdc70ab0",
"status": "created",
"web_url":"https://gitlab.com/gitlab-org/gitlab-ce/pipelines/54268416"
},
"stats": {
"additions": 15,
"deletions": 10,
"total": 25
},
"status": "running",
"project_id":13083
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment