diff --git a/.github/workflows/next_deploy.yml b/.github/workflows/next_deploy.yml index d23c37d2e..d8ede1b9d 100644 --- a/.github/workflows/next_deploy.yml +++ b/.github/workflows/next_deploy.yml @@ -3,7 +3,7 @@ on: push: branches: - develop # change to main if needed - - feat/add-failure-reason-when-run-fails + - feat/fix-bug-for-trigger-applies jobs: deploy: name: Deploy app diff --git a/next/controllers/drift.go b/next/controllers/drift.go index 9b9bb67b2..833bd412b 100644 --- a/next/controllers/drift.go +++ b/next/controllers/drift.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "fmt" + "github.com/diggerhq/digger/libs/scheduler" "github.com/diggerhq/digger/next/ci_backends" "github.com/diggerhq/digger/next/dbmodels" "github.com/diggerhq/digger/next/services" @@ -70,7 +71,7 @@ func (d DiggerController) TriggerDriftDetectionForProject(c *gin.Context) { } - batchId, _, err := services.CreateJobAndBatchForProjectFromBranch(d.GithubClientProvider, projectId, "digger plan") + batchId, _, err := services.CreateJobAndBatchForProjectFromBranch(d.GithubClientProvider, projectId, "digger plan", dbmodels.DiggerBatchDriftEvent, scheduler.DiggerCommandPlan) ciBackend, err := d.CiBackendProvider.GetCiBackend( ci_backends.CiBackendOptions{ diff --git a/next/controllers/runs.go b/next/controllers/runs.go index f7e90032f..e931e9d32 100644 --- a/next/controllers/runs.go +++ b/next/controllers/runs.go @@ -2,6 +2,7 @@ package controllers import ( "fmt" + "github.com/diggerhq/digger/libs/scheduler" "github.com/diggerhq/digger/next/dbmodels" "github.com/diggerhq/digger/next/model" "github.com/diggerhq/digger/next/services" @@ -109,14 +110,14 @@ func (d DiggerController) TriggerRunForProjectAssumingUser(c *gin.Context) { } installationId := appInstallation.GithubInstallationID - planBatchId, commitSha, err := services.CreateJobAndBatchForProjectFromBranch(d.GithubClientProvider, projectId, "digger plan") + planBatchId, commitSha, err := services.CreateJobAndBatchForProjectFromBranch(d.GithubClientProvider, projectId, "digger plan", dbmodels.DiggerBatchManualTriggerEvent, scheduler.DiggerCommandPlan) if err != nil { log.Printf("Error creating plan batch: %v", err) c.JSON(http.StatusBadRequest, gin.H{"error": "error creating plan batch jobs"}) return } - applyBatchId, _, err := services.CreateJobAndBatchForProjectFromBranch(d.GithubClientProvider, projectId, "digger apply") + applyBatchId, _, err := services.CreateJobAndBatchForProjectFromBranch(d.GithubClientProvider, projectId, "digger apply", dbmodels.DiggerBatchManualTriggerEvent, scheduler.DiggerCommandApply) if err != nil { log.Printf("Error creating apply batch: %v", err) c.JSON(http.StatusBadRequest, gin.H{"error": "error creating apply batch jobs"}) diff --git a/next/dbmodels/scheduler.go b/next/dbmodels/scheduler.go index 71b9087de..0668388a9 100644 --- a/next/dbmodels/scheduler.go +++ b/next/dbmodels/scheduler.go @@ -20,6 +20,7 @@ type BatchEventType string const DiggerBatchMergeEvent = "merge_event" const DiggerBatchPullRequestEvent = "pull_request_event" const DiggerBatchDriftEvent = "drift_event" +const DiggerBatchManualTriggerEvent = "manual_trigger" const ( DiggerJobLinkCreated DiggerJobLinkStatus = 1 diff --git a/next/services/scheduler.go b/next/services/scheduler.go index c67a03309..8d39d50ca 100644 --- a/next/services/scheduler.go +++ b/next/services/scheduler.go @@ -113,7 +113,7 @@ func TriggerJob(gh utils.GithubClientProvider, ciBackend ci_backends.CiBackend, return nil } -func CreateJobAndBatchForProjectFromBranch(gh utils.GithubClientProvider, projectId string, command string) (*string, *string, error) { +func CreateJobAndBatchForProjectFromBranch(gh utils.GithubClientProvider, projectId string, command string, event dbmodels.BatchEventType, batchType orchestrator_scheduler.DiggerCommand) (*string, *string, error) { p := dbmodels.DB.Query.Project project, err := dbmodels.DB.Query.Project.Where(p.ID.Eq(projectId)).First() if err != nil { @@ -163,7 +163,7 @@ func CreateJobAndBatchForProjectFromBranch(gh utils.GithubClientProvider, projec Plan: nil, Apply: nil, Configuration: &dg_configuration.WorkflowConfiguration{ - OnPullRequestPushed: []string{"digger plan"}, + OnPullRequestPushed: []string{command}, OnPullRequestClosed: []string{}, OnPullRequestConvertedToDraft: []string{}, OnCommitToDefault: []string{}, @@ -176,7 +176,7 @@ func CreateJobAndBatchForProjectFromBranch(gh utils.GithubClientProvider, projec issueNumber := 0 - jobs, err := generic.CreateJobsForProjects(dgprojects, "digger plan", "drift-detection", repoFullName, "digger", config.Workflows, &issueNumber, nil, branch, branch) + jobs, err := generic.CreateJobsForProjects(dgprojects, command, string(event), repoFullName, "digger", config.Workflows, &issueNumber, nil, branch, branch) if err != nil { log.Printf("Error creating jobs: %v", err) return nil, nil, fmt.Errorf("error creating jobs: %v", err) @@ -200,7 +200,7 @@ func CreateJobAndBatchForProjectFromBranch(gh utils.GithubClientProvider, projec commitSha, _, err := ghService.GetHeadCommitFromBranch(branch) - batchId, _, err := ConvertJobsToDiggerJobs(orchestrator_scheduler.DiggerCommandPlan, dbmodels.DiggerVCSGithub, orgId, impactedJobsMap, impactedProjectsMap, projectsGraph, installationId, project.Branch, 0, repoOwner, repoName, repoFullName, commitSha, 0, "", 0, dbmodels.DiggerBatchDriftEvent) + batchId, _, err := ConvertJobsToDiggerJobs(batchType, dbmodels.DiggerVCSGithub, orgId, impactedJobsMap, impactedProjectsMap, projectsGraph, installationId, project.Branch, 0, repoOwner, repoName, repoFullName, commitSha, 0, "", 0, event) if err != nil { log.Printf("ConvertJobsToDiggerJobs error: %v", err) return nil, nil, fmt.Errorf("ConvertJobsToDiggerJobs error: %v", err) diff --git a/next/services/spec.go b/next/services/spec.go index e2aa2c20d..2eea71b57 100644 --- a/next/services/spec.go +++ b/next/services/spec.go @@ -154,6 +154,8 @@ func GetRunNameFromJob(job model.DiggerJob) (*string, error) { runName += fmt.Sprintf(" (merge)") case dbmodels.DiggerBatchDriftEvent: runName += fmt.Sprintf(" (drift)") + case dbmodels.DiggerBatchManualTriggerEvent: + runName += fmt.Sprintf(" (user)") case dbmodels.DiggerBatchPullRequestEvent: runName += fmt.Sprintf(" PR: %v", prNumber) } @@ -227,6 +229,10 @@ func GetSpecFromJob(job model.DiggerJob) (*spec.Spec, error) { spec.Reporter.ReporterType = "noop" spec.CommentUpdater.CommentUpdaterType = "noop" spec.VCS.VcsType = "noop" + case dbmodels.DiggerBatchManualTriggerEvent: + spec.Reporter.ReporterType = "noop" + spec.CommentUpdater.CommentUpdaterType = "noop" + spec.VCS.VcsType = "noop" case dbmodels.DiggerBatchPullRequestEvent: }