Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@bdovaz
Copy link
Collaborator

@bdovaz bdovaz commented Jan 8, 2025

If you have REPOSITORY_GITLEAKS_PR_COMMITS_SCAN: true but the linter is not enabled it will fail:

https://github.com/oxsecurity/megalinter/blob/2402a653f4d13b4a4be7b0ab2df3b5b9fa325d7e/megalinter/linters/GitleaksLinter.py

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/megalinter/run.py", line 11, in <module>
    linter = megalinter.Megalinter({"cli": True, "request_id": str(uuid.uuid1())})
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/megalinter/MegaLinter.py", line 185, in __init__
    self.load_linters()
  File "/megalinter/MegaLinter.py", line 612, in load_linters
    all_linters = linter_factory.list_all_linters(linter_init_params)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/megalinter/linter_factory.py", line 30, in list_all_linters
    descriptor_linters = build_descriptor_linters(
                         ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/megalinter/linter_factory.py", line 117, in build_descriptor_linters
    linter_instance = linter_class(linter_init_params, instance_attributes)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/megalinter/linters/GitleaksLinter.py", line 19, in __init__
    self.pr_source_sha, self.pr_target_sha = self.get_pr_data()
                                             ^^^^^^^^^^^^^^^^^^
  File "/megalinter/linters/GitleaksLinter.py", line 40, in get_pr_data
    pr_target_sha = self.get_azure_devops_pr_target_sha(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/megalinter/linters/GitleaksLinter.py", line 67, in get_azure_devops_pr_target_sha
    repo = utils.git.Repo(os.path.realpath(self.workspace))
                                           ^^^^^^^^^^^^^^
AttributeError: 'GitleaksLinter' object has no attribute 'workspace'

This happens because if the linter is not active, the workspace variable is not assigned:

self.workspace = params["workspace"] if "workspace" in params else "."

I therefore propose that you do nothing if it is deactivated.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 8, 2025

🦙 MegaLinter status: ⚠️ WARNING

Descriptor Linter Files Fixed Errors Elapsed time
✅ API spectral 1 0 1.77s
⚠️ BASH bash-exec 6 1 0.02s
✅ BASH shellcheck 6 0 0.21s
✅ BASH shfmt 6 0 0 0.84s
✅ COPYPASTE jscpd yes no 3.4s
✅ DOCKERFILE hadolint 129 0 23.87s
✅ JSON jsonlint 20 0 0.25s
✅ JSON v8r 22 0 16.49s
⚠️ MARKDOWN markdownlint 267 0 301 27.93s
✅ MARKDOWN markdown-table-formatter 267 0 0 159.85s
⚠️ PYTHON bandit 214 66 3.5s
✅ PYTHON black 214 0 0 5.49s
✅ PYTHON flake8 214 0 2.05s
✅ PYTHON isort 214 0 0 1.18s
✅ PYTHON mypy 214 0 18.58s
✅ PYTHON pylint 214 0 34.22s
✅ PYTHON ruff 214 0 0 0.78s
✅ REPOSITORY checkov yes no 36.44s
✅ REPOSITORY git_diff yes no 1.32s
⚠️ REPOSITORY grype yes 26 15.61s
✅ REPOSITORY secretlint yes no 11.82s
✅ REPOSITORY trivy yes no 16.51s
✅ REPOSITORY trivy-sbom yes no 0.28s
⚠️ REPOSITORY trufflehog yes 1 53.21s
✅ SPELL cspell 717 0 13.97s
⚠️ SPELL lychee 349 13 6.05s
✅ XML xmllint 3 0 0 0.81s
✅ YAML prettier 160 0 0 5.03s
✅ YAML v8r 102 0 34.04s
✅ YAML yamllint 161 0 2.98s

See detailed report in MegaLinter reports

MegaLinter is graciously provided by OX Security

@nvuillam nvuillam merged commit fbad2c0 into main Jan 9, 2025
131 checks passed
@nvuillam nvuillam deleted the fix-disabled-gitleaks branch January 9, 2025 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants