forked from jenkins-x/jx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.go
211 lines (153 loc) · 7.13 KB
/
interface.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
package gits
import (
"io"
"time"
"github.com/google/go-github/github"
"github.com/jenkins-x/jx/pkg/auth"
gitcfg "gopkg.in/src-d/go-git.v4/config"
)
// OrganisationLister returns a slice of GitOrganisation
//go:generate pegomock generate github.com/jenkins-x/jx/pkg/gits OrganisationLister -o mocks/organisation_lister.go
type OrganisationLister interface {
ListOrganisations() ([]GitOrganisation, error)
}
// OrganisationChecker verifies if an user is member of an organization
//go:generate pegomock generate github.com/jenkins-x/jx/pkg/gits OrganisationChecker -o mocks/organisation_checker.go
type OrganisationChecker interface {
IsUserInOrganisation(user string, organisation string) (bool, error)
}
// GitProvider is the interface for abstracting use of different git provider APIs
//go:generate pegomock generate github.com/jenkins-x/jx/pkg/gits GitProvider -o mocks/git_provider.go
type GitProvider interface {
OrganisationLister
ListRepositories(org string) ([]*GitRepository, error)
CreateRepository(org string, name string, private bool) (*GitRepository, error)
GetRepository(org string, name string) (*GitRepository, error)
DeleteRepository(org string, name string) error
ForkRepository(originalOrg string, name string, destinationOrg string) (*GitRepository, error)
RenameRepository(org string, name string, newName string) (*GitRepository, error)
ValidateRepositoryName(org string, name string) error
CreatePullRequest(data *GitPullRequestArguments) (*GitPullRequest, error)
UpdatePullRequestStatus(pr *GitPullRequest) error
GetPullRequest(owner string, repo *GitRepositoryInfo, number int) (*GitPullRequest, error)
GetPullRequestCommits(owner string, repo *GitRepositoryInfo, number int) ([]*GitCommit, error)
PullRequestLastCommitStatus(pr *GitPullRequest) (string, error)
ListCommitStatus(org string, repo string, sha string) ([]*GitRepoStatus, error)
UpdateCommitStatus(org string, repo string, sha string, status *GitRepoStatus) (*GitRepoStatus, error)
MergePullRequest(pr *GitPullRequest, message string) error
CreateWebHook(data *GitWebHookArguments) error
IsGitHub() bool
IsGitea() bool
IsBitbucketCloud() bool
IsBitbucketServer() bool
IsGerrit() bool
Kind() string
GetIssue(org string, name string, number int) (*GitIssue, error)
IssueURL(org string, name string, number int, isPull bool) string
SearchIssues(org string, name string, query string) ([]*GitIssue, error)
SearchIssuesClosedSince(org string, name string, t time.Time) ([]*GitIssue, error)
CreateIssue(owner string, repo string, issue *GitIssue) (*GitIssue, error)
HasIssues() bool
AddPRComment(pr *GitPullRequest, comment string) error
CreateIssueComment(owner string, repo string, number int, comment string) error
UpdateRelease(owner string, repo string, tag string, releaseInfo *GitRelease) error
ListReleases(org string, name string) ([]*GitRelease, error)
// returns the path relative to the Jenkins URL to trigger webhooks on this kind of repository
//
// e.g. for GitHub its /github-webhook/
// other examples include:
//
// * gitlab: /gitlab/notify_commit
// https://github.com/elvanja/jenkins-gitlab-hook-plugin#notify-commit-hook
//
// * git plugin
// /git/notifyCommit?url=
// http://kohsuke.org/2011/12/01/polling-must-die-triggering-jenkins-builds-from-a-git-hook/
//
// * gitea
// /gitea-webhook/post
//
// * generic webhook
// /generic-webhook-trigger/invoke?token=abc123
// https://wiki.jenkins.io/display/JENKINS/Generic+Webhook+Trigger+Plugin
JenkinsWebHookPath(gitURL string, secret string) string
// Label returns the Git service label or name
Label() string
// ServerURL returns the Git server URL
ServerURL() string
// BranchArchiveURL returns a URL to the ZIP archive for the git branch
BranchArchiveURL(org string, name string, branch string) string
// Returns the current username
CurrentUsername() string
// Returns the current user auth
UserAuth() auth.UserAuth
// Returns user info, if possible
UserInfo(username string) *GitUser
AddCollaborator(string, string, string) error
// TODO Refactor to remove bespoke types when we implement another provider
ListInvitations() ([]*github.RepositoryInvitation, *github.Response, error)
// TODO Refactor to remove bespoke types when we implement another provider
AcceptInvitation(int64) (*github.Response, error)
}
// Gitter defines common git actions used by Jenkins X via git cli
//go:generate pegomock generate github.com/jenkins-x/jx/pkg/gits Gitter -o mocks/gitter.go
type Gitter interface {
FindGitConfigDir(dir string) (string, string, error)
ToGitLabels(names []string) []GitLabel
PrintCreateRepositoryGenerateAccessToken(server *auth.AuthServer, username string, o io.Writer)
Status(dir string) error
Server(dir string) (string, error)
Info(dir string) (*GitRepositoryInfo, error)
IsFork(gitProvider GitProvider, gitInfo *GitRepositoryInfo, dir string) (bool, error)
Version() (string, error)
RepoName(org, repoName string) string
Username(dir string) (string, error)
SetUsername(dir string, username string) error
Email(dir string) (string, error)
SetEmail(dir string, email string) error
GetAuthorEmailForCommit(dir string, sha string) (string, error)
Init(dir string) error
Clone(url string, directory string) error
Push(dir string) error
PushMaster(dir string) error
PushTag(dir string, tag string) error
CreatePushURL(cloneURL string, userAuth *auth.UserAuth) (string, error)
ForcePushBranch(dir string, localBranch string, remoteBranch string) error
CloneOrPull(url string, directory string) error
Pull(dir string) error
PullRemoteBranches(dir string) error
PullUpstream(dir string) error
AddRemote(dir string, name string, url string) error
SetRemoteURL(dir string, name string, gitURL string) error
UpdateRemote(dir, url string) error
DiscoverRemoteGitURL(gitConf string) (string, error)
DiscoverUpstreamGitURL(gitConf string) (string, error)
RemoteBranches(dir string) ([]string, error)
RemoteBranchNames(dir string, prefix string) ([]string, error)
GetRemoteUrl(config *gitcfg.Config, name string) string
Branch(dir string) (string, error)
CreateBranch(dir string, branch string) error
CheckoutRemoteBranch(dir string, branch string) error
Checkout(dir string, branch string) error
CheckoutOrphan(dir string, branch string) error
ConvertToValidBranchName(name string) string
FetchBranch(dir string, repo string, refspec string) error
Stash(dir string) error
Remove(dir, fileName string) error
RemoveForce(dir, fileName string) error
CleanForce(dir, fileName string) error
Add(dir string, args ...string) error
CommitIfChanges(dir string, message string) error
CommitDir(dir string, message string) error
AddCommmit(dir string, msg string) error
HasChanges(dir string) (bool, error)
Diff(dir string) (string, error)
GetPreviousGitTagSHA(dir string) (string, error)
GetCurrentGitTagSHA(dir string) (string, error)
FetchTags(dir string) error
Tags(dir string) ([]string, error)
CreateTag(dir string, tag string, msg string) error
GetRevisionBeforeDate(dir string, t time.Time) (string, error)
GetRevisionBeforeDateText(dir string, dateText string) (string, error)
DeleteRemoteBranch(dir string, remoteName string, branch string) error
}