Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled exception for Gitlab comment reporter #1246

Closed
1vm0 opened this issue Feb 3, 2022 · 0 comments · Fixed by #1247
Closed

Unhandled exception for Gitlab comment reporter #1246

1vm0 opened this issue Feb 3, 2022 · 0 comments · Fixed by #1247
Labels
bug Something isn't working

Comments

@1vm0
Copy link
Contributor

1vm0 commented Feb 3, 2022

If the environment variable GITLAB_COMMENT_REPORTER set as true, but the pipeline being executed is not a merge request pipeline, then the python-gitlab package will throw a gitlab.exceptions.GitlabParsingError exception and GitlabCommentReporter does not catch it and megalinter will crash.

traceback:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.9/site-packages/megalinter-0.1-py3.9.egg/megalinter/run.py", line 15, in <module>
    linter.run()
  File "/usr/local/lib/python3.9/site-packages/megalinter-0.1-py3.9.egg/megalinter/MegaLinter.py", line 172, in run
    reporter.produce_report()
  File "/usr/local/lib/python3.9/site-packages/megalinter-0.1-py3.9.egg/megalinter/reporters/GitlabCommentReporter.py", line 72, in produce_report
    mr = project.mergerequests.get(gitlab_merge_request_id)
  File "/usr/local/lib/python3.9/site-packages/python_gitlab-3.1.1-py3.9.egg/gitlab/v4/objects/merge_requests.py", line 467, in get
    return cast(ProjectMergeRequest, super().get(id=id, lazy=lazy, **kwargs))
  File "/usr/local/lib/python3.9/site-packages/python_gitlab-3.1.1-py3.9.egg/gitlab/exceptions.py", line 311, in wrapped_f
    return f(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/python_gitlab-3.1.1-py3.9.egg/gitlab/mixins.py", line 114, in get
    return self._obj_cls(self, server_data)
  File "/usr/local/lib/python3.9/site-packages/python_gitlab-3.1.1-py3.9.egg/gitlab/base.py", line 73, in __init__
    raise GitlabParsingError(

This happens because if the CI_MERGE_REQUEST_ID and CI_OPEN_MERGE_REQUESTS environment variables are missing, then the gitlab_merge_request_id variable is set to empty string.

@1vm0 1vm0 added the bug Something isn't working label Feb 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant