-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvcs_revision.go
52 lines (43 loc) · 1.29 KB
/
vcs_revision.go
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
package scalr
import (
"context"
"errors"
"fmt"
"net/url"
)
// Compile-time proof of interface implementation.
var _ VcsRevisions = (*vcsRevisions)(nil)
// VCS revision implements VcsRevisions.
type vcsRevisions struct {
client *Client
}
// VcsRevisions describes all the vcs revisions related methods that the Scalr API supports.
type VcsRevisions interface {
// Read reads a VCS revision by its ID.
Read(ctx context.Context, vcsRevisionID string) (*VcsRevision, error)
}
// VcsRevision represents the VCS metadata
type VcsRevision struct {
ID string `jsonapi:"primary,vcs-revisions"`
Branch string `jsonapi:"attr,branch"`
CommitSha string `jsonapi:"attr,commit-sha"`
CommitMessage string `jsonapi:"attr,commit-message"`
SenderUsername string `jsonapi:"attr,sender-username"`
}
// Read a VCS revision by its ID.
func (s *vcsRevisions) Read(ctx context.Context, vcsRevisionID string) (*VcsRevision, error) {
if !validStringID(&vcsRevisionID) {
return nil, errors.New("invalid value for vcs revision ID")
}
u := fmt.Sprintf("vcs-revisions/%s", url.QueryEscape(vcsRevisionID))
req, err := s.client.newRequest("GET", u, nil)
if err != nil {
return nil, err
}
r := &VcsRevision{}
err = s.client.do(ctx, req, r)
if err != nil {
return nil, err
}
return r, nil
}