Skip to content

Commit 523c18d

Browse files
Merge pull request #20 from rcchopra/git-app-support
git apps support
2 parents 248795f + 63c13a3 commit 523c18d

File tree

26 files changed

+1400
-2
lines changed

26 files changed

+1400
-2
lines changed

scm/apps.go

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
// Copyright 2017 Drone.IO Inc. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package scm
6+
7+
import (
8+
"context"
9+
"time"
10+
)
11+
12+
type (
13+
// App represents an SCM App.
14+
App struct {
15+
ID int64
16+
Slug string
17+
NodeID string
18+
Owner *User
19+
Name string
20+
Description string
21+
ExternalURL string
22+
HTMLURL string
23+
CreatedAt time.Time
24+
UpdatedAt time.Time
25+
Permissions *InstallationPermissions
26+
Events []string
27+
}
28+
29+
// Installation represents an Apps installation.
30+
Installation struct {
31+
ID int64
32+
NodeID string
33+
AppID int64
34+
AppSlug string
35+
TargetID int64
36+
Account *User
37+
AccessTokensURL string
38+
RepositoriesURL string
39+
HTMLURL string
40+
TargetType string
41+
SingleFileName string
42+
RepositorySelection string
43+
Events []string
44+
SingleFilePaths []string
45+
Permissions *InstallationPermissions
46+
CreatedAt time.Time
47+
UpdatedAt time.Time
48+
HasMultipleSingleFiles bool
49+
SuspendedBy *User
50+
SuspendedAt *time.Time
51+
}
52+
53+
// InstallationToken represents an installation token.
54+
InstallationToken struct {
55+
Token string
56+
ExpiresAt time.Time
57+
Permissions *InstallationPermissions
58+
Repositories []*Repository
59+
}
60+
61+
// InstallationTokenOptions allow restricting a token's access to specific repositories.
62+
InstallationTokenOptions struct {
63+
// The IDs of the repositories that the installation token can access.
64+
// Providing repository IDs restricts the access of an installation token to specific repositories.
65+
RepositoryIDs []int64 `json:"repository_ids,omitempty"`
66+
67+
// The names of the repositories that the installation token can access.
68+
// Providing repository names restricts the access of an installation token to specific repositories.
69+
Repositories []string `json:"repositories,omitempty"`
70+
71+
// The permissions granted to the access token.
72+
// The permissions object includes the permission names and their access type.
73+
Permissions *InstallationPermissions `json:"permissions,omitempty"`
74+
}
75+
76+
// InstallationPermissions lists the repository and organization permissions for an installation.
77+
InstallationPermissions struct {
78+
Actions string `json:"actions,omitempty"`
79+
Administration string `json:"administration,omitempty"`
80+
Blocking string `json:"blocking,omitempty"`
81+
Checks string `json:"checks,omitempty"`
82+
Contents string `json:"contents,omitempty"`
83+
ContentReferences string `json:"content_references,omitempty"`
84+
Deployments string `json:"deployments,omitempty"`
85+
Emails string `json:"emails,omitempty"`
86+
Environments string `json:"environments,omitempty"`
87+
Followers string `json:"followers,omitempty"`
88+
Issues string `json:"issues,omitempty"`
89+
Metadata string `json:"metadata,omitempty"`
90+
Members string `json:"members,omitempty"`
91+
OrganizationAdministration string `json:"organization_administration,omitempty"`
92+
OrganizationCustomRoles string `json:"organization_custom_roles,omitempty"`
93+
OrganizationHooks string `json:"organization_hooks,omitempty"`
94+
OrganizationPackages string `json:"organization_packages,omitempty"`
95+
OrganizationPlan string `json:"organization_plan,omitempty"`
96+
OrganizationPreReceiveHooks string `json:"organization_pre_receive_hooks,omitempty"`
97+
OrganizationProjects string `json:"organization_projects,omitempty"`
98+
OrganizationSecrets string `json:"organization_secrets,omitempty"`
99+
OrganizationSelfHostedRunners string `json:"organization_self_hosted_runners,omitempty"`
100+
OrganizationUserBlocking string `json:"organization_user_blocking,omitempty"`
101+
Packages string `json:"packages,omitempty"`
102+
Pages string `json:"pages,omitempty"`
103+
PullRequests string `json:"pull_requests,omitempty"`
104+
RepositoryHooks string `json:"repository_hooks,omitempty"`
105+
RepositoryProjects string `json:"repository_projects,omitempty"`
106+
RepositoryPreReceiveHooks string `json:"repository_pre_receive_hooks,omitempty"`
107+
Secrets string `json:"secrets,omitempty"`
108+
SecretScanningAlerts string `json:"secret_scanning_alerts,omitempty"`
109+
SecurityEvents string `json:"security_events,omitempty"`
110+
SingleFile string `json:"single_file,omitempty"`
111+
Statuses string `json:"statuses,omitempty"`
112+
TeamDiscussions string `json:"team_discussions,omitempty"`
113+
VulnerabilityAlerts string `json:"vulnerability_alerts,omitempty"`
114+
Workflows string `json:"workflows,omitempty"`
115+
}
116+
117+
// AppsService provides access to Apps-related functions.
118+
AppsService interface {
119+
// Get returns a single App. Passing the empty string will get
120+
// the authenticated App.
121+
Get(ctx context.Context, appSlug string) (*App, *Response, error)
122+
123+
// ListInstallations lists the installations that the current App has.
124+
ListInstallations(ctx context.Context, opts ListOptions) ([]*Installation, *Response, error)
125+
126+
// GetInstallation returns the specified installation.
127+
GetInstallation(ctx context.Context, id int64) (*Installation, *Response, error)
128+
129+
// ListUserInstallations lists installations that are accessible to the authenticated user.
130+
ListUserInstallations(ctx context.Context, opts ListOptions) ([]*Installation, *Response, error)
131+
132+
// SuspendInstallation suspends the specified installation.
133+
SuspendInstallation(ctx context.Context, id int64) (*Response, error)
134+
135+
// UnsuspendInstallation unsuspends the specified installation.
136+
UnsuspendInstallation(ctx context.Context, id int64) (*Response, error)
137+
138+
// DeleteInstallation deletes the specified installation.
139+
DeleteInstallation(ctx context.Context, id int64) (*Response, error)
140+
141+
// CreateInstallationToken creates a new installation token.
142+
CreateInstallationToken(ctx context.Context, id int64, opts *InstallationTokenOptions) (*InstallationToken, *Response, error)
143+
144+
// FindOrganizationInstallation finds the organization's installation information.
145+
FindOrganizationInstallation(ctx context.Context, org string) (*Installation, *Response, error)
146+
147+
// FindRepositoryInstallation finds the repository's installation information.
148+
FindRepositoryInstallation(ctx context.Context, owner, repo string) (*Installation, *Response, error)
149+
150+
// FindRepositoryInstallationByID finds the repository's installation information by repository ID.
151+
FindRepositoryInstallationByID(ctx context.Context, id int64) (*Installation, *Response, error)
152+
153+
// FindUserInstallation finds the user's installation information.
154+
FindUserInstallation(ctx context.Context, user string) (*Installation, *Response, error)
155+
}
156+
)

