You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cycode’s pre-commit hook can be set up within your local repository so that the Cycode CLI application will identify any issues with your code automatically before you commit it to your codebase.
217
+
Cycode's pre-commit and pre-push hooks can be set up within your local repository so that the Cycode CLI application will identify any issues with your code automatically before you commit or push it to your codebase.
217
218
218
219
> [!NOTE]
219
-
> pre-commit hook is not available for IaC scans.
220
+
> pre-commit and pre-push hooks are not available for IaC scans.
220
221
221
222
Perform the following steps to install the pre-commit hook:
222
223
224
+
### Installing Pre-Commit Hook
225
+
223
226
1. Install the pre-commit framework (Python 3.9 or higher must be installed):
224
227
225
228
```bash
@@ -278,6 +281,37 @@ Perform the following steps to install the pre-commit hook:
278
281
> Trigger happens on `git commit` command.
279
282
> Hook triggers only on the files that are staged for commit.
280
283
284
+
### Installing Pre-Push Hook
285
+
286
+
To install the pre-push hook in addition to or instead of the pre-commit hook:
287
+
288
+
1. Add the pre-push hooks to your `.pre-commit-config.yaml` file:
289
+
290
+
```yaml
291
+
repos:
292
+
- repo: https://github.com/cycodehq/cycode-cli
293
+
rev: v3.4.2
294
+
hooks:
295
+
- id: cycode-pre-push
296
+
stages: [pre-push]
297
+
```
298
+
299
+
2. Install the pre-push hook:
300
+
301
+
```bash
302
+
pre-commit install --hook-type pre-push
303
+
```
304
+
305
+
3. For both pre-commit and pre-push hooks, use:
306
+
307
+
```bash
308
+
pre-commit install
309
+
pre-commit install --hook-type pre-push
310
+
```
311
+
312
+
> [!NOTE]
313
+
> Pre-push hooks trigger on `git push` command and scan only the commits about to be pushed.
314
+
281
315
# Cycode CLI Commands
282
316
283
317
The following are the options and commands available with the Cycode CLI application:
@@ -786,6 +820,91 @@ After installing the pre-commit hook, you may occasionally wish to skip scanning
786
820
SKIP=cycode git commit -m <your commit message>`
787
821
```
788
822
823
+
### Pre-Push Scan
824
+
825
+
A pre-push scan automatically identifies any issues before you push changes to the remote repository. This hook runs on the client side and scans only the commits that are about to be pushed, making it efficient for catching issues before they reach the remote repository.
826
+
827
+
> [!NOTE]
828
+
> Pre-push hook is not available for IaC scans.
829
+
830
+
The pre-push hook integrates with the pre-commit framework and can be configured to run before any `git push` operation.
831
+
832
+
#### Installing Pre-Push Hook
833
+
834
+
To set up the pre-push hook using the pre-commit framework:
835
+
836
+
1. Install the pre-commit framework (if not already installed):
837
+
838
+
```bash
839
+
pip3 install pre-commit
840
+
```
841
+
842
+
2. Create or update your `.pre-commit-config.yaml` file to include the pre-push hooks:
843
+
844
+
```yaml
845
+
repos:
846
+
- repo: https://github.com/cycodehq/cycode-cli
847
+
rev: v3.4.2
848
+
hooks:
849
+
- id: cycode-pre-push
850
+
stages: [pre-push]
851
+
```
852
+
853
+
3. For multiple scan types, use this configuration:
854
+
855
+
```yaml
856
+
repos:
857
+
- repo: https://github.com/cycodehq/cycode-cli
858
+
rev: v3.4.2
859
+
hooks:
860
+
- id: cycode-pre-push # Secrets scan
861
+
stages: [pre-push]
862
+
- id: cycode-sca-pre-push # SCA scan
863
+
stages: [pre-push]
864
+
- id: cycode-sast-pre-push # SAST scan
865
+
stages: [pre-push]
866
+
```
867
+
868
+
4. Install the pre-push hook:
869
+
870
+
```bash
871
+
pre-commit install --hook-type pre-push
872
+
```
873
+
874
+
A successful installation will result in the message: `Pre-push installed at .git/hooks/pre-push`.
875
+
876
+
5. Keep the pre-push hook up to date:
877
+
878
+
```bash
879
+
pre-commit autoupdate
880
+
```
881
+
882
+
#### How Pre-Push Scanning Works
883
+
884
+
The pre-push hook:
885
+
- Receives information about what commits are being pushed
886
+
- Calculates the appropriate commit range to scan
887
+
- For new branches: scans all commits from the merge base with the default branch
888
+
- For existing branches: scans only the new commits since the last push
889
+
- Runs the same comprehensive scanning as other Cycode scan modes
890
+
891
+
#### Skipping Pre-Push Scans
892
+
893
+
To skip the pre-push scan for a specific push operation, use:
894
+
895
+
```bash
896
+
SKIP=cycode-pre-push git push
897
+
```
898
+
899
+
Or to skip all pre-push hooks:
900
+
901
+
```bash
902
+
git push --no-verify
903
+
```
904
+
905
+
> [!TIP]
906
+
> The pre-push hook is triggered on `git push` command and scans only the commits that are about to be pushed, making it more efficient than scanning the entire repository.
907
+
789
908
## Scan Results
790
909
791
910
Each scan will complete with a message stating if any issues were found or not.
0 commit comments