Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix job title for trigger apply, and also fix the command passed #1712

Merged
merged 4 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/next_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion next/controllers/drift.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand Down
5 changes: 3 additions & 2 deletions next/controllers/runs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"})
Expand Down
1 change: 1 addition & 0 deletions next/dbmodels/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions next/services/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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{},
Expand All @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions next/services/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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:
}

Expand Down
Loading