forked from drone/go-scm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git.go
98 lines (78 loc) · 2.9 KB
/
git.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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright 2017 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package scm
import (
"context"
"time"
)
// EmptyCommit is an empty commit sha.
const EmptyCommit = "0000000000000000000000000000000000000000"
type (
// Reference represents a git reference.
Reference struct {
Name string
Path string
Sha string
}
// ReferenceInput provides a SHA for creating a reference.
ReferenceInput struct {
Name string
Sha string
}
// Commit represents a repository commit.
Commit struct {
Sha string
Message string
Author Signature
Committer Signature
Link string
}
// CommitListOptions provides options for querying a
// list of repository commits.
CommitListOptions struct {
Ref string
Page int
Size int
Path string
}
// Signature identifies a git commit creator.
Signature struct {
Name string
Email string
Date time.Time
// Fields are optional. The provider may choose to
// include account information in the response.
Login string
Avatar string
}
// GitService provides access to git resources.
GitService interface {
// CreateBranch creates a git branch by name given a sha.
CreateBranch(ctx context.Context, repo string, params *ReferenceInput) (*Response, error)
// FindBranch finds a git branch by name.
FindBranch(ctx context.Context, repo, name string) (*Reference, *Response, error)
// FindCommit finds a git commit by ref.
FindCommit(ctx context.Context, repo, ref string) (*Commit, *Response, error)
// FindTag finds a git tag by name.
FindTag(ctx context.Context, repo, name string) (*Reference, *Response, error)
// ListBranches returns a list of git branches.
ListBranches(ctx context.Context, repo string, opts ListOptions) ([]*Reference, *Response, error)
// ListBranchesV2 returns a list of git branches based on the searchTerm passed.
ListBranchesV2(ctx context.Context, repo string, opts BranchListOptions) ([]*Reference, *Response, error)
// ListCommits returns a list of git commits.
ListCommits(ctx context.Context, repo string, opts CommitListOptions) ([]*Commit, *Response, error)
// ListChanges returns the changeset of a commit.
ListChanges(ctx context.Context, repo, ref string, opts ListOptions) ([]*Change, *Response, error)
// ListTags returns a list of git tags.
ListTags(ctx context.Context, repo string, opts ListOptions) ([]*Reference, *Response, error)
// CompareChanges returns the changeset between two
// commits. If the source commit is not an ancestor
// of the target commit, it is up to the driver to
// return a 2-way or 3-way diff changeset.
CompareChanges(ctx context.Context, repo, source, target string, opts ListOptions) ([]*Change, *Response, error)
}
// CreateBranch is a type alias for upstream projects
// that use the previous CreateBranch type name.
CreateBranch = ReferenceInput
)