|
| 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 | +) |
0 commit comments