Repository: diggerhq/digger
Pull request #377 (2023-06-15 16:27:39)

make digger commands case insensitive


Patch:
diff --git a/pkg/azure/azure.go b/pkg/azure/azure.go
index 3fb5e4cb..9caffbf8 100644
--- a/pkg/azure/azure.go
+++ b/pkg/azure/azure.go
@@ -409,11 +409,8 @@ func ConvertAzureEventToCommands(parseAzureContext Azure, impactedProjects []con
 		}
 		return commandsPerProject, true, nil
 	case AzurePrCommented:
-
-		diggerCommand := parseAzureContext.Event.(AzureCommentEvent).Resource.Comment.Content
-
+		diggerCommand := strings.ToLower(parseAzureContext.Event.(AzureCommentEvent).Resource.Comment.Content)
 		coversAllImpactedProjects := true
-
 		runForProjects := impactedProjects
 
 		if requestedProject != nil {
diff --git a/pkg/github/github.go b/pkg/github/github.go
index 7ab3b3e9..4f012bd4 100644
--- a/pkg/github/github.go
+++ b/pkg/github/github.go
@@ -202,8 +202,10 @@ func ConvertGithubEventToCommands(event models.Event, impactedProjects []configu
 			}
 		}
 
+		diggerCommand := strings.ToLower(event.Comment.Body)
+
 		for _, command := range supportedCommands {
-			if strings.Contains(event.Comment.Body, command) {
+			if strings.Contains(diggerCommand, command) {
 				for _, project := range runForProjects {
 					workflow, ok := workflows[project.Workflow]
 					if !ok {
diff --git a/pkg/gitlab/gitlab.go b/pkg/gitlab/gitlab.go
index b46e429a..8b9fd58e 100644
--- a/pkg/gitlab/gitlab.go
+++ b/pkg/gitlab/gitlab.go
@@ -101,7 +101,8 @@ func ProcessGitLabEvent(gitlabContext *GitLabContext, diggerConfig *configuratio
 
 	switch gitlabContext.EventType {
 	case MergeRequestComment:
-		requestedProject := utils.ParseProjectName(gitlabContext.DiggerCommand)
+		diggerCommand := strings.ToLower(gitlabContext.DiggerCommand)
+		requestedProject := utils.ParseProjectName(diggerCommand)
 
 		if requestedProject == "" {
 			return impactedProjects, nil, nil
@@ -311,15 +312,16 @@ func ConvertGitLabEventToCommands(event GitLabEvent, gitLabContext *GitLabContex
 			}
 		}
 
+		diggerCommand := strings.ToLower(gitLabContext.DiggerCommand)
 		for _, command := range supportedCommands {
-			if strings.Contains(gitLabContext.DiggerCommand, command) {
+			if strings.Contains(diggerCommand, command) {
 				for _, project := range runForProjects {
 					workflow, ok := workflows[project.Workflow]
 					if !ok {
 						workflow = workflows["default"]
 					}
 					workspace := project.Workspace
-					workspaceOverride, err := utils.ParseWorkspace(gitLabContext.DiggerCommand)
+					workspaceOverride, err := utils.ParseWorkspace(diggerCommand)
 					if err != nil {
 						return []models.ProjectCommand{}, false, err
 					}


Test patch:
diff --git a/cmd/digger/main_test.go b/cmd/digger/main_test.go
index 9deb7ad9..f663f61c 100644
--- a/cmd/digger/main_test.go
+++ b/cmd/digger/main_test.go
@@ -987,3 +987,22 @@ func TestGitHubNewPullRequestInMultiEnvProjectContext(t *testing.T) {
 	assert.Equal(t, 1, len(commandsToRunPerProject))
 	assert.NoError(t, err)
 }
+
+func TestGitHubTestPRCommandCaseInsensitivity(t *testing.T) {
+	ghEvent := gh_models.IssueCommentEvent{}
+	ghEvent.Comment.Body = "DiGGeR PlAn"
+
+	project := configuration.Project{Name: "test project", Workflow: "default"}
+	var impactedProjects []configuration.Project
+	impactedProjects = make([]configuration.Project, 1)
+	impactedProjects[0] = project
+	var requestedProject = project
+	workflows := make(map[string]configuration.Workflow, 1)
+	workflows["default"] = configuration.Workflow{}
+
+	commandsToRunPerProject, _, err := github.ConvertGithubEventToCommands(ghEvent, impactedProjects, &requestedProject, workflows)
+
+	assert.Equal(t, 1, len(commandsToRunPerProject))
+	assert.Equal(t, "digger plan", commandsToRunPerProject[0].Commands[0])
+	assert.NoError(t, err)
+}