forked from drone/go-scm
-
Notifications
You must be signed in to change notification settings - Fork 83
/
repo.go
205 lines (169 loc) · 5.99 KB
/
repo.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
// 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"
)
const (
// NoPermission means the user has no permission to access the repository
NoPermission = "none"
// ReadPermission means the user has read access to the repository
ReadPermission = "read"
// WritePermission means the user has write/push access to the repository
WritePermission = "write"
// AdminPermission means the user has full admin access to the repository
AdminPermission = "admin"
)
type (
// Repository represents a git repository.
Repository struct {
ID string
Namespace string
Name string
FullName string
Perm *Perm
Branch string
Private bool
Archived bool
Clone string
CloneSSH string
Link string
Created time.Time
Updated time.Time
}
// RepositoryInput provides the input fields required for
// creating a new repository.
RepositoryInput struct {
Namespace string
Name string
Description string
Homepage string
Private bool
}
// Perm represents a user's repository permissions.
Perm struct {
Pull bool
Push bool
Admin bool
}
// Hook represents a repository hook.
Hook struct {
ID string
Name string
Target string
Events []string
Active bool
SkipVerify bool
}
// HookInput provides the input fields required for
// creating or updating repository webhooks.
HookInput struct {
Name string
Target string
Secret string
Events HookEvents
SkipVerify bool
// NativeEvents are used to create hooks with
// provider-specific event types that cannot be
// abstracted or represented in HookEvents.
NativeEvents []string
}
// HookEvents represents supported hook events.
HookEvents struct {
Branch bool
Deployment bool
DeploymentStatus bool
Issue bool
IssueComment bool
PullRequest bool
PullRequestComment bool
Push bool
Release bool
Review bool
ReviewComment bool
Tag bool
}
// CombinedStatus is the latest statuses for a ref.
CombinedStatus struct {
State State
Sha string
Statuses []*Status
}
// Status represents a commit status.
Status struct {
State State
Label string
Desc string
Target string
Link string
}
// StatusInput provides the input fields required for
// creating or updating commit statuses.
StatusInput struct {
State State
Label string
Desc string
Target string
Link string
}
// DeployStatus represents a deployment status.
DeployStatus struct {
Number int64
State State
Desc string
Target string
Environment string
EnvironmentURL string
}
// RepositoryService provides access to repository resources.
RepositoryService interface {
// Find returns a repository by name.
Find(context.Context, string) (*Repository, *Response, error)
// FindHook returns a repository hook.
FindHook(context.Context, string, string) (*Hook, *Response, error)
// FindPerms returns repository permissions.
FindPerms(context.Context, string) (*Perm, *Response, error)
// List returns a list of repositories.
List(context.Context, *ListOptions) ([]*Repository, *Response, error)
// ListOrganisation returns a list of repositories for a given organisation
ListOrganisation(context.Context, string, *ListOptions) ([]*Repository, *Response, error)
// ListUser returns a list of repositories for a given user.
ListUser(context.Context, string, *ListOptions) ([]*Repository, *Response, error)
// ListLabels returns the labels on a repo
ListLabels(context.Context, string, *ListOptions) ([]*Label, *Response, error)
// ListHooks returns a list or repository hooks.
ListHooks(context.Context, string, *ListOptions) ([]*Hook, *Response, error)
// ListStatus returns a list of commit statuses.
ListStatus(context.Context, string, string, *ListOptions) ([]*Status, *Response, error)
// FindCombinedStatus returns the combined status for a ref
FindCombinedStatus(ctx context.Context, repo, ref string) (*CombinedStatus, *Response, error)
// Create creates a new repository .
Create(context.Context, *RepositoryInput) (*Repository, *Response, error)
// Fork creates a new repository as a fork of an existing one.
Fork(context.Context, *RepositoryInput, string) (*Repository, *Response, error)
// CreateHook creates a new repository webhook.
CreateHook(context.Context, string, *HookInput) (*Hook, *Response, error)
// UpdateHook edit a repository webhook
UpdateHook(context.Context, string, *HookInput) (*Hook, *Response, error)
// CreateStatus creates a new commit status.
CreateStatus(context.Context, string, string, *StatusInput) (*Status, *Response, error)
// DeleteHook deletes a repository webhook.
DeleteHook(context.Context, string, string) (*Response, error)
// IsCollaborator returns true if the user is a collaborator on the repository
IsCollaborator(ctx context.Context, repo string, user string) (bool, *Response, error)
// AddCollaborator adds a collaborator to the repository
AddCollaborator(ctx context.Context, repo, user, permission string) (bool, bool, *Response, error)
// ListCollaborators lists the collaborators on a repository
ListCollaborators(ctx context.Context, repo string, ops *ListOptions) ([]User, *Response, error)
// FindUserPermission returns the user's permission level for a repo
FindUserPermission(ctx context.Context, repo string, user string) (string, *Response, error)
// Delete deletes a repository
Delete(ctx context.Context, repo string) (*Response, error)
}
)
// TODO(bradrydzewski): Add endpoint to get a repository deploy key
// TODO(bradrydzewski): Add endpoint to list repository deploy keys
// TODO(bradrydzewski): Add endpoint to create a repository deploy key
// TODO(bradrydzewski): Add endpoint to delete a repository deploy key