This repository was archived by the owner on Jan 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathcommits.go
More file actions
83 lines (71 loc) · 2.48 KB
/
commits.go
File metadata and controls
83 lines (71 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) 2015 Ableton AG, Berlin. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
// Fragments of this file have been copied from the go-github (https://github.com/google/go-github)
// project, and is therefore licensed under the following copyright:
// Copyright 2013 The go-github AUTHORS. All rights reserved.
package travis
import (
"fmt"
"net/http"
)
// CommitsService handles communication with the commits
// related parts of the Travis CI API. As commits are not directly
// exposed as an endpoint, most of this service methods will fetch
// commits through the builds or jobs endpoint.
type CommitsService struct {
client *Client
}
// Commit represents a VCS commit as seen by Travis CI
type Commit struct {
Id uint `json:"id,omitempty"`
Sha string `json:"sha,omitempty"`
Branch string `json:"branch,omitempty"`
Message string `json:"message,omitempty"`
CommittedAt string `json:"committed_at,omitempty"`
AuthorName string `json:"author_name,omitempty"`
AuthorEmail string `json:"author_email,omitempty"`
CommitterName string `json:"committer_name,omitempty"`
CommitterEmail string `json:"committer_email,omitempty"`
CompareUrl string `json:"compare_url,omitempty"`
}
// Get fetches the commit that triggered a build based on the build id.
//
// Travis CI API docs: http://docs.travis-ci.com/api/#builds
func (cs *CommitsService) GetFromBuild(buildId uint) (*Commit, *http.Response, error) {
u, err := urlWithOptions(fmt.Sprintf("/builds/%d", buildId), nil)
if err != nil {
return nil, nil, err
}
req, err := cs.client.NewRequest("GET", u, nil, nil)
if err != nil {
return nil, nil, err
}
var buildResp getBuildResponse
resp, err := cs.client.Do(req, &buildResp)
if err != nil {
return nil, resp, err
}
return &buildResp.Commit, resp, nil
}
// List last commits attached to a repository builds.
//
// Travis CI API docs: http://docs.travis-ci.com/api/#builds
func (cs *CommitsService) ListFromRepository(repositorySlug string) ([]Commit, *http.Response, error) {
u, err := urlWithOptions(fmt.Sprintf("/repos/%s/builds", repositorySlug), nil)
if err != nil {
return nil, nil, err
}
req, err := cs.client.NewRequest("GET", u, nil, nil)
if err != nil {
return nil, nil, err
}
var buildsResp listBuildsResponse
resp, err := cs.client.Do(req, &buildsResp)
if err != nil {
return nil, resp, err
}
return buildsResp.Commits, resp, nil
}