Skip to content

Commit

Permalink
chore: removing github app web flow install code
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed Oct 14, 2024
1 parent cbe94e6 commit 8b022a3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 35 deletions.
27 changes: 22 additions & 5 deletions api/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ import (
"github.com/sirupsen/logrus"
)

// RepoInstall is the configuration for installing a repo into the SCM.
type RepoInstall struct {
OrgSCMID int64
RepoSCMID int64
AppInstalled bool
InstallID int64
RepoAdded bool
InstallURL string
InstallCallback
}

// InstallCallback is the callback configuration for the installation.
type InstallCallback struct {
Type string
Port string
}

// HandleInstallCallback represents the API handler to
// process an SCM app installation for Vela.
func HandleInstallCallback(c *gin.Context) {
Expand Down Expand Up @@ -120,10 +137,10 @@ func Install(c *gin.Context) {
p := util.FormParameter(c, "port")

// capture query params
ri := &types.RepoInstall{
ri := &RepoInstall{
OrgSCMID: int64(orgSCMID),
RepoSCMID: int64(repoSCMID),
InstallCallback: types.InstallCallback{
InstallCallback: InstallCallback{
Type: t,
Port: p,
},
Expand Down Expand Up @@ -254,7 +271,7 @@ func GetInstallInfo(c *gin.Context) {
}

// GetRepoInstallInfo retrieves the repo information required for installation, such as org and repo ID for the given org and repo name.
func GetRepoInstallInfo(ctx context.Context, userClient *github.Client, appClient *github.Client, u *types.User, r *types.Repo) (*types.RepoInstall, error) {
func GetRepoInstallInfo(ctx context.Context, userClient *github.Client, appClient *github.Client, u *types.User, r *types.Repo) (*RepoInstall, error) {
// client := c.newClientToken(ctx, u.GetToken())

// send an API call to get the org info
Expand All @@ -273,7 +290,7 @@ func GetRepoInstallInfo(ctx context.Context, userClient *github.Client, appClien
return nil, err
}

ri := &types.RepoInstall{
ri := &RepoInstall{
OrgSCMID: orgID,
RepoSCMID: repoInfo.GetID(),
}
Expand Down Expand Up @@ -304,7 +321,7 @@ func GetRepoInstallInfo(ctx context.Context, userClient *github.Client, appClien
}

// GetRepoInstallURL takes RepoInstall configurations and returns the SCM URL for installing the application.
func GetRepoInstallURL(ctx context.Context, appClient *github.Client, ri *types.RepoInstall) (string, error) {
func GetRepoInstallURL(ctx context.Context, appClient *github.Client, ri *RepoInstall) (string, error) {
// retrieve the authenticated app information
// required for slug and HTML URL
app, _, err := appClient.Apps.Get(ctx, "")
Expand Down
17 changes: 0 additions & 17 deletions api/types/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,6 @@ import (
"strings"
)

// RepoInstall is the configuration for installing a repo into the SCM.
type RepoInstall struct {
OrgSCMID int64
RepoSCMID int64
AppInstalled bool
InstallID int64
RepoAdded bool
InstallURL string
InstallCallback
}

// InstallCallback is the callback configuration for the installation.
type InstallCallback struct {
Type string
Port string
}

// Repo is the API representation of a repo.
//
// swagger:model Repo
Expand Down
2 changes: 0 additions & 2 deletions router/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package router
import (
"github.com/gin-gonic/gin"

"github.com/go-vela/server/api"
"github.com/go-vela/server/api/build"
"github.com/go-vela/server/api/repo"
"github.com/go-vela/server/router/middleware"
Expand Down Expand Up @@ -74,7 +73,6 @@ func RepoHandlers(base *gin.RouterGroup) {
_repo.DELETE("", perm.MustAdmin(), repo.DeleteRepo)
_repo.PATCH("/repair", perm.MustAdmin(), repo.RepairRepo)
_repo.PATCH("/chown", perm.MustAdmin(), repo.ChownRepo)
_repo.GET("/install/info", perm.MustRead(), api.GetInstallInfo)

// Build endpoints
// * Service endpoints
Expand Down
3 changes: 0 additions & 3 deletions router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ func Load(options ...gin.HandlerFunc) *gin.Engine {
authenticate.POST("/token", auth.PostAuthToken)
}

// Repo installation endpoint (GitHub App)
r.GET("/install", api.Install)

// API endpoints
baseAPI := r.Group(base, claims.Establish(), user.Establish())
{
Expand Down
8 changes: 0 additions & 8 deletions scm/github/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ func (c *client) Config(ctx context.Context, u *api.User, r *api.Repo, ref strin

// Disable deactivates a repo by deleting the webhook.
func (c *client) Disable(ctx context.Context, u *api.User, org, name string) error {
// todo: remove repo from github app installation

// todo: if there are no other repos in the org github app installation, should we uninstall it from the org?
return c.DestroyWebhook(ctx, u, org, name)
}

Expand Down Expand Up @@ -160,11 +157,6 @@ func (c *client) DestroyWebhook(ctx context.Context, u *api.User, org, name stri

// Enable activates a repo by creating the webhook.
func (c *client) Enable(ctx context.Context, u *api.User, r *api.Repo, h *api.Hook) (*api.Hook, string, error) {
// todo: check for org installation
// todo: if org installation does not exist, we need to redirec the user
// todo: use cli vs web redirect logic
// todo: ensure repo is visible/enabled in org installation

return c.CreateWebhook(ctx, u, r, h)
}

Expand Down

0 comments on commit 8b022a3

Please sign in to comment.