Skip to content

Commit 46492d6

Browse files
Merge pull request #1073 from Checkmarx/pre-commit-hook
Pre commit hook
2 parents 144331c + d01e4ca commit 46492d6

File tree

6 files changed

+16
-18
lines changed

6 files changed

+16
-18
lines changed

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/Checkmarx/containers-resolver v1.0.6-0.20250130184119-42af4015f216
77
github.com/Checkmarx/gen-ai-prompts v0.0.0-20240807143411-708ceec12b63
88
github.com/Checkmarx/gen-ai-wrapper v1.0.2
9-
github.com/Checkmarx/secret-detection v0.0.3-0.20250227154803-c62fe8ce1523
9+
github.com/Checkmarx/secret-detection v0.0.3-0.20250327150305-31c2c3be9edf
1010
github.com/MakeNowJust/heredoc v1.0.0
1111
github.com/bouk/monkey v1.0.0
1212
github.com/gofrs/flock v0.12.1
@@ -28,6 +28,7 @@ require (
2828
golang.org/x/text v0.22.0
2929
google.golang.org/grpc v1.67.3
3030
google.golang.org/protobuf v1.36.3
31+
gopkg.in/yaml.v2 v2.4.0
3132
gopkg.in/yaml.v3 v3.0.1
3233
gotest.tools v2.2.0+incompatible
3334
)
@@ -82,7 +83,7 @@ require (
8283
github.com/chai2010/gettext-go v1.0.3 // indirect
8384
github.com/charmbracelet/lipgloss v1.0.0 // indirect
8485
github.com/charmbracelet/x/ansi v0.4.5 // indirect
85-
github.com/checkmarx/2ms v1.4.1-0.20250227102300-e162a8629579 // indirect
86+
github.com/checkmarx/2ms v1.4.1-0.20250327145719-b78804cb08c7 // indirect
8687
github.com/cloudflare/circl v1.3.8 // indirect
8788
github.com/containerd/cgroups/v3 v3.0.3 // indirect
8889
github.com/containerd/containerd v1.7.24 // indirect
@@ -285,7 +286,6 @@ require (
285286
gopkg.in/inf.v0 v0.9.1 // indirect
286287
gopkg.in/ini.v1 v1.67.0 // indirect
287288
gopkg.in/warnings.v0 v0.1.2 // indirect
288-
gopkg.in/yaml.v2 v2.4.0 // indirect
289289
helm.sh/helm/v3 v3.17.0 // indirect
290290
k8s.io/api v0.32.0 // indirect
291291
k8s.io/apiextensions-apiserver v0.32.0 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ github.com/Checkmarx/gen-ai-prompts v0.0.0-20240807143411-708ceec12b63 h1:SCuTcE
7575
github.com/Checkmarx/gen-ai-prompts v0.0.0-20240807143411-708ceec12b63/go.mod h1:MI6lfLerXU+5eTV/EPTDavgnV3owz3GPT4g/msZBWPo=
7676
github.com/Checkmarx/gen-ai-wrapper v1.0.2 h1:T6X40+4hYnwfDsvkjWs9VIcE6s1O+8DUu0+sDdCY3GI=
7777
github.com/Checkmarx/gen-ai-wrapper v1.0.2/go.mod h1:xwRLefezwNNnRGu1EjGS6wNiR9FVV/eP9D+oXwLViVM=
78-
github.com/Checkmarx/secret-detection v0.0.3-0.20250227154803-c62fe8ce1523 h1:F2aOPKbcCZPZBxfsJ1c7pNK0rjA8P9wPxBZ48YnZuw0=
79-
github.com/Checkmarx/secret-detection v0.0.3-0.20250227154803-c62fe8ce1523/go.mod h1:lLVCf7AT8v2LV+up7yIcj8aValbOSIJ+f453015/1P4=
78+
github.com/Checkmarx/secret-detection v0.0.3-0.20250327150305-31c2c3be9edf h1:lKiogedU3WzWBc/xI6Xj1BhX2Gp1QBJj8C+czY7CcaE=
79+
github.com/Checkmarx/secret-detection v0.0.3-0.20250327150305-31c2c3be9edf/go.mod h1:mtAHOm1mHGh7MVu6JdYUyitANsLcHNLUTBIh9pTERNI=
8080
github.com/CycloneDX/cyclonedx-go v0.9.2 h1:688QHn2X/5nRezKe2ueIVCt+NRqf7fl3AVQk+vaFcIo=
8181
github.com/CycloneDX/cyclonedx-go v0.9.2/go.mod h1:vcK6pKgO1WanCdd61qx4bFnSsDJQ6SbM2ZuMIgq86Jg=
8282
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
@@ -216,8 +216,8 @@ github.com/charmbracelet/x/ansi v0.4.5 h1:LqK4vwBNaXw2AyGIICa5/29Sbdq58GbGdFngSe
216216
github.com/charmbracelet/x/ansi v0.4.5/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
217217
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
218218
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
219-
github.com/checkmarx/2ms v1.4.1-0.20250227102300-e162a8629579 h1:zfbP8DzU00h1bm7PhTBNQglr47qXV+5PdUY6+iJkvRI=
220-
github.com/checkmarx/2ms v1.4.1-0.20250227102300-e162a8629579/go.mod h1:Bnd2YSh8LQSc4fHAFN0BKz8LYThB6qHg3Wn/+H+WZ4I=
219+
github.com/checkmarx/2ms v1.4.1-0.20250327145719-b78804cb08c7 h1:COsC3skOJeJaSoCPuhLZ0byRGKm+ZHlyw5qm9ydlab0=
220+
github.com/checkmarx/2ms v1.4.1-0.20250327145719-b78804cb08c7/go.mod h1:Bnd2YSh8LQSc4fHAFN0BKz8LYThB6qHg3Wn/+H+WZ4I=
221221
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
222222
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
223223
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=

internal/commands/pre_commit.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func PreCommitCommand(jwtWrapper wrappers.JWTWrapper) *cobra.Command {
5151
`,
5252
),
5353
}
54+
preCommitCmd.PersistentFlags().Bool("global", false, "Install the hook globally for all repositories")
5455

5556
preCommitCmd.AddCommand(secretsInstallGitHookCommand(jwtWrapper))
5657
preCommitCmd.AddCommand(secretsUninstallGitHookCommand(jwtWrapper))
@@ -89,7 +90,8 @@ func secretsInstallGitHookCommand(jwtWrapper wrappers.JWTWrapper) *cobra.Command
8990
return validateLicense(jwtWrapper)
9091
},
9192
RunE: func(cmd *cobra.Command, args []string) error {
92-
return precommit.Install()
93+
global, _ := cmd.Flags().GetBool("global")
94+
return precommit.Install(global)
9395
},
9496
}
9597

@@ -106,11 +108,9 @@ func secretsUninstallGitHookCommand(jwtWrapper wrappers.JWTWrapper) *cobra.Comma
106108
$ cx hooks pre-commit secrets-uninstall-git-hook
107109
`,
108110
),
109-
PreRunE: func(cmd *cobra.Command, args []string) error {
110-
return validateLicense(jwtWrapper)
111-
},
112111
RunE: func(cmd *cobra.Command, args []string) error {
113-
return precommit.Uninstall()
112+
global, _ := cmd.Flags().GetBool("global")
113+
return precommit.Uninstall(global)
114114
},
115115
}
116116

@@ -131,7 +131,8 @@ func secretsUpdateGitHookCommand(jwtWrapper wrappers.JWTWrapper) *cobra.Command
131131
return validateLicense(jwtWrapper)
132132
},
133133
RunE: func(cmd *cobra.Command, args []string) error {
134-
return precommit.Update()
134+
global, _ := cmd.Flags().GetBool("global")
135+
return precommit.Update(global)
135136
},
136137
}
137138