scm/client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ type (
110110
// Services used for communicating with the API.
111111
Driver Driver
112112
Linker Linker
113+
Apps AppsService
113114
Contents ContentService
114115
Git GitService
115116
Organizations OrganizationService
@@ -230,7 +231,7 @@ func (c *Client) Do(ctx context.Context, in *Request) (*Response, error) {
230231
return newResponse(res), nil
231232
}
232233

233-
//requestDetails checks if RequestContextKey exits in the context
234+
// requestDetails checks if RequestContextKey exits in the context
234235
func (c *Client) requestDetails(ctx context.Context) (*RequestDetails, error) {
235236
requestDetails, _ := ctx.Value(RequestContextKey{}).(*RequestDetails)
236237
return requestDetails, nil

scm/driver/azure/apps.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright 2017 Drone.IO Inc. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package azure
6+
7+
import (
8+
"context"
9+
10+
"github.com/drone/go-scm/scm"
11+
)
12+
13+
type appsService struct {
14+
client *wrapper
15+
}
16+
17+
func (s *appsService) Get(ctx context.Context, appSlug string) (*scm.App, *scm.Response, error) {
18+
return nil, nil, scm.ErrNotSupported
19+
}
20+
21+
func (s *appsService) ListInstallations(ctx context.Context, opts scm.ListOptions) ([]*scm.Installation, *scm.Response, error) {
22+
return nil, nil, scm.ErrNotSupported
23+
}
24+
25+
func (s *appsService) GetInstallation(ctx context.Context, id int64) (*scm.Installation, *scm.Response, error) {
26+
return nil, nil, scm.ErrNotSupported
27+
}
28+
29+
func (s *appsService) ListUserInstallations(ctx context.Context, opts scm.ListOptions) ([]*scm.Installation, *scm.Response, error) {
30+
return nil, nil, scm.ErrNotSupported
31+
}
32+
33+
func (s *appsService) SuspendInstallation(ctx context.Context, id int64) (*scm.Response, error) {
34+
return nil, scm.ErrNotSupported
35+
}
36+
37+
func (s *appsService) UnsuspendInstallation(ctx context.Context, id int64) (*scm.Response, error) {
38+
return nil, scm.ErrNotSupported
39+
}
40+
41+
func (s *appsService) DeleteInstallation(ctx context.Context, id int64) (*scm.Response, error) {
42+
return nil, scm.ErrNotSupported
43+
}
44+
45+
func (s *appsService) CreateInstallationToken(ctx context.Context, id int64, opts *scm.InstallationTokenOptions) (*scm.InstallationToken, *scm.Response, error) {
46+
return nil, nil, scm.ErrNotSupported
47+
}
48+
49+
func (s *appsService) FindOrganizationInstallation(ctx context.Context, org string) (*scm.Installation, *scm.Response, error) {
50+
return nil, nil, scm.ErrNotSupported
51+
}
52+
53+
func (s *appsService) FindRepositoryInstallation(ctx context.Context, owner, repo string) (*scm.Installation, *scm.Response, error) {
54+
return nil, nil, scm.ErrNotSupported
55+
}
56+
57+
func (s *appsService) FindRepositoryInstallationByID(ctx context.Context, id int64) (*scm.Installation, *scm.Response, error) {
58+
return nil, nil, scm.ErrNotSupported
59+
}
60+
61+
func (s *appsService) FindUserInstallation(ctx context.Context, user string) (*scm.Installation, *scm.Response, error) {
62+
return nil, nil, scm.ErrNotSupported
63+
}

scm/driver/azure/azure.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func New(uri, owner, project string) (*scm.Client, error) {
3838
// initialize services
3939
client.Driver = scm.DriverAzure
4040
client.Linker = &linker{base.String()}
41+
client.Apps = &appsService{client}
4142
client.Contents = &contentService{client}
4243
client.Git = &gitService{client}
4344
client.Issues = &issueService{client}

scm/driver/bitbucket/apps.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright 2017 Drone.IO Inc. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package bitbucket
6+
7+
import (
8+
"context"
9+
10+
"github.com/drone/go-scm/scm"
11+
)
12+
13+
type appsService struct {
14+
client *wrapper
15+
}
16+
17+
func (s *appsService) Get(ctx context.Context, appSlug string) (*scm.App, *scm.Response, error) {
18+
return nil, nil, scm.ErrNotSupported
19+
}
20+
21+
func (s *appsService) ListInstallations(ctx context.Context, opts scm.ListOptions) ([]*scm.Installation, *scm.Response, error) {
22+
return nil, nil, scm.ErrNotSupported
23+
}
24+
25+
func (s *appsService) GetInstallation(ctx context.Context, id int64) (*scm.Installation, *scm.Response, error) {
26+
return nil, nil, scm.ErrNotSupported
27+
}
28+
29+
func (s *appsService) ListUserInstallations(ctx context.Context, opts scm.ListOptions) ([]*scm.Installation, *scm.Response, error) {
30+
return nil, nil, scm.ErrNotSupported
31+
}
32+
33+
func (s *appsService) SuspendInstallation(ctx context.Context, id int64) (*scm.Response, error) {
34+
return nil, scm.ErrNotSupported
35+
}
36+
37+
func (s *appsService) UnsuspendInstallation(ctx context.Context, id int64) (*scm.Response, error) {
38+
return nil, scm.ErrNotSupported
39+
}
40+
41+
func (s *appsService) DeleteInstallation(ctx context.Context, id int64) (*scm.Response, error) {
42+
return nil, scm.ErrNotSupported
43+
}
44+
45+
func (s *appsService) CreateInstallationToken(ctx context.Context, id int64, opts *scm.InstallationTokenOptions) (*scm.InstallationToken, *scm.Response, error) {
46+
return nil, nil, scm.ErrNotSupported
47+
}
48+
49+
func (s *appsService) FindOrganizationInstallation(ctx context.Context, org string) (*scm.Installation, *scm.Response, error) {
50+
return nil, nil, scm.ErrNotSupported
51+
}
52+
53+
func (s *appsService) FindRepositoryInstallation(ctx context.Context, owner, repo string) (*scm.Installation, *scm.Response, error) {
54+
return nil, nil, scm.ErrNotSupported
55+
}
56+
57+
func (s *appsService) FindRepositoryInstallationByID(ctx context.Context, id int64) (*scm.Installation, *scm.Response, error) {
58+
return nil, nil, scm.ErrNotSupported
59+
}
60+
61+
func (s *appsService) FindUserInstallation(ctx context.Context, user string) (*scm.Installation, *scm.Response, error) {
62+
return nil, nil, scm.ErrNotSupported
63+
}

scm/driver/bitbucket/bitbucket.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func New(uri string) (*scm.Client, error) {
3131
// initialize services
3232
client.Driver = scm.DriverBitbucket
3333
client.Linker = &linker{"https://bitbucket.org/"}
34+
client.Apps = &appsService{client}
3435
client.Contents = &contentService{client}
3536
client.Git = &gitService{client}
3637
client.Issues = &issueService{client}

scm/driver/gitea/apps.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright 2017 Drone.IO Inc. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package gitea
6+
7+
import (
8+
"context"
9+
10+
"github.com/drone/go-scm/scm"
11+
)
12+
13+
type appsService struct {
14+
client *wrapper
15+
}
16+
17+
func (s *appsService) Get(ctx context.Context, appSlug string) (*scm.App, *scm.Response, error) {
18+
return nil, nil, scm.ErrNotSupported
19+
}
20+
21+
func (s *appsService) ListInstallations(ctx context.Context, opts scm.ListOptions) ([]*scm.Installation, *scm.Response, error) {
22+
return nil, nil, scm.ErrNotSupported
23+
}
24+
25+
func (s *appsService) GetInstallation(ctx context.Context, id int64) (*scm.Installation, *scm.Response, error) {
26+
return nil, nil, scm.ErrNotSupported
27+
}
28+
29+
func (s *appsService) ListUserInstallations(ctx context.Context, opts scm.ListOptions) ([]*scm.Installation, *scm.Response, error) {
30+
return nil, nil, scm.ErrNotSupported
31+
}
32+
33+
func (s *appsService) SuspendInstallation(ctx context.Context, id int64) (*scm.Response, error) {
34+
return nil, scm.ErrNotSupported
35+
}
36+
37+
func (s *appsService) UnsuspendInstallation(ctx context.Context, id int64) (*scm.Response, error) {
38+
return nil, scm.ErrNotSupported
39+
}
40+
41+
func (s *appsService) DeleteInstallation(ctx context.Context, id int64) (*scm.Response, error) {
42+
return nil, scm.ErrNotSupported
43+
}
44+
45+
func (s *appsService) CreateInstallationToken(ctx context.Context, id int64, opts *scm.InstallationTokenOptions) (*scm.InstallationToken, *scm.Response, error) {
46+
return nil, nil, scm.ErrNotSupported
47+
}
48+
49+
func (s *appsService) FindOrganizationInstallation(ctx context.Context, org string) (*scm.Installation, *scm.Response, error) {
50+
return nil, nil, scm.ErrNotSupported
51+
}
52+
53+
func (s *appsService) FindRepositoryInstallation(ctx context.Context, owner, repo string) (*scm.Installation, *scm.Response, error) {
54+
return nil, nil, scm.ErrNotSupported
55+
}
56+
57+
func (s *appsService) FindRepositoryInstallationByID(ctx context.Context, id int64) (*scm.Installation, *scm.Response, error) {
58+
return nil, nil, scm.ErrNotSupported
59+
}
60+
61+
func (s *appsService) FindUserInstallation(ctx context.Context, user string) (*scm.Installation, *scm.Response, error) {
62+
return nil, nil, scm.ErrNotSupported
63+
}

scm/driver/gitea/gitea.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ func New(uri string) (*scm.Client, error) {
3232
// initialize services
3333
client.Driver = scm.DriverGitea
3434
client.Linker = &linker{base.String()}
35+
client.Apps = &appsService{client}
3536
client.Contents = &contentService{client}
3637
client.Git = &gitService{client}
3738
client.Issues = &issueService{client}
38-
client.Milestones = & milestoneService{client}
39+
client.Milestones = &milestoneService{client}
3940
client.Organizations = &organizationService{client}
4041
client.PullRequests = &pullService{client}
4142
client.Repositories = &repositoryService{client}

0 commit comments

Comments
 (0)