GitGuardian / ggshield

Find and fix 400+ types of hardcoded secrets and 70+ types of infrastructure-as-code misconfigurations.
https://gitguardian.com
MIT License
1.62k stars 143 forks source link

fix: fix gitlab push pipelines for new branches #809

Closed Paul-GitGuardian closed 9 months ago

Paul-GitGuardian commented 9 months ago

When pushing a new branch for the first time, the GGshield IAC and SCA CI cannot find the commit to use as ref. As described here, CI_COMMIT_BEFORE_SHA is empty in that case. Here we use git commands to find the starting commit of the new branch.

codecov-commenter commented 9 months ago

Codecov Report

Attention: 9 lines in your changes are missing coverage. Please review.

Comparison is base (ea75562) 92.15% compared to head (cb42e1a) 92.03%.

Files Patch % Lines
ggshield/core/git_hooks/ci/previous_commit.py 10.00% 9 Missing :warning:

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #809 +/- ## ========================================== - Coverage 92.15% 92.03% -0.12% ========================================== Files 160 160 Lines 6766 6781 +15 ========================================== + Hits 6235 6241 +6 - Misses 531 540 +9 ``` | [Flag](https://app.codecov.io/gh/GitGuardian/ggshield/pull/809/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GitGuardian) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/GitGuardian/ggshield/pull/809/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GitGuardian) | `92.03% <40.00%> (-0.12%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GitGuardian#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

Paul-GitGuardian commented 9 months ago

Good catch, in fact it doesn't clone other branches. I've changed it to use remote branches instead. Not sure if I can test the CI using this branch on a real repository. At least I've tested the git commands in a Gitlab pipeline, they work.

GG-HH commented 9 months ago

You can test it, just declare a job that will clone and install ggshield from your latest commit (maybe on another repo).

BTW, the CI is failing here

Paul-GitGuardian commented 9 months ago

@GG-HH I've tested on a repository and made the necessary changes. Could you review it one last time please?