-
Notifications
You must be signed in to change notification settings - Fork 22
Add --gitlab option to mh_style and mh_lint #303
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
Open
LucasDooms
wants to merge
1
commit into
florianschanda:master
Choose a base branch
from
LucasDooms:gitlab-code-quality-output
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -28,6 +28,7 @@ | |||||||||
| import sys | ||||||||||
| import html | ||||||||||
| import json | ||||||||||
| import hashlib | ||||||||||
|
|
||||||||||
| from miss_hit_core import pathutil | ||||||||||
| from miss_hit_core.config import STYLE_RULES, METRICS | ||||||||||
|
|
@@ -103,6 +104,12 @@ def to_json(self, detailed=True): | |||||||||
| rv["context"] = self.context | ||||||||||
| return rv | ||||||||||
|
|
||||||||||
| def to_gitlab(self): | ||||||||||
| rv = {} | ||||||||||
| rv["path"] = self.filename if self.filename else "" | ||||||||||
| rv["lines"] = {"begin": self.line if self.line else 0} | ||||||||||
| return rv | ||||||||||
|
|
||||||||||
| def short_string(self): | ||||||||||
| rv = self.filename | ||||||||||
| if self.line: | ||||||||||
|
|
@@ -197,6 +204,36 @@ def to_json(self): | |||||||||
| "fixable" : self.fixed, | ||||||||||
| "fatal" : self.fatal} | ||||||||||
|
|
||||||||||
| def to_gitlab(self): | ||||||||||
| check_name = self.check_id if self.check_id else "" | ||||||||||
|
|
||||||||||
| map_severity = { | ||||||||||
| "low": "info", | ||||||||||
| "medium": "minor", | ||||||||||
| "high": "major", | ||||||||||
| } | ||||||||||
| severity = map_severity.get(self.severity, "minor") | ||||||||||
|
|
||||||||||
| if self.fatal: | ||||||||||
| severity = "critical" | ||||||||||
| check_name = "fatal" | ||||||||||
|
|
||||||||||
| contents = { | ||||||||||
| "description" : self.message, | ||||||||||
| "check_name" : check_name, | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Eventually map categories in https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md#data-types to |
||||||||||
| "fingerprint" : 0, | ||||||||||
| "severity" : severity, | ||||||||||
| "location" : self.location.to_gitlab(), | ||||||||||
| } | ||||||||||
|
|
||||||||||
| # Produce unique fingerprint based on contents | ||||||||||
| # Use sort_keys for better reproducibility | ||||||||||
| contents["fingerprint"] = hashlib.sha1( | ||||||||||
| json.dumps(contents, sort_keys=True).encode("utf-8") | ||||||||||
| ).hexdigest() | ||||||||||
|
|
||||||||||
| return contents | ||||||||||
|
|
||||||||||
|
|
||||||||||
| class Check_Message(Message): | ||||||||||
| def __init__(self, location, severity, check_id, message): | ||||||||||
|
|
@@ -760,3 +797,34 @@ def emit_summary(self): | |||||||||
| json.dump(self.blob, self.fd, indent=2) | ||||||||||
| self.fd.write("\n") | ||||||||||
| self.fd.close() | ||||||||||
|
|
||||||||||
|
|
||||||||||
| class GITLAB_Message_Handler(File_Based_Message_Handler): | ||||||||||
| def __init__(self, tool_id, filename): | ||||||||||
| super().__init__(tool_id, filename) | ||||||||||
| self.blob = None | ||||||||||
|
|
||||||||||
| def fork(self): | ||||||||||
| rv = GITLAB_Message_Handler(self.tool_id, self.filename) | ||||||||||
| self.fork_copy_attributes(rv) | ||||||||||
| return rv | ||||||||||
|
|
||||||||||
| def setup_fd(self): | ||||||||||
| # pylint: disable=consider-using-with | ||||||||||
| if self.fd is not None: | ||||||||||
| return | ||||||||||
|
|
||||||||||
| self.fd = open(self.filename, "w", encoding="UTF-8") | ||||||||||
| self.blob = [] | ||||||||||
|
|
||||||||||
| def emit_message(self, message): | ||||||||||
| self.setup_fd() | ||||||||||
|
|
||||||||||
| self.blob.append(message.to_gitlab()) | ||||||||||
|
|
||||||||||
| def emit_summary(self): | ||||||||||
| self.setup_fd() | ||||||||||
| super().emit_summary() | ||||||||||
| json.dump(self.blob, self.fd, indent=2) | ||||||||||
| self.fd.write("\n") | ||||||||||
| self.fd.close() | ||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.