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

Commit

Permalink
Issue grantmcconnaughey#58 - Add support for posting review without body
Browse files Browse the repository at this point in the history
  • Loading branch information
bugale committed Jul 11, 2022
1 parent 5a2c5dd commit 6fd3ab6
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lintly/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
2 changes: 1 addition & 1 deletion lintly/backends/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions lintly/backends/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lintly/backends/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lintly/builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions lintly/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
4 changes: 4 additions & 0 deletions lintly/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ def post_status(self):
def request_changes(self):
return self.cli_config['request_changes']

@property
def review_body(self):
return self.cli_config['review_body']

@property
def github_check_run_id(self):
"""The Check Run ID from GitHub Actions.
Expand Down

0 comments on commit 6fd3ab6

Please sign in to comment.