mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-05 05:10:38 +08:00
Merge pull request #779 from Codium-ai/tr/describe_keep_labels
Update get_pr_labels method to support label updates
This commit is contained in:
@ -165,7 +165,7 @@ class AzureDevopsProvider(GitProvider):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
get_logger().exception(f"Failed to publish labels, error: {e}")
|
get_logger().exception(f"Failed to publish labels, error: {e}")
|
||||||
|
|
||||||
def get_pr_labels(self):
|
def get_pr_labels(self, update=False):
|
||||||
try:
|
try:
|
||||||
labels = self.azure_devops_client.get_pull_request_labels(
|
labels = self.azure_devops_client.get_pull_request_labels(
|
||||||
project=self.workspace_slug,
|
project=self.workspace_slug,
|
||||||
|
@ -404,5 +404,5 @@ class BitbucketProvider(GitProvider):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
# bitbucket does not support labels
|
# bitbucket does not support labels
|
||||||
def get_pr_labels(self):
|
def get_pr_labels(self, update=False):
|
||||||
pass
|
pass
|
||||||
|
@ -347,7 +347,7 @@ class BitbucketServerProvider(GitProvider):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
# bitbucket does not support labels
|
# bitbucket does not support labels
|
||||||
def get_pr_labels(self):
|
def get_pr_labels(self, update=False):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _get_pr_comments_url(self):
|
def _get_pr_comments_url(self):
|
||||||
|
@ -216,7 +216,7 @@ class CodeCommitProvider(GitProvider):
|
|||||||
def publish_labels(self, labels):
|
def publish_labels(self, labels):
|
||||||
return [""] # not implemented yet
|
return [""] # not implemented yet
|
||||||
|
|
||||||
def get_pr_labels(self):
|
def get_pr_labels(self, update=False):
|
||||||
return [""] # not implemented yet
|
return [""] # not implemented yet
|
||||||
|
|
||||||
def remove_initial_comment(self):
|
def remove_initial_comment(self):
|
||||||
|
@ -208,7 +208,7 @@ class GerritProvider(GitProvider):
|
|||||||
Comment = namedtuple('Comment', ['body'])
|
Comment = namedtuple('Comment', ['body'])
|
||||||
return Comments([Comment(c['message']) for c in reversed(comments)])
|
return Comments([Comment(c['message']) for c in reversed(comments)])
|
||||||
|
|
||||||
def get_pr_labels(self):
|
def get_pr_labels(self, update=False):
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
'Getting labels is not implemented for the gerrit provider')
|
'Getting labels is not implemented for the gerrit provider')
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ class GitProvider(ABC):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_pr_labels(self):
|
def get_pr_labels(self, update=False):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_repo_labels(self):
|
def get_repo_labels(self):
|
||||||
|
@ -650,9 +650,16 @@ class GithubProvider(GitProvider):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
get_logger().exception(f"Failed to publish labels, error: {e}")
|
get_logger().exception(f"Failed to publish labels, error: {e}")
|
||||||
|
|
||||||
def get_pr_labels(self):
|
def get_pr_labels(self, update=False):
|
||||||
try:
|
try:
|
||||||
return [label.name for label in self.pr.labels]
|
if not update:
|
||||||
|
labels =self.pr.labels
|
||||||
|
return [label.name for label in labels]
|
||||||
|
else: # obtain the latest labels. Maybe they changed while the AI was running
|
||||||
|
headers, labels = self.pr._requester.requestJsonAndCheck(
|
||||||
|
"GET", f"{self.pr.issue_url}/labels")
|
||||||
|
return [label['name'] for label in labels]
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
get_logger().exception(f"Failed to get labels, error: {e}")
|
get_logger().exception(f"Failed to get labels, error: {e}")
|
||||||
return []
|
return []
|
||||||
|
@ -419,7 +419,7 @@ class GitLabProvider(GitProvider):
|
|||||||
def publish_inline_comments(self, comments: list[dict]):
|
def publish_inline_comments(self, comments: list[dict]):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_pr_labels(self):
|
def get_pr_labels(self, update=False):
|
||||||
return self.mr.labels
|
return self.mr.labels
|
||||||
|
|
||||||
def get_repo_labels(self):
|
def get_repo_labels(self):
|
||||||
|
@ -176,5 +176,5 @@ class LocalGitProvider(GitProvider):
|
|||||||
def get_issue_comments(self):
|
def get_issue_comments(self):
|
||||||
raise NotImplementedError('Getting issue comments is not implemented for the local git provider')
|
raise NotImplementedError('Getting issue comments is not implemented for the local git provider')
|
||||||
|
|
||||||
def get_pr_labels(self):
|
def get_pr_labels(self, update=False):
|
||||||
raise NotImplementedError('Getting labels is not implemented for the local git provider')
|
raise NotImplementedError('Getting labels is not implemented for the local git provider')
|
||||||
|
@ -118,11 +118,15 @@ class PRDescription:
|
|||||||
if get_settings().config.publish_output:
|
if get_settings().config.publish_output:
|
||||||
# publish labels
|
# publish labels
|
||||||
if get_settings().pr_description.publish_labels and self.git_provider.is_supported("get_labels"):
|
if get_settings().pr_description.publish_labels and self.git_provider.is_supported("get_labels"):
|
||||||
original_labels = self.git_provider.get_pr_labels()
|
original_labels = self.git_provider.get_pr_labels(update=True)
|
||||||
get_logger().debug(f"original labels", artifact=original_labels)
|
get_logger().debug(f"original labels", artifact=original_labels)
|
||||||
user_labels = get_user_labels(original_labels)
|
user_labels = get_user_labels(original_labels)
|
||||||
get_logger().debug(f"published labels:\n{pr_labels + user_labels}")
|
new_labels = pr_labels + user_labels
|
||||||
self.git_provider.publish_labels(pr_labels + user_labels)
|
get_logger().debug(f"published labels", artifact=new_labels)
|
||||||
|
if new_labels != original_labels:
|
||||||
|
self.git_provider.publish_labels(new_labels)
|
||||||
|
else:
|
||||||
|
get_logger().debug(f"Labels are the same, not updating")
|
||||||
|
|
||||||
# publish description
|
# publish description
|
||||||
if get_settings().pr_description.publish_description_as_comment:
|
if get_settings().pr_description.publish_description_as_comment:
|
||||||
|
@ -369,17 +369,20 @@ class PRReviewer:
|
|||||||
if security_concerns_bool:
|
if security_concerns_bool:
|
||||||
review_labels.append('Possible security concern')
|
review_labels.append('Possible security concern')
|
||||||
|
|
||||||
current_labels = self.git_provider.get_pr_labels()
|
current_labels = self.git_provider.get_pr_labels(update=True)
|
||||||
|
get_logger().debug(f"Current labels:\n{current_labels}")
|
||||||
if current_labels:
|
if current_labels:
|
||||||
current_labels_filtered = [label for label in current_labels if
|
current_labels_filtered = [label for label in current_labels if
|
||||||
not label.lower().startswith('review effort [1-5]:') and not label.lower().startswith(
|
not label.lower().startswith('review effort [1-5]:') and not label.lower().startswith(
|
||||||
'possible security concern')]
|
'possible security concern')]
|
||||||
else:
|
else:
|
||||||
current_labels_filtered = []
|
current_labels_filtered = []
|
||||||
if current_labels or review_labels:
|
new_labels = review_labels + current_labels_filtered
|
||||||
get_logger().debug(f"Current labels:\n{current_labels}")
|
if (current_labels or review_labels) and new_labels != current_labels:
|
||||||
get_logger().info(f"Setting review labels:\n{review_labels + current_labels_filtered}")
|
get_logger().info(f"Setting review labels:\n{review_labels + current_labels_filtered}")
|
||||||
self.git_provider.publish_labels(review_labels + current_labels_filtered)
|
self.git_provider.publish_labels(new_labels)
|
||||||
|
else:
|
||||||
|
get_logger().info(f"Review labels are already set:\n{review_labels + current_labels_filtered}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
get_logger().error(f"Failed to set review labels, error: {e}")
|
get_logger().error(f"Failed to set review labels, error: {e}")
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user