Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support Enterprise Apps (not ready - private beta) #3273

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions github/enterprise_actions_runners.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,4 @@

return s.client.Do(ctx, req, nil)
}

Check failure on line 140 in github/enterprise_actions_runners.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)
107 changes: 107 additions & 0 deletions github/enterprise_apps.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Copyright 2020 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package github

import (
"context"
"fmt"
)

// InstallableOrganization represents a GitHub organization that can be used to install enteprise apps.
type InstallableOrganization struct {
ID *int64 `json:"id,omitempty"`
Login *string `json:"login,omitempty"`
AccessibleRepositoriesUrl *string `json:"accessible_repositories_url,omitempty"`

Check failure on line 17 in github/enterprise_apps.go

View workflow job for this annotation

GitHub Actions / lint

ST1003: struct field AccessibleRepositoriesUrl should be AccessibleRepositoriesURL (stylecheck)
}

// ListRunnerApplicationDownloads lists self-hosted runner application binaries that can be downloaded and run.

Check failure on line 20 in github/enterprise_apps.go

View workflow job for this annotation

GitHub Actions / lint

ST1020: comment on exported method ListOrganizations should be of the form "ListOrganizations ..." (stylecheck)
//
// GitHub API docs: TBD
//
//meta:operation GET /enterprises/{enterprise}/apps/installable_organization
func (s *EnterpriseService) ListOrganizations(ctx context.Context, enterprise string) ([]*InstallableOrganization, *Response, error) {
u := fmt.Sprintf("enterprises/%v/apps/installable_organization", enterprise)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err

Check warning on line 29 in github/enterprise_apps.go

View check run for this annotation

Codecov / codecov/patch

github/enterprise_apps.go#L25-L29

Added lines #L25 - L29 were not covered by tests
}

var orgs []*InstallableOrganization
resp, err := s.client.Do(ctx, req, &orgs)
if err != nil {
return nil, resp, err

Check warning on line 35 in github/enterprise_apps.go

View check run for this annotation

Codecov / codecov/patch

github/enterprise_apps.go#L32-L35

Added lines #L32 - L35 were not covered by tests
}

return orgs, resp, nil

Check warning on line 38 in github/enterprise_apps.go

View check run for this annotation

Codecov / codecov/patch

github/enterprise_apps.go#L38

Added line #L38 was not covered by tests
}

// ListOrgInstallations list all apps installed on the specified organization.
//
// GitHub API docs: TBD
//
//meta:operation GET /enterprises/{enterprise}/apps/organizations/{org1}/installations
func (s *EnterpriseService) ListOrgInstallations(ctx context.Context, enterprise string, org string) ([]*Installation, *Response, error) {
u := fmt.Sprintf("enterprises/%v/apps/organizations/%v/installations", enterprise, org)

Check warning on line 47 in github/enterprise_apps.go

View check run for this annotation

Codecov / codecov/patch

github/enterprise_apps.go#L46-L47

Added lines #L46 - L47 were not covered by tests

req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err

Check warning on line 51 in github/enterprise_apps.go

View check run for this annotation

Codecov / codecov/patch

github/enterprise_apps.go#L49-L51

Added lines #L49 - L51 were not covered by tests
}

var installations []*Installation
resp, err := s.client.Do(ctx, req, installations)
if err != nil {
return nil, resp, err

Check warning on line 57 in github/enterprise_apps.go

View check run for this annotation

Codecov / codecov/patch

github/enterprise_apps.go#L54-L57

Added lines #L54 - L57 were not covered by tests
}

return installations, resp, nil

Check warning on line 60 in github/enterprise_apps.go

View check run for this annotation

Codecov / codecov/patch

github/enterprise_apps.go#L60

Added line #L60 was not covered by tests
}

type InstallAppRequest struct {
// ClientID is the client ID of the GitHub App that should be installed.
ClientID string
// RepositorySelection is the type of repository selection requested.
// Possible values are: "none", "all", "subset".
RepositorySelection *string `json:"repository_selection"`
}

// InstallApp installs a GitHub App on the specified organization.
//
// GitHub API docs: TBD
//
//meta:operation POST /enterprises/{enterprise}/apps/organizations/{org1}/installation
func (s *EnterpriseService) InstallApp(ctx context.Context, enterprise string, org string, request *InstallAppRequest) (*Installation, *Response, error) {
u := fmt.Sprintf("enterprises/%v/apps/organizations/%v/installation", enterprise, org)

Check warning on line 77 in github/enterprise_apps.go

View check run for this annotation

Codecov / codecov/patch

github/enterprise_apps.go#L76-L77

Added lines #L76 - L77 were not covered by tests

req, err := s.client.NewRequest("POST", u, request)
if err != nil {
return nil, nil, err

Check warning on line 81 in github/enterprise_apps.go

View check run for this annotation

Codecov / codecov/patch

github/enterprise_apps.go#L79-L81

Added lines #L79 - L81 were not covered by tests
}

installation := new(Installation)
resp, err := s.client.Do(ctx, req, installation)
if err != nil {
return nil, resp, err

Check warning on line 87 in github/enterprise_apps.go

View check run for this annotation

Codecov / codecov/patch

github/enterprise_apps.go#L84-L87

Added lines #L84 - L87 were not covered by tests
}

return installation, resp, nil

Check warning on line 90 in github/enterprise_apps.go

View check run for this annotation

Codecov / codecov/patch

github/enterprise_apps.go#L90

Added line #L90 was not covered by tests
}

// UninstallApp uninstalls the GitHub App for the Enterprise-owned organization
//
// GitHub API docs: TBD
//
//meta:operation DELETE /enterprises/{enterprise}/apps/organizations/{org}/installations/{installation_id}
func (s *EnterpriseService) UninstallApp(ctx context.Context, enterprise string, org string, installationID string) (*Response, error) {
u := fmt.Sprintf("enterprises/%v/apps/organizations/%v/installations/%v", enterprise, org, installationID)

Check warning on line 99 in github/enterprise_apps.go

View check run for this annotation

Codecov / codecov/patch

github/enterprise_apps.go#L98-L99

Added lines #L98 - L99 were not covered by tests

req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err

Check warning on line 103 in github/enterprise_apps.go

View check run for this annotation

Codecov / codecov/patch

github/enterprise_apps.go#L101-L103

Added lines #L101 - L103 were not covered by tests
}

return s.client.Do(ctx, req, nil)

Check warning on line 106 in github/enterprise_apps.go

View check run for this annotation

Codecov / codecov/patch

github/enterprise_apps.go#L106

Added line #L106 was not covered by tests
}
Loading