From 4ec3e871b5b6ccf1400d799cbdd10c6cd37cd36b Mon Sep 17 00:00:00 2001 From: golemiso <3282656+golemiso@users.noreply.github.com> Date: Tue, 26 Dec 2023 15:55:12 +0900 Subject: [PATCH 1/2] Use repository settings from piped config Signed-off-by: golemiso <3282656+golemiso@users.noreply.github.com> --- pkg/app/piped/controller/planner.go | 10 ++++++---- pkg/app/piped/controller/scheduler.go | 10 ++++++---- pkg/app/piped/planpreview/builder.go | 6 ------ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/pkg/app/piped/controller/planner.go b/pkg/app/piped/controller/planner.go index 0beef633c2..6bd5f269c1 100644 --- a/pkg/app/piped/controller/planner.go +++ b/pkg/app/piped/controller/planner.go @@ -150,10 +150,12 @@ func (p *planner) Run(ctx context.Context) error { p.done.Store(true) }() - repoCfg := config.PipedRepository{ - RepoID: p.deployment.GitPath.Repo.Id, - Remote: p.deployment.GitPath.Repo.Remote, - Branch: p.deployment.GitPath.Repo.Branch, + repoID := p.deployment.GitPath.Repo.Id + repoCfg, ok := p.pipedConfig.GetRepository(repoID) + if !ok { + p.doneDeploymentStatus = model.DeploymentStatus_DEPLOYMENT_FAILURE + reason := fmt.Sprintf("Repository %s was not found in piped configuration", repoID) + return p.reportDeploymentFailed(ctx, reason) } in := pln.Input{ diff --git a/pkg/app/piped/controller/scheduler.go b/pkg/app/piped/controller/scheduler.go index 91e0bf63a2..42a3589f52 100644 --- a/pkg/app/piped/controller/scheduler.go +++ b/pkg/app/piped/controller/scheduler.go @@ -220,10 +220,12 @@ func (s *scheduler) Run(ctx context.Context) error { ) deploymentStatus = model.DeploymentStatus_DEPLOYMENT_SUCCESS - repoCfg := config.PipedRepository{ - RepoID: s.deployment.GitPath.Repo.Id, - Remote: s.deployment.GitPath.Repo.Remote, - Branch: s.deployment.GitPath.Repo.Branch, + repoID := s.deployment.GitPath.Repo.Id + repoCfg, ok := s.pipedConfig.GetRepository(repoID) + if !ok { + deploymentStatus := model.DeploymentStatus_DEPLOYMENT_FAILURE + statusReason := fmt.Sprintf("Repository %s was not found in piped configuration", repoID) + return s.reportDeploymentCompleted(ctx, deploymentStatus, statusReason, "") } s.targetDSP = deploysource.NewProvider( diff --git a/pkg/app/piped/planpreview/builder.go b/pkg/app/piped/planpreview/builder.go index 1a307ea259..fe827e9161 100644 --- a/pkg/app/piped/planpreview/builder.go +++ b/pkg/app/piped/planpreview/builder.go @@ -377,12 +377,6 @@ func (b *builder) listApplications(repo config.PipedRepository) []*model.Applica if app.GitPath.Repo.Id != repo.RepoID { continue } - if app.GitPath.Repo.Remote != repo.Remote { - continue - } - if app.GitPath.Repo.Branch != repo.Branch { - continue - } out = append(out, app) } From dab442a035e4ec18041960c890cd6d65e604bf84 Mon Sep 17 00:00:00 2001 From: golemiso <3282656+golemiso@users.noreply.github.com> Date: Thu, 7 Mar 2024 13:19:51 +0900 Subject: [PATCH 2/2] override repository when creating deployment Signed-off-by: golemiso <3282656+golemiso@users.noreply.github.com> --- pkg/app/piped/controller/planner.go | 10 ++++------ pkg/app/piped/controller/scheduler.go | 10 ++++------ pkg/app/piped/trigger/deployment.go | 6 +++++- pkg/app/piped/trigger/trigger.go | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pkg/app/piped/controller/planner.go b/pkg/app/piped/controller/planner.go index 6bd5f269c1..0beef633c2 100644 --- a/pkg/app/piped/controller/planner.go +++ b/pkg/app/piped/controller/planner.go @@ -150,12 +150,10 @@ func (p *planner) Run(ctx context.Context) error { p.done.Store(true) }() - repoID := p.deployment.GitPath.Repo.Id - repoCfg, ok := p.pipedConfig.GetRepository(repoID) - if !ok { - p.doneDeploymentStatus = model.DeploymentStatus_DEPLOYMENT_FAILURE - reason := fmt.Sprintf("Repository %s was not found in piped configuration", repoID) - return p.reportDeploymentFailed(ctx, reason) + repoCfg := config.PipedRepository{ + RepoID: p.deployment.GitPath.Repo.Id, + Remote: p.deployment.GitPath.Repo.Remote, + Branch: p.deployment.GitPath.Repo.Branch, } in := pln.Input{ diff --git a/pkg/app/piped/controller/scheduler.go b/pkg/app/piped/controller/scheduler.go index 42a3589f52..91e0bf63a2 100644 --- a/pkg/app/piped/controller/scheduler.go +++ b/pkg/app/piped/controller/scheduler.go @@ -220,12 +220,10 @@ func (s *scheduler) Run(ctx context.Context) error { ) deploymentStatus = model.DeploymentStatus_DEPLOYMENT_SUCCESS - repoID := s.deployment.GitPath.Repo.Id - repoCfg, ok := s.pipedConfig.GetRepository(repoID) - if !ok { - deploymentStatus := model.DeploymentStatus_DEPLOYMENT_FAILURE - statusReason := fmt.Sprintf("Repository %s was not found in piped configuration", repoID) - return s.reportDeploymentCompleted(ctx, deploymentStatus, statusReason, "") + repoCfg := config.PipedRepository{ + RepoID: s.deployment.GitPath.Repo.Id, + Remote: s.deployment.GitPath.Repo.Remote, + Branch: s.deployment.GitPath.Repo.Branch, } s.targetDSP = deploysource.NewProvider( diff --git a/pkg/app/piped/trigger/deployment.go b/pkg/app/piped/trigger/deployment.go index c3576b92aa..93ff8d3dd0 100644 --- a/pkg/app/piped/trigger/deployment.go +++ b/pkg/app/piped/trigger/deployment.go @@ -40,7 +40,7 @@ func (t *Trigger) triggerDeployment( return nil } -func buildDeployment( +func (t *Trigger) buildDeployment( app *model.Application, branch string, commit git.Commit, @@ -55,6 +55,10 @@ func buildDeployment( var commitURL string if r := app.GitPath.Repo; r != nil { + if repo, ok := t.config.GetRepository(r.Id); ok { + r.Branch = repo.Branch + r.Remote = repo.Remote + } url, err := git.MakeCommitURL(r.Remote, commit.Hash) if err != nil { return nil, err diff --git a/pkg/app/piped/trigger/trigger.go b/pkg/app/piped/trigger/trigger.go index e73b1f15bb..4d20ea2751 100644 --- a/pkg/app/piped/trigger/trigger.go +++ b/pkg/app/piped/trigger/trigger.go @@ -296,7 +296,7 @@ func (t *Trigger) checkRepoCandidates(ctx context.Context, repoID string, cs []c } // Build the deployment to trigger. - deployment, err := buildDeployment( + deployment, err := t.buildDeployment( app, branch, headCommit,