phantomcyber / dev-cicd-tools

Apache License 2.0
4 stars 1 forks source link

Prevent markdown files from being modified when some pre-commit hooks are run #33

Closed jdemelo closed 2 years ago

jdemelo commented 2 years ago

Some markdown files are getting modified as part of pre-commit hook execution. We should prevent this from happening, since the changes (even whitespace only) can modify how the documents are formatted.

Testing

Before

README.md is modified ``` jdemelo@C02D2551MD6R> splunk-soar-connectors (, play1.dev.us-wes) $ git clone git@github.com:splunk-soar-connectors/autofocus.git Cloning into 'autofocus'... remote: Enumerating objects: 182, done. remote: Counting objects: 100% (182/182), done. remote: Compressing objects: 100% (126/126), done. remote: Total 182 (delta 76), reused 141 (delta 52), pack-reused 0 Receiving objects: 100% (182/182), 825.33 KiB | 1.13 MiB/s, done. Resolving deltas: 100% (76/76), done. jdemelo@C02D2551MD6R> splunk-soar-connectors (, play1.dev.us-wes) $ cd autofocus jdemelo@C02D2551MD6R> autofocus (next, play1.dev.us-wes) $ pre-commit run --all-files [INFO] Initializing environment for https://github.com/phantomcyber/dev-cicd-tools. [INFO] Initializing environment for https://github.com/Yelp/detect-secrets. [INFO] Installing environment for https://github.com/Yelp/detect-secrets. [INFO] Once installed this environment will be reused. [INFO] This may take a few minutes... org-wide hooks...........................................................Failed ... jdemelo@C02D2551MD6R> autofocus (next, play1.dev.us-wes) $ git status On branch next Your branch is up to date with 'origin/next'. Changes not staged for commit: (use "git add/rm ..." to update what will be committed) (use "git restore ..." to discard changes in working directory) modified: .github/workflows/linting.yml modified: .github/workflows/semgrep.yml modified: .github/workflows/start-release.yml modified: README.md modified: af_get_report.html modified: autofocus.json modified: logo_paloaltonetworks.svg modified: logo_paloaltonetworks_dark.svg deleted: wheels/urllib3-1.26.7-py2.py3-none-any.whl Untracked files: (use "git add ..." to include in what will be committed) tox.ini wheels/urllib3-1.26.8-py2.py3-none-any.whl no changes added to commit (use "git add" and/or "git commit -a") jdemelo@C02D2551MD6R> autofocus (next, play1.dev.us-wes) $ ```

After

README.md is not modified ``` jdemelo@C02D2551MD6R> splunk-soar-connectors (, play1.dev.us-wes) $ git clone git@github.com:splunk-soar-connectors/autofocus.git Cloning into 'autofocus'... remote: Enumerating objects: 182, done. remote: Counting objects: 100% (182/182), done. remote: Compressing objects: 100% (126/126), done. remote: Total 182 (delta 76), reused 141 (delta 52), pack-reused 0 Receiving objects: 100% (182/182), 825.33 KiB | 1.38 MiB/s, done. Resolving deltas: 100% (76/76), done. jdemelo@C02D2551MD6R> splunk-soar-connectors (, play1.dev.us-wes) $ cd autofocus jdemelo@C02D2551MD6R> autofocus (next, play1.dev.us-wes) $ pre-commit try-repo https://github.com/phantomcyber/dev-cicd-tools --ref 64b2a413b862ccd2bad1373c2055237268d9f29c --all-files [INFO] Initializing environment for https://github.com/phantomcyber/dev-cicd-tools. =============================================================================== Using config: =============================================================================== repos: - repo: https://github.com/phantomcyber/dev-cicd-tools rev: 64b2a413b862ccd2bad1373c2055237268d9f29c hooks: - id: org-hook - id: package-app-dependencies ... jdemelo@C02D2551MD6R> autofocus (next, play1.dev.us-wes) $ git status On branch next Your branch is up to date with 'origin/next'. Changes not staged for commit: (use "git add/rm ..." to update what will be committed) (use "git restore ..." to discard changes in working directory) modified: .github/workflows/linting.yml modified: .github/workflows/semgrep.yml modified: .github/workflows/start-release.yml modified: af_get_report.html modified: autofocus.json modified: logo_paloaltonetworks.svg modified: logo_paloaltonetworks_dark.svg deleted: wheels/urllib3-1.26.7-py2.py3-none-any.whl Untracked files: (use "git add ..." to include in what will be committed) tox.ini wheels/urllib3-1.26.8-py2.py3-none-any.whl no changes added to commit (use "git add" and/or "git commit -a") jdemelo@C02D2551MD6R> autofocus (next, play1.dev.us-wes) $ ```
rgil-splunk commented 2 years ago

btw, I was thinking we may want to add a pre-commit config (basically copying orghooks.yml) + tox.ini (maybe just a top-level symlink since it already lives in this repo?) to this repo and doing a pre-commit run --all-files. this repo already contains all the template files + tests for start-release and whatnot, so it would capture if we missed other edge cases like this

I actually did the two things above yesterday (add pre-commit and run on all files), but the tests failed so I didn't delve into fixing them. as such not sure how much effort it might take, so it could be done in a separate PR as well 🙂

jdemelo commented 2 years ago

btw, I was thinking we may want to add a pre-commit config (basically copying orghooks.yml) + tox.ini (maybe just a top-level symlink since it already lives in this repo?) to this repo and doing a pre-commit run --all-files. this repo already contains all the template files + tests for start-release and whatnot, so it would capture if we missed other edge cases like this

I actually did the two things above yesterday (add pre-commit and run on all files), but the tests failed so I didn't delve into fixing them. as such not sure how much effort it might take, so it could be done in a separate PR as well 🙂

Oh nice! I would think we should treat them separately. It would be good to start preventing the ongoing markdown edits ASAP.

rgil-splunk commented 2 years ago

also cc: @shiyingtu