Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue grantmcconnaughey#58 - Add support for posting review without body
Browse files Browse the repository at this point in the history
bugale committed Jul 11, 2022
1 parent 4ed0329 commit bf00192
Showing 6 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lintly/backends/base.py
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ def get_pr_diff(self, pr):
"""
raise NotImplementedError

def create_pull_request_review(self, pr, patch, all_violations, pr_review_action):
def create_pull_request_review(self, pr, patch, all_violations, pr_review_action, has_body):
"""
Creates a pull request review for the given build.
"""
2 changes: 1 addition & 1 deletion lintly/backends/dummy.py
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ def create_pull_request_comment(self, pr, comment):
def delete_pull_request_comments(self, pr):
pass

def create_pull_request_review(self, pr, patch, all_violations, pr_review_action):
def create_pull_request_review(self, pr, patch, all_violations, pr_review_action, has_body):
pass

def delete_pull_request_review_comments(self, pr):
5 changes: 3 additions & 2 deletions lintly/backends/github.py
Original file line number Diff line number Diff line change
@@ -180,7 +180,7 @@ def _get_event(self, review_action):
elif review_action == ACTION_REVIEW_APPROVE:
return 'APPROVE'

def create_pull_request_review(self, pr, patch, all_violations, pr_review_action):
def create_pull_request_review(self, pr, patch, all_violations, pr_review_action, has_body):
comments = []
for file_path in all_violations:
violations = all_violations[file_path]
@@ -209,10 +209,11 @@ def create_pull_request_review(self, pr, patch, all_violations, pr_review_action
# there are no pending comments to add then we send the request
if len(comments_batch) == GITHUB_PULL_REQUEST_COMMENT_LIMIT or not comments:
data = {
'body': build_pr_review_body(all_violations),
'event': self._get_event(pr_review_action),
'comments': comments_batch,
}
if has_body:
data['body'] = build_pr_review_body(all_violations)

url = '/repos/{owner}/{repo_name}/pulls/{pr_number}/reviews'.format(
owner=self.project.owner_login,
2 changes: 1 addition & 1 deletion lintly/backends/gitlab.py
Original file line number Diff line number Diff line change
@@ -143,7 +143,7 @@ def delete_pull_request_comments(self, pr):
client.delete(url)

@translate_gitlab_exception
def create_pull_request_review(self, pr, patch, all_violations, pr_review_action):
def create_pull_request_review(self, pr, patch, all_violations, pr_review_action, has_body):
raise NotSupportedError()

@translate_gitlab_exception
3 changes: 2 additions & 1 deletion lintly/builds.py
Original file line number Diff line number Diff line change
@@ -164,7 +164,8 @@ def submit_pr_review(self, patch, pr_review_action):
self.config.pr,
patch,
self._diff_violations,
pr_review_action
pr_review_action,
self.config.review_body
)
post_pr_comment = False
except GitClientError as e:
4 changes: 4 additions & 0 deletions lintly/cli.py
Original file line number Diff line number Diff line change
@@ -55,6 +55,10 @@
@click.option('--log',
is_flag=True,
help='Send Lintly debug logs to the console. Default false')
@click.option('--review-body/--no-review-body',
default=True,
help=('Whether Lintly should post a PR review with a body. '
'The body is not removed after a re-run.'))
@click.option('--exit-zero/--no-exit-zero', default=False,
help=('Whether Lintly should exit with error code indicating '
'amount of violations or not. Default false'))

0 comments on commit bf00192

Please sign in to comment.