Skip to content

Add AllowDraftPRs flag, disabled by default #1329

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

Merged
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
13 changes: 13 additions & 0 deletions backend/controllers/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
repoFullName := *payload.Repo.FullName
cloneURL := *payload.Repo.CloneURL
prNumber := *payload.PullRequest.Number
isDraft := payload.PullRequest.GetDraft()

link, err := models.DB.GetGithubAppInstallationLink(installationId)
if err != nil {
log.Printf("Error getting GetGithubAppInstallationLink: %v", err)
Expand All @@ -437,6 +439,11 @@ func handlePullRequestEvent(gh utils.GithubClientProvider, payload *github.PullR
return fmt.Errorf("error getting digger config")
}

if !config.AllowDraftPRs && isDraft {
log.Printf("Draft PRs are disabled, skipping PR: %v", prNumber)
return nil
}

impactedProjects, _, err := dg_github.ProcessGitHubPullRequestEvent(payload, config, projectsGraph, ghService)
if err != nil {
log.Printf("Error processing event: %v", err)
Expand Down Expand Up @@ -596,6 +603,7 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
repoFullName := *payload.Repo.FullName
cloneURL := *payload.Repo.CloneURL
issueNumber := *payload.Issue.Number
isDraft := payload.Issue.GetDraft()

link, err := models.DB.GetGithubAppInstallationLink(installationId)
if err != nil {
Expand All @@ -620,6 +628,11 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
return fmt.Errorf("error getting digger config")
}

if !config.AllowDraftPRs && isDraft {
log.Printf("AllowDraftPRs is enabled, skipping PR: %v", issueNumber)
return nil
}

commentReporter, err := utils.InitCommentReporter(ghService, issueNumber, ":construction_worker: Digger starting....")
if err != nil {
log.Printf("Error initializing comment reporter: %v", err)
Expand Down
3 changes: 2 additions & 1 deletion backend/controllers/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package controllers

import (
"encoding/json"
orchestrator_scheduler "github.com/diggerhq/digger/libs/orchestrator/scheduler"
"log"
"os"
"strings"
"testing"

orchestrator_scheduler "github.com/diggerhq/digger/libs/orchestrator/scheduler"

"github.com/diggerhq/digger/backend/models"
"github.com/diggerhq/digger/backend/utils"
configuration "github.com/diggerhq/digger/libs/digger_config"
Expand Down
3 changes: 2 additions & 1 deletion cli/pkg/digger/digger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package digger
import (
"errors"
"fmt"
"github.com/diggerhq/digger/cli/pkg/comment_updater"
"log"
"os"
"path"
"strings"
"time"

"github.com/diggerhq/digger/cli/pkg/comment_updater"

"github.com/diggerhq/digger/cli/pkg/core/backend"
core_drift "github.com/diggerhq/digger/cli/pkg/core/drift"
"github.com/diggerhq/digger/cli/pkg/core/execution"
Expand Down
1 change: 1 addition & 0 deletions libs/digger_config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package digger_config

type DiggerConfig struct {
ApplyAfterMerge bool
AllowDraftPRs bool
DependencyConfiguration DependencyConfiguration
Projects []Project
AutoMerge bool
Expand Down
6 changes: 6 additions & 0 deletions libs/digger_config/converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ func ConvertDiggerYamlToConfig(diggerYaml *DiggerConfigYaml) (*DiggerConfig, gra
diggerConfig.TraverseToNestedProjects = false
}

if diggerYaml.AllowDraftPRs != nil {
diggerConfig.AllowDraftPRs = *diggerYaml.AllowDraftPRs
} else {
diggerConfig.AllowDraftPRs = false
}

// if workflow block is not specified in yaml we create a default one, and add it to every project
if diggerYaml.Workflows != nil {
workflows := copyWorkflows(diggerYaml.Workflows)
Expand Down
3 changes: 3 additions & 0 deletions libs/digger_config/digger_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,9 @@ func AutoDetectDiggerConfig(workingDir string) (*DiggerConfigYaml, error) {
TraverseToNestedProjects := false
configYaml.TraverseToNestedProjects = &TraverseToNestedProjects

AllowDraftPRs := false
configYaml.AllowDraftPRs = &AllowDraftPRs

terragruntDirWalker := &FileSystemTerragruntDirWalker{}
terraformDirWalker := &FileSystemTopLevelTerraformDirWalker{}
moduleDirWalker := &FileSystemModuleDirWalker{}
Expand Down
20 changes: 20 additions & 0 deletions libs/digger_config/digger_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,7 @@ func TestDiggerTraverseToNestedProjects(t *testing.T) {
defer teardown()

diggerCfg := `
allow_draft_prs: true
traverse_to_nested_projects: true
generate_projects:
blocks:
Expand Down Expand Up @@ -1178,4 +1179,23 @@ generate_projects:
assert.Equal(t, "dev/test1", dg.Projects[2].Dir)
assert.Equal(t, "dev_test2", dg.Projects[3].Name)
assert.Equal(t, "dev/test2", dg.Projects[3].Dir)
assert.Equal(t, true, dg.AllowDraftPRs)
}

// TestDiggerAllowDraftPRs tests if allow_draft_prs is set to true, digger will allow draft PRs. Defaults to false
func TestDiggerAllowDraftPRs(t *testing.T) {
tempDir, teardown := setUp()
defer teardown()

diggerCfg := `
projects:
- name: dev
dir: .
`
defer createFile(path.Join(tempDir, "digger.yml"), diggerCfg)()
defer createFile(path.Join(tempDir, "main.tf"), "resource \"null_resource\" \"test4\" {}")()

dg, _, _, err := LoadDiggerConfig(tempDir)
assert.NoError(t, err)
assert.Equal(t, false, dg.AllowDraftPRs)
}
1 change: 1 addition & 0 deletions libs/digger_config/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

type DiggerConfigYaml struct {
ApplyAfterMerge *bool `yaml:"apply_after_merge"`
AllowDraftPRs *bool `yaml:"allow_draft_prs"`
DependencyConfiguration *DependencyConfigurationYaml `yaml:"dependency_configuration"`
Projects []*ProjectYaml `yaml:"projects"`
AutoMerge *bool `yaml:"auto_merge"`
Expand Down
Loading