Skip to content

Commit 4d71d2b

Browse files
authored
feat/disable apply comment (#2123)
* allow user to create slack connect channel * support disabling of digger apply comment
1 parent 7ad2e77 commit 4d71d2b

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

backend/controllers/github.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,8 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
13581358
return nil
13591359
}
13601360

1361-
if !strings.HasPrefix(commentBody, "digger") {
1361+
cleanedComment := strings.TrimSpace(strings.ToLower(commentBody))
1362+
if !strings.HasPrefix(cleanedComment, "digger") {
13621363
slog.Info("Comment is not a Digger command, ignoring",
13631364
"issueNumber", issueNumber,
13641365
"commentBody", commentBody,
@@ -1405,6 +1406,14 @@ func handleIssueCommentEvent(gh utils.GithubClientProvider, payload *github.Issu
14051406
return fmt.Errorf("error getting digger config")
14061407
}
14071408

1409+
if config.DisableDiggerApplyComment && strings.HasPrefix(cleanedComment, "digger apply") {
1410+
slog.Info("Digger configured to disable apply comment in PRs, ignoring comment", "DisableDiggerApplyComment", config.DisableDiggerApplyComment)
1411+
if os.Getenv("DIGGER_REPORT_BEFORE_LOADING_CONFIG") == "1" {
1412+
commentReporterManager.UpdateComment("Digger configured to disable apply comment in PRs, ignoring comment")
1413+
}
1414+
return nil
1415+
}
1416+
14081417
// terraform code generator
14091418
if os.Getenv("DIGGER_GENERATION_ENABLED") == "1" {
14101419
slog.Info("Terraform code generation is enabled",

docs/ce/howto/apply-on-merge.mdx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ By default, Digger does not run apply on merge. This is a safer way to resolve t
77
You can configure Digger to run apply on merge with the following entries in `digger.yml`
88

99
```
10+
disable_digger_apply_comment: true
11+
1012
projects:
1113
...
1214
workflows:
@@ -17,9 +19,5 @@ workflows:
1719
on_commit_to_default: [digger apply]
1820
```
1921

20-
<Note>
21-
**Limitation**
2222

23-
right now there is no way to prevent running `apply` via comment, even if apply on merge is configured. Tracked in [#272](https://github.com/diggerhq/digger/issues/272)
24-
</Note>
2523
The tradeoff then of course shifts to handling flaky applies. You'll need to raise a new PR for every change. But that might be preferable in some cases, for example for highly sensitive parts of production environments that are rarely changed. (eg the "foundation infra" layer with VPC definitions etc).

libs/digger_config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type DiggerConfig struct {
1515
CommentRenderMode string
1616
DependencyConfiguration DependencyConfiguration
1717
DeletePriorComments bool
18+
DisableDiggerApplyComment bool
1819
RespectLayers bool
1920
PrLocks bool
2021
Projects []Project

libs/digger_config/converters.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ func ConvertDiggerYamlToConfig(diggerYaml *DiggerConfigYaml) (*DiggerConfig, gra
205205
}
206206
}
207207

208+
if diggerYaml.DisableDiggerApplyComment != nil {
209+
diggerConfig.DisableDiggerApplyComment = *diggerYaml.DisableDiggerApplyComment
210+
} else {
211+
diggerConfig.DisableDiggerApplyComment = false
212+
}
213+
208214
if diggerYaml.ReportTerraformOutputs != nil {
209215
diggerConfig.ReportTerraformOutputs = *diggerYaml.ReportTerraformOutputs
210216
} else {

libs/digger_config/yaml.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type DiggerConfigYaml struct {
1313
AllowDraftPRs *bool `yaml:"allow_draft_prs"`
1414
DependencyConfiguration *DependencyConfigurationYaml `yaml:"dependency_configuration"`
1515
DeletePriorComments *bool `yaml:"delete_prior_comments"`
16+
DisableDiggerApplyComment *bool `yaml:"disable_digger_apply_comment"`
1617
PrLocks *bool `yaml:"pr_locks"`
1718
Projects []*ProjectYaml `yaml:"projects"`
1819
AutoMerge *bool `yaml:"auto_merge"`

0 commit comments

Comments
 (0)