-
-
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 5 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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -12,10 +12,10 @@ LABEL com.github.actions.color="green" | |||||||||
RUN apk add --no-cache --upgrade expat libuuid | ||||||||||
|
||||||||||
COPY python/requirements.txt /action/ | ||||||||||
RUN apk add --no-cache build-base libffi-dev; \ | ||||||||||
RUN apk add --no-cache build-base libffi-dev git; \ | ||||||||||
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. DL3018: Pin versions in apk add. Instead of ℹ️ 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. |
||||||||||
pip install --upgrade --force --no-cache-dir pip && \ | ||||||||||
pip install --upgrade --force --no-cache-dir -r /action/requirements.txt; \ | ||||||||||
apk del build-base libffi-dev | ||||||||||
apk del build-base libffi-dev git | ||||||||||
|
||||||||||
COPY python/publish /action/publish | ||||||||||
COPY python/publish_test_results.py /action/ | ||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4,13 +4,14 @@ | |||||||||||||||||
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 | ||||||||||||||||||
from github.CheckRun import CheckRun | ||||||||||||||||||
from github.CheckRunAnnotation import CheckRunAnnotation | ||||||||||||||||||
from github.PullRequest import PullRequest | ||||||||||||||||||
from github.PullRequestComment import PullRequestComment | ||||||||||||||||||
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. E0401: Unable to import 'github.PullRequestComment' ℹ️ 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. 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. reportMissingImports: Import "github.PullRequestComment" could not be resolved ℹ️ 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. |
||||||||||||||||||
from github.IssueComment import 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. F401: 'github.IssueComment.IssueComment' imported but unused ℹ️ 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. 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. vulture-90: unused import 'IssueComment' ℹ️ 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. |
||||||||||||||||||
|
||||||||||||||||||
from publish import __version__, comment_mode_off, digest_prefix, restrict_unicode_list, \ | ||||||||||||||||||
|
@@ -654,7 +655,7 @@ def do_stats_require_comment(earlier_stats_require: Optional[bool], stats_requir | |||||||||||||||||
|
||||||||||||||||||
return False | ||||||||||||||||||
|
||||||||||||||||||
def get_latest_comment(self, pull: PullRequest) -> Optional[IssueComment]: | ||||||||||||||||||
def get_latest_comment(self, pull: PullRequest) -> Optional[PullRequestComment]: | ||||||||||||||||||
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 (84 > 79 characters) ❗❗ 2 similar findings have been found in this PR 🔎 Expand here to view all instances of this finding
Visit the Lift Web Console to find more details in your report. ℹ️ 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. |
||||||||||||||||||
# get comments of this pull request | ||||||||||||||||||
comments = self.get_pull_request_comments(pull, order_by_updated=True) | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -665,11 +666,10 @@ 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 comments[-1] | ||||||||||||||||||
|
||||||||||||||||||
def reuse_comment(self, comment: IssueComment, body: str): | ||||||||||||||||||
def reuse_comment(self, comment: PullRequestComment, body: str): | ||||||||||||||||||
if ':recycle:' not in body: | ||||||||||||||||||
body = f'{body}\n:recycle: This comment has been updated with latest results.' | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -703,41 +703,16 @@ 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 = '' | ||||||||||||||||||
def get_pull_request_comments(self, pull: PullRequest, order_by_updated: bool) -> List[PullRequestComment]: | ||||||||||||||||||
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') | ||||||||||||||||||
return list(pull.get_comments(sort="updated_at", direction="asc")) | ||||||||||||||||||
else: | ||||||||||||||||||
return list(pull.get_comments()) | ||||||||||||||||||
|
||||||||||||||||||
def get_action_comments(self, comments: List[Mapping[str, Any]], is_minimized: Optional[bool] = False): | ||||||||||||||||||
def get_action_comments(self, comments: List[PullRequestComment]): | ||||||||||||||||||
comment_body_start = f'## {self._settings.comment_title}\n' | ||||||||||||||||||
comment_body_indicators = ['\nresults for commit ', '\nResults for commit '] | ||||||||||||||||||
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.
DL3013: Pin versions in pip. Instead of
pip install <package>
usepip install <package>==<version>
orpip install --requirement <requirements file>
ℹ️ 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.