Skip to content

Commit

Permalink
Merge pull request #995 from mumoshu/model-gitops-src
Browse files Browse the repository at this point in the history
Move ModelGitOps code into its own model_gitops.go
  • Loading branch information
pirlodog1125 authored Dec 4, 2023
2 parents 4735e16 + 299ba11 commit a504be2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 40 deletions.
41 changes: 41 additions & 0 deletions model_gitops.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

type ModelGitOps struct {
github *GitHub
git *GitOperator
plugin GitOpsPlugin
}

type GitOpsPrepareOutput struct {
PullRequestID string
PullRequestNumber int
Branch string
status DeployStatus
}

func (self GitOpsPrepareOutput) Status() DeployStatus {
return self.status
}

func (self GitOpsPrepareOutput) Message() string {
return "Success to deploy"
}

func (self ModelGitOps) Commit(pullRequestID string) error {
return self.github.MergePullRequest(pullRequestID)

}

func (self ModelGitOps) Deploy(pj DeployProject, phase string, option DeployOption) (do DeployOutput, err error) {
o, err := self.plugin.Prepare(pj, phase, option.Branch, option.Assigner, option.Tag)
if err != nil {
return
}
if o.Status() == DeployStatusSuccess {
err = self.Commit(o.PullRequestID)
if err != nil {
return
}
}
return o, nil
}
40 changes: 0 additions & 40 deletions model_kustomize.go
Original file line number Diff line number Diff line change
@@ -1,49 +1,9 @@
package main

type ModelGitOps struct {
github *GitHub
git *GitOperator
plugin GitOpsPlugin
}

func NewModelKustomize(github *GitHub, git *GitOperator) ModelGitOps {
return ModelGitOps{
github: github,
git: git,
plugin: NewGitOpsPluginKustomize(github, git),
}
}

type GitOpsPrepareOutput struct {
PullRequestID string
PullRequestNumber int
Branch string
status DeployStatus
}

func (self GitOpsPrepareOutput) Status() DeployStatus {
return self.status
}

func (self GitOpsPrepareOutput) Message() string {
return "Success to deploy"
}

func (self ModelGitOps) Commit(pullRequestID string) error {
return self.github.MergePullRequest(pullRequestID)

}

func (self ModelGitOps) Deploy(pj DeployProject, phase string, option DeployOption) (do DeployOutput, err error) {
o, err := self.plugin.Prepare(pj, phase, option.Branch, option.Assigner, option.Tag)
if err != nil {
return
}
if o.Status() == DeployStatusSuccess {
err = self.Commit(o.PullRequestID)
if err != nil {
return
}
}
return o, nil
}

0 comments on commit a504be2

Please sign in to comment.