internal/commands/predicates_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,4 +338,3 @@ func TestDetermineSystemOrCustomState(t *testing.T) {
338338
})
339339
}
340340
}
341-

internal/services/export.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func pollForCompletion(exportWrapper wrappers.ExportWrapper, exportID string) (*
112112
logger.PrintIfVerbose("Polling for export report generation completion")
113113

114114
for pollingResp.ExportStatus == exportingStatus || pollingResp.ExportStatus == pendingStatus {
115-
115+
116116
logger.Printf("SCA Export Status is: %s", pollingResp.ExportStatus)
117117

118118
select {

test/integration/predicate_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,6 @@ func TestPredicateWithInvalidValues(t *testing.T) {
153153
assert.Assert(t, kicsPredicate.TotalCount == 0, "Predicate with invalid values should have 0 as the result.")
154154
}
155155

156-
157-
158156
func TestTriageShowAndUpdateWithCustomStates(t *testing.T) {
159157
t.Skip("Skipping this test temporarily until the API becomes available in the DEU environment.")
160158
fmt.Println("Step 1: Testing the command 'triage show' with predefined values.")
@@ -216,4 +214,4 @@ func TestTriageShowAndUpdateWithCustomStates(t *testing.T) {
216214
}
217215

218216
assert.Assert(t, found, "Updated predicate should have state set to state2")
219-
}
217+
}

0 commit comments

Comments
 (0)