Преглед изворни кода

refactor name and delete unused endpoint

Ivan Galakhov пре 4 година
родитељ
комит
5df82604f2

+ 8 - 8
internal/integrations/ci/actions/actions.go

@@ -20,10 +20,10 @@ import (
 type GithubActions struct {
 	ServerURL string
 
-	GitIntegration *models.GitRepo
-	GitRepoName    string
-	GitRepoOwner   string
-	Repo           repository.Repository
+	GithubOAuthIntegration *models.GitRepo
+	GitRepoName            string
+	GitRepoOwner           string
+	Repo                   repository.Repository
 
 	GithubConf           *oauth2.Config // one of these will let us authenticate
 	GithubAppID          int64
@@ -202,10 +202,10 @@ func (g *GithubActions) GetGithubActionYAML() ([]byte, error) {
 func (g *GithubActions) getClient() (*github.Client, error) {
 
 	// in the case that this still uses the oauth integration
-	if g.GitIntegration != nil {
+	if g.GithubOAuthIntegration != nil {
 
 		// get the oauth integration
-		oauthInt, err := g.Repo.OAuthIntegration.ReadOAuthIntegration(g.GitIntegration.OAuthIntegrationID)
+		oauthInt, err := g.Repo.OAuthIntegration.ReadOAuthIntegration(g.GithubOAuthIntegration.OAuthIntegrationID)
 
 		if err != nil {
 			return nil, err
@@ -375,7 +375,7 @@ func (g *GithubActions) commitGithubFile(
 		SHA:     &sha,
 	}
 
-	if g.GitIntegration != nil {
+	if g.GithubOAuthIntegration != nil {
 		opts.Committer = &github.CommitAuthor{
 			Name:  github.String("Porter Bot"),
 			Email: github.String("contact@getporter.dev"),
@@ -423,7 +423,7 @@ func (g *GithubActions) deleteGithubFile(
 		SHA:     &sha,
 	}
 
-	if g.GitIntegration != nil {
+	if g.GithubOAuthIntegration != nil {
 		opts.Committer = &github.CommitAuthor{
 			Name:  github.String("Porter Bot"),
 			Email: github.String("contact@getporter.dev"),

+ 16 - 16
server/api/deploy_handler.go

@@ -372,22 +372,22 @@ func (app *App) HandleUninstallTemplate(w http.ResponseWriter, r *http.Request)
 				}
 
 				gaRunner := &actions.GithubActions{
-					ServerURL:            app.ServerConf.ServerURL,
-					GitIntegration:       gr,
-					GithubAppID:          app.GithubAppConf.AppID,
-					GithubInstallationID: gitAction.GitRepoID,
-					GitRepoName:          repoSplit[1],
-					GitRepoOwner:         repoSplit[0],
-					Repo:                 *app.Repo,
-					GithubConf:           app.GithubProjectConf,
-					WebhookToken:         release.WebhookToken,
-					ProjectID:            uint(projID),
-					ReleaseName:          name,
-					GitBranch:            gitAction.GitBranch,
-					DockerFilePath:       gitAction.DockerfilePath,
-					FolderPath:           gitAction.FolderPath,
-					ImageRepoURL:         gitAction.ImageRepoURI,
-					BuildEnv:             cEnv.Container.Env.Normal,
+					ServerURL:              app.ServerConf.ServerURL,
+					GithubOAuthIntegration: gr,
+					GithubAppID:            app.GithubAppConf.AppID,
+					GithubInstallationID:   gitAction.GitRepoID,
+					GitRepoName:            repoSplit[1],
+					GitRepoOwner:           repoSplit[0],
+					Repo:                   *app.Repo,
+					GithubConf:             app.GithubProjectConf,
+					WebhookToken:           release.WebhookToken,
+					ProjectID:              uint(projID),
+					ReleaseName:            name,
+					GitBranch:              gitAction.GitBranch,
+					DockerFilePath:         gitAction.DockerfilePath,
+					FolderPath:             gitAction.FolderPath,
+					ImageRepoURL:           gitAction.ImageRepoURI,
+					BuildEnv:               cEnv.Container.Env.Normal,
 				}
 
 				err = gaRunner.Cleanup()

+ 17 - 17
server/api/git_action_handler.go

@@ -156,23 +156,23 @@ func (app *App) createGitActionFromForm(
 
 	// create the commit in the git repo
 	gaRunner := &actions.GithubActions{
-		ServerURL:            app.ServerConf.ServerURL,
-		GitIntegration:       nil,
-		GithubAppID:          app.GithubAppConf.AppID,
-		GithubInstallationID: form.GitRepoID,
-		GitRepoName:          repoSplit[1],
-		GitRepoOwner:         repoSplit[0],
-		Repo:                 *app.Repo,
-		GithubConf:           app.GithubProjectConf,
-		WebhookToken:         release.WebhookToken,
-		ProjectID:            uint(projID),
-		ReleaseName:          name,
-		GitBranch:            gitAction.GitBranch,
-		DockerFilePath:       gitAction.DockerfilePath,
-		FolderPath:           gitAction.FolderPath,
-		ImageRepoURL:         gitAction.ImageRepoURI,
-		PorterToken:          encoded,
-		BuildEnv:             form.BuildEnv,
+		ServerURL:              app.ServerConf.ServerURL,
+		GithubOAuthIntegration: nil,
+		GithubAppID:            app.GithubAppConf.AppID,
+		GithubInstallationID:   form.GitRepoID,
+		GitRepoName:            repoSplit[1],
+		GitRepoOwner:           repoSplit[0],
+		Repo:                   *app.Repo,
+		GithubConf:             app.GithubProjectConf,
+		WebhookToken:           release.WebhookToken,
+		ProjectID:              uint(projID),
+		ReleaseName:            name,
+		GitBranch:              gitAction.GitBranch,
+		DockerFilePath:         gitAction.DockerfilePath,
+		FolderPath:             gitAction.FolderPath,
+		ImageRepoURL:           gitAction.ImageRepoURI,
+		PorterToken:            encoded,
+		BuildEnv:               form.BuildEnv,
 	}
 
 	_, err = gaRunner.Setup()

+ 0 - 26
server/api/git_repo_handler.go

@@ -188,32 +188,6 @@ func (app *App) HandleListRepos(w http.ResponseWriter, r *http.Request) {
 	json.NewEncoder(w).Encode(res)
 }
 
-// HandleDeleteProjectGitRepo handles the deletion of a Github Repo via the git repo ID
-func (app *App) HandleDeleteProjectGitRepo(w http.ResponseWriter, r *http.Request) {
-	id, err := strconv.ParseUint(chi.URLParam(r, "git_repo_id"), 0, 64)
-
-	if err != nil || id == 0 {
-		app.handleErrorFormDecoding(err, ErrProjectDecode, w)
-		return
-	}
-
-	repo, err := app.Repo.GitRepo.ReadGitRepo(uint(id))
-
-	if err != nil {
-		app.handleErrorRead(err, ErrProjectDataRead, w)
-		return
-	}
-
-	err = app.Repo.GitRepo.DeleteGitRepo(repo)
-
-	if err != nil {
-		app.handleErrorRead(err, ErrProjectDataRead, w)
-		return
-	}
-
-	w.WriteHeader(http.StatusOK)
-}
-
 // HandleGetBranches retrieves a list of branch names for a specified repo
 func (app *App) HandleGetBranches(w http.ResponseWriter, r *http.Request) {
 

+ 32 - 32
server/api/release_handler.go

@@ -950,22 +950,22 @@ func (app *App) HandleUpgradeRelease(w http.ResponseWriter, r *http.Request) {
 				repoSplit := strings.Split(gitAction.GitRepo, "/")
 
 				gaRunner := &actions.GithubActions{
-					ServerURL:            app.ServerConf.ServerURL,
-					GitIntegration:       gr,
-					GithubInstallationID: gitAction.GitRepoID,
-					GithubAppID:          app.GithubAppConf.AppID,
-					GitRepoName:          repoSplit[1],
-					GitRepoOwner:         repoSplit[0],
-					Repo:                 *app.Repo,
-					GithubConf:           app.GithubProjectConf,
-					WebhookToken:         release.WebhookToken,
-					ProjectID:            uint(projID),
-					ReleaseName:          name,
-					GitBranch:            gitAction.GitBranch,
-					DockerFilePath:       gitAction.DockerfilePath,
-					FolderPath:           gitAction.FolderPath,
-					ImageRepoURL:         gitAction.ImageRepoURI,
-					BuildEnv:             cEnv.Container.Env.Normal,
+					ServerURL:              app.ServerConf.ServerURL,
+					GithubOAuthIntegration: gr,
+					GithubInstallationID:   gitAction.GitRepoID,
+					GithubAppID:            app.GithubAppConf.AppID,
+					GitRepoName:            repoSplit[1],
+					GitRepoOwner:           repoSplit[0],
+					Repo:                   *app.Repo,
+					GithubConf:             app.GithubProjectConf,
+					WebhookToken:           release.WebhookToken,
+					ProjectID:              uint(projID),
+					ReleaseName:            name,
+					GitBranch:              gitAction.GitBranch,
+					DockerFilePath:         gitAction.DockerfilePath,
+					FolderPath:             gitAction.FolderPath,
+					ImageRepoURL:           gitAction.ImageRepoURI,
+					BuildEnv:               cEnv.Container.Env.Normal,
 				}
 
 				err = gaRunner.CreateEnvSecret()
@@ -1345,22 +1345,22 @@ func (app *App) HandleRollbackRelease(w http.ResponseWriter, r *http.Request) {
 				}
 
 				gaRunner := &actions.GithubActions{
-					ServerURL:            app.ServerConf.ServerURL,
-					GitIntegration:       gr,
-					GithubInstallationID: gitAction.GitRepoID,
-					GithubAppID:          app.GithubAppConf.AppID,
-					GitRepoName:          repoSplit[1],
-					GitRepoOwner:         repoSplit[0],
-					Repo:                 *app.Repo,
-					GithubConf:           app.GithubProjectConf,
-					WebhookToken:         release.WebhookToken,
-					ProjectID:            uint(projID),
-					ReleaseName:          name,
-					GitBranch:            gitAction.GitBranch,
-					DockerFilePath:       gitAction.DockerfilePath,
-					FolderPath:           gitAction.FolderPath,
-					ImageRepoURL:         gitAction.ImageRepoURI,
-					BuildEnv:             cEnv.Container.Env.Normal,
+					ServerURL:              app.ServerConf.ServerURL,
+					GithubOAuthIntegration: gr,
+					GithubInstallationID:   gitAction.GitRepoID,
+					GithubAppID:            app.GithubAppConf.AppID,
+					GitRepoName:            repoSplit[1],
+					GitRepoOwner:           repoSplit[0],
+					Repo:                   *app.Repo,
+					GithubConf:             app.GithubProjectConf,
+					WebhookToken:           release.WebhookToken,
+					ProjectID:              uint(projID),
+					ReleaseName:            name,
+					GitBranch:              gitAction.GitBranch,
+					DockerFilePath:         gitAction.DockerfilePath,
+					FolderPath:             gitAction.FolderPath,
+					ImageRepoURL:           gitAction.ImageRepoURI,
+					BuildEnv:               cEnv.Container.Env.Normal,
 				}
 
 				err = gaRunner.CreateEnvSecret()

+ 0 - 13
server/router/router.go

@@ -1129,19 +1129,6 @@ func New(a *api.App) *chi.Mux {
 				),
 			)
 
-			r.Method( // this endpoint isn't going to be used anymore, should it get deleted?
-				"DELETE",
-				"/projects/{project_id}/gitrepos/{git_repo_id}",
-				auth.DoesUserHaveProjectAccess(
-					auth.DoesUserHaveGitInstallationAccess(
-						requestlog.NewHandler(a.HandleDeleteProjectGitRepo, l),
-						mw.URLParam,
-					),
-					mw.URLParam,
-					mw.WriteAccess,
-				),
-			)
-
 			r.Method(
 				"GET",
 				"/projects/{project_id}/gitrepos/{installation_id}/repos",