-
-
Notifications
You must be signed in to change notification settings - Fork 184
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
Use REST API to get comments #467
base: master
Are you sure you want to change the base?
Changes from all commits
5017898
996e38b
5b7280f
303f51a
dca99f4
d480e2a
e84d602
1549e51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4,7 +4,7 @@ | |||||||||
import os | ||||||||||
import re | ||||||||||
from dataclasses import dataclass | ||||||||||
from typing import List, Set, Any, Optional, Tuple, Mapping, Dict, Union, Callable | ||||||||||
from typing import List, Any, Optional, Tuple, Mapping, Dict, Union, Callable | ||||||||||
from copy import deepcopy | ||||||||||
|
||||||||||
from github import Github, GithubException, UnknownObjectException | ||||||||||
|
@@ -656,7 +656,7 @@ def do_stats_require_comment(earlier_stats_require: Optional[bool], stats_requir | |||||||||
|
||||||||||
def get_latest_comment(self, pull: PullRequest) -> Optional[IssueComment]: | ||||||||||
# get comments of this pull request | ||||||||||
comments = self.get_pull_request_comments(pull, order_by_updated=True) | ||||||||||
comments = self.get_pull_request_comments(pull) | ||||||||||
|
||||||||||
# get all comments that come from this action and are not hidden | ||||||||||
comments = self.get_action_comments(comments) | ||||||||||
|
@@ -665,9 +665,8 @@ def get_latest_comment(self, pull: PullRequest) -> Optional[IssueComment]: | |||||||||
if len(comments) == 0: | ||||||||||
return None | ||||||||||
|
||||||||||
# fetch latest action comment | ||||||||||
comment_id = comments[-1].get("databaseId") | ||||||||||
return pull.get_issue_comment(comment_id) | ||||||||||
# return latest action comment | ||||||||||
return sorted(comments, key=lambda comment: comment.updated_at, reverse=True)[-1] | ||||||||||
|
||||||||||
def reuse_comment(self, comment: IssueComment, body: str): | ||||||||||
if ':recycle:' not in body: | ||||||||||
|
@@ -703,41 +702,20 @@ def get_base_commit_sha(self, pull_request: PullRequest) -> Optional[str]: | |||||||||
|
||||||||||
return None | ||||||||||
|
||||||||||
def get_pull_request_comments(self, pull: PullRequest, order_by_updated: bool) -> List[Mapping[str, Any]]: | ||||||||||
order = '' | ||||||||||
if order_by_updated: | ||||||||||
order = ', orderBy: { direction: ASC, field: UPDATED_AT }' | ||||||||||
|
||||||||||
query = dict( | ||||||||||
query=r'query ListComments {' | ||||||||||
r' repository(owner:"' + self._repo.owner.login + r'", name:"' + self._repo.name + r'") {' | ||||||||||
r' pullRequest(number: ' + str(pull.number) + r') {' | ||||||||||
f' comments(last: 100{order}) {{' | ||||||||||
r' nodes {' | ||||||||||
r' id, databaseId, author { login }, body, isMinimized' | ||||||||||
r' }' | ||||||||||
r' }' | ||||||||||
r' }' | ||||||||||
r' }' | ||||||||||
r'}' | ||||||||||
) | ||||||||||
|
||||||||||
headers, data = self._req.requestJsonAndCheck( | ||||||||||
"POST", self._settings.graphql_url, input=query | ||||||||||
) | ||||||||||
|
||||||||||
return data \ | ||||||||||
.get('data', {}) \ | ||||||||||
.get('repository', {}) \ | ||||||||||
.get('pullRequest', {}) \ | ||||||||||
.get('comments', {}) \ | ||||||||||
.get('nodes') | ||||||||||
def get_pull_request_comments(self, pull: PullRequest) -> List[IssueComment]: | ||||||||||
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. E501: line too long (81 > 79 characters) ℹ️ Expand to see all @sonatype-lift commandsYou can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.
Note: When talking to LiftBot, you need to refresh the page to see its response. |
||||||||||
comments = list(pull.get_issue_comments()) | ||||||||||
logger.debug(f'Found {len(comments)} comments for pull request {pull.number}') | ||||||||||
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. E501: line too long (86 > 79 characters) ℹ️ Expand to see all @sonatype-lift commandsYou can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.
Note: When talking to LiftBot, you need to refresh the page to see its response. |
||||||||||
for comment in comments: | ||||||||||
logger.debug(f'comment: {comment}') | ||||||||||
return comments | ||||||||||
|
||||||||||
def get_action_comments(self, comments: List[Mapping[str, Any]], is_minimized: Optional[bool] = False): | ||||||||||
def get_action_comments(self, comments: List[IssueComment]): | ||||||||||
comment_body_start = f'## {self._settings.comment_title}\n' | ||||||||||
comment_body_indicators = ['\nresults for commit ', '\nResults for commit '] | ||||||||||
for comment in comments: | ||||||||||
logger.debug(f'login={comment.user.login}') | ||||||||||
logger.debug(f'body={comment.body}') | ||||||||||
return list([comment for comment in comments | ||||||||||
if comment.get('author', {}).get('login') == self._settings.actor | ||||||||||
and (is_minimized is None or comment.get('isMinimized') == is_minimized) | ||||||||||
and comment.get('body', '').startswith(comment_body_start) | ||||||||||
and any(indicator in comment.get('body', '') for indicator in comment_body_indicators)]) | ||||||||||
if comment.user.login == self._settings.actor | ||||||||||
and comment.body.startswith(comment_body_start) | ||||||||||
and any(indicator in comment.body for indicator in comment_body_indicators)]) |
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.
E501: line too long (89 > 79 characters)
ℹ️ Expand to see all @sonatype-lift commands
You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.
@sonatype-lift ignore
@sonatype-lift ignoreall
@sonatype-lift exclude <file|issue|path|tool>
file|issue|path|tool
from Lift findings by updating your config.toml fileNote: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.