Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into tr/code_enhancment
Browse files Browse the repository at this point in the history
  • Loading branch information
okotek committed Jul 24, 2023
2 parents 4d84f76 + dd8f6eb commit abca2fd
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pr_agent/git_providers/bitbucket_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, pr_url: Optional[str] = None, incremental: Optional[bool] = F
self.set_pr(pr_url)

def is_supported(self, capability: str) -> bool:
if capability in ['get_issue_comments', 'create_inline_comment', 'publish_inline_comments']:
if capability in ['get_issue_comments', 'create_inline_comment', 'publish_inline_comments', 'get_labels']:
return False
return True

Expand Down
4 changes: 4 additions & 0 deletions pr_agent/git_providers/git_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ def publish_code_suggestions(self, code_suggestions: list):
def publish_labels(self, labels):
pass

@abstractmethod
def get_labels(self):
pass

@abstractmethod
def remove_initial_comment(self):
pass
Expand Down
11 changes: 9 additions & 2 deletions pr_agent/git_providers/github_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,5 +322,12 @@ def publish_labels(self, pr_types):
headers, data = self.pr._requester.requestJsonAndCheck(
"PUT", f"{self.pr.issue_url}/labels", input=post_parameters
)
except:
logging.exception("Failed to publish labels")
except Exception as e:
logging.exception(f"Failed to publish labels, error: {e}")

def get_labels(self):
try:
return [label.name for label in self.pr.labels]
except Exception as e:
logging.exception(f"Failed to get labels, error: {e}")
return []
2 changes: 1 addition & 1 deletion pr_agent/git_providers/gitlab_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, merge_request_url: Optional[str] = None, incremental: Optiona
self.incremental = incremental

def is_supported(self, capability: str) -> bool:
if capability in ['get_issue_comments', 'create_inline_comment', 'publish_inline_comments']:
if capability in ['get_issue_comments', 'create_inline_comment', 'publish_inline_comments', 'get_labels']:
return False
return True

Expand Down
4 changes: 3 additions & 1 deletion pr_agent/tools/pr_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ async def describe(self):
self.git_provider.publish_comment(markdown_text)
else:
self.git_provider.publish_description(pr_title, pr_body)
self.git_provider.publish_labels(pr_types)
if self.git_provider.is_supported("get_labels"):
current_labels = self.git_provider.get_labels()
self.git_provider.publish_labels(pr_types + current_labels)
self.git_provider.remove_initial_comment()
return ""

Expand Down

0 comments on commit abca2fd

Please sign in to comment.