Skip to content

Commit 7ddd234

Browse files
committed
Promote GitHub Issues Drift Notifier to CE
1 parent 05f4168 commit 7ddd234

File tree

7 files changed

+67
-65
lines changed

7 files changed

+67
-65
lines changed

cli/pkg/drift/Provider.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ type DriftNotificationProviderBasic struct{}
1515

1616
func (d DriftNotificationProviderBasic) Get(prService ci.PullRequestService) (core_drift.Notification, error) {
1717
slackNotificationUrl := os.Getenv("INPUT_DRIFT_DETECTION_SLACK_NOTIFICATION_URL")
18+
githubIssues := os.Getenv("INPUT_DRIFT_GITHUB_ISSUES")
1819
var notification core_drift.Notification
1920
if slackNotificationUrl != "" {
2021
notification = &SlackNotification{slackNotificationUrl}
22+
} else if githubIssues != "" {
23+
notification = &GithubIssueNotification{GithubService: &prService}
2124
} else {
22-
return nil, fmt.Errorf("could not identify drift mode, please specify slack using env variable INPUT_DRIFT_DETECTION_SLACK_NOTIFICATION_URL")
25+
return nil, fmt.Errorf("could not identify drift mode, please specify using INPUT_DRIFT_DETECTION_SLACK_NOTIFICATION_URL or INPUT_DRIFT_GITHUB_ISSUES")
2326
}
2427
return notification, nil
2528
}

cli/pkg/drift/github_issue.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package drift
2+
3+
import (
4+
"fmt"
5+
orchestrator "github.com/diggerhq/digger/libs/ci"
6+
"github.com/samber/lo"
7+
"log"
8+
)
9+
10+
type GithubIssueNotification struct {
11+
GithubService *orchestrator.PullRequestService
12+
RelatedPrNumber *int64
13+
}
14+
15+
func (ghi *GithubIssueNotification) SendNotificationForProject(projectName string, repoFullName string, plan string) error {
16+
log.Printf("Info: Sending drift notification regarding project: %v", projectName)
17+
title := fmt.Sprintf("Drift detected in project: %v", projectName)
18+
message := fmt.Sprintf(":bangbang: Drift detected in digger project %v details below: \n\n```\n%v\n```", projectName, plan)
19+
existingIssues, err := (*ghi.GithubService).ListIssues()
20+
if err != nil {
21+
log.Printf("failed to retrieve issues: %v", err)
22+
return fmt.Errorf("failed to retrieve issues: %v", err)
23+
}
24+
25+
theIssue, exists := lo.Find(existingIssues, func(item *orchestrator.Issue) bool {
26+
return item.Title == title
27+
})
28+
if exists {
29+
_, err := (*ghi.GithubService).UpdateIssue(theIssue.ID, theIssue.Title, message)
30+
if err != nil {
31+
log.Printf("error while updating issue: %v", err)
32+
}
33+
return err
34+
} else {
35+
labels := []string{"digger"}
36+
_, err := (*ghi.GithubService).PublishIssue(title, message, &labels)
37+
if err != nil {
38+
log.Printf("error while publishing issue: %v", err)
39+
}
40+
return err
41+
}
42+
}
43+
44+
func (ghi *GithubIssueNotification) SendErrorNotificationForProject(projectName string, repoFullName string, err error) error {
45+
return nil
46+
}
47+
48+
func (ghi *GithubIssueNotification) Flush() error {
49+
return nil
50+
}
51+

docs/ce/features/drift-detection.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ jobs:
7070
- name: digger drift detection
7171
uses: diggerhq/digger@vLatest
7272
with:
73-
ee: 'true'
7473
mode: drift-detection
7574
setup-aws: true
7675
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}

drift/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"os"
1111

1212
"github.com/diggerhq/digger/backend/ci_backends"
13-
"github.com/diggerhq/digger/drift/controllers"
14-
"github.com/diggerhq/digger/drift/middleware"
13+
"github.com/diggerhq/digger/drift/controllers"
14+
"github.com/diggerhq/digger/drift/middleware"
1515
"github.com/getsentry/sentry-go"
1616
sentrygin "github.com/getsentry/sentry-go/gin"
1717
"github.com/gin-gonic/gin"

ee/cli/pkg/drift/github_issue.go

Lines changed: 0 additions & 51 deletions
This file was deleted.

ee/cli/pkg/drift/provider.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package drift
33
import (
44
"fmt"
55
core_drift "github.com/diggerhq/digger/cli/pkg/core/drift"
6-
"github.com/diggerhq/digger/cli/pkg/drift"
6+
ce_drift "github.com/diggerhq/digger/cli/pkg/drift"
77
"github.com/diggerhq/digger/libs/ci"
88
"os"
99
)
@@ -16,11 +16,11 @@ func (d DriftNotificationProviderAdvanced) Get(prService ci.PullRequestService)
1616
DriftAsGithubIssues := os.Getenv("INPUT_DRIFT_GITHUB_ISSUES")
1717
var notification core_drift.Notification
1818
if slackNotificationUrl != "" {
19-
notification = &drift.SlackNotification{Url: slackNotificationUrl}
19+
notification = &ce_drift.SlackNotification{Url: slackNotificationUrl}
2020
} else if slackNotificationAdvancedUrl != "" {
2121
notification = NewSlackAdvancedAggregatedNotificationWithAiSummary(slackNotificationAdvancedUrl)
2222
} else if DriftAsGithubIssues != "" {
23-
notification = &GithubIssueNotification{GithubService: &prService}
23+
notification = &ce_drift.GithubIssueNotification{GithubService: &prService}
2424
} else {
2525
return nil, fmt.Errorf("could not identify drift mode, please specify using env variable INPUT_DRIFT_DETECTION_SLACK_NOTIFICATION_URL, INPUT_DRIFT_DETECTION_ADVANCED_SLACK_NOTIFICATION_URL or INPUT_DRIFT_GITHUB_ISSUES")
2626
}

ee/drift/main.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import (
99
"net/http"
1010
"os"
1111

12-
"github.com/diggerhq/digger/backend/ci_backends"
13-
"github.com/diggerhq/digger/drift/controllers"
14-
"github.com/diggerhq/digger/drift/middleware"
15-
"github.com/getsentry/sentry-go"
16-
sentrygin "github.com/getsentry/sentry-go/gin"
17-
"github.com/gin-gonic/gin"
18-
sloggin "github.com/samber/slog-gin"
12+
"github.com/diggerhq/digger/backend/ci_backends"
13+
"github.com/diggerhq/digger/drift/controllers"
14+
"github.com/diggerhq/digger/drift/middleware"
15+
"github.com/getsentry/sentry-go"
16+
sentrygin "github.com/getsentry/sentry-go/gin"
17+
"github.com/gin-gonic/gin"
18+
sloggin "github.com/samber/slog-gin"
1919
)
2020

2121
func init() {

0 commit comments

Comments
 (0)