Skip to content
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

feat: Add repository labels retrieval function in gitlab_provider.py #524

Merged
merged 1 commit into from
Dec 13, 2023

Conversation

hussam789
Copy link
Collaborator

No description provided.

Copy link
Contributor

PR Analysis

  • 🎯 Main theme: Adding a function to retrieve repository labels in GitLab provider
  • 📝 PR summary: This PR introduces a new function get_repo_labels in the gitlab_provider.py file. The function retrieves the labels of a repository in GitLab.
  • 📌 Type of PR: Enhancement
  • 🧪 Relevant tests added: No
  • ⏱️ Estimated effort to review [1-5]: 1, because the PR is small and straightforward, adding a single function to an existing class.
  • 🔒 Security concerns: No security concerns found

PR Feedback

  • 💡 General suggestions: The PR is concise and clear, focusing on a single enhancement. However, it would be beneficial to include tests for the new function to ensure it works as expected.

  • 🤖 Code feedback:
    relevant filepr_agent/git_providers/gitlab_provider.py
    suggestion      Consider handling potential exceptions that might be raised when trying to access the project or its labels. This could be done using a try/except block. [important]
    relevant linereturn self.gl.projects.get(self.id_project).labels.list()

How to use

Instructions

To invoke the PR-Agent, add a comment using one of the following commands:
/review: Request a review of your Pull Request.
/describe: Update the PR title and description based on the contents of the PR.
/improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
/ask <QUESTION>: Ask a question about the PR.
/update_changelog: Update the changelog based on the PR's contents.
/add_docs: Generate docstring for new components introduced in the PR.
/generate_labels: Generate labels for the PR based on the PR's contents.
see the tools guide for more details.

To edit any configuration parameter from the configuration.toml, add --config_path=new_value.
For example: /review --pr_reviewer.extra_instructions="focus on the file: ..."
To list the possible configuration parameters, add a /config comment.

Copy link
Contributor

PR Code Suggestions

💡 Suggestion:

Consider handling potential exceptions when retrieving repository labels.

File: pr_agent/git_providers/gitlab_provider.py (414-415)

Example code:

Existing code:

def get_repo_labels(self):
    return self.gl.projects.get(self.id_project).labels.list()

Improved code:

def get_repo_labels(self):
    try:
        return self.gl.projects.get(self.id_project).labels.list()
    except Exception as e:
        print(f"Error retrieving repository labels: {e}")
        return None

💡 Suggestion:

Consider caching the result of the get call to avoid multiple network requests.

File: pr_agent/git_providers/gitlab_provider.py (414-415)

Example code:

Existing code:

def get_repo_labels(self):
    return self.gl.projects.get(self.id_project).labels.list()

Improved code:

def get_repo_labels(self):
    if not hasattr(self, '_repo_labels'):
        self._repo_labels = self.gl.projects.get(self.id_project).labels.list()
    return self._repo_labels

💡 Suggestion:

Consider returning an empty list instead of None when there are no labels.

File: pr_agent/git_providers/gitlab_provider.py (414-415)

Example code:

Existing code:

def get_repo_labels(self):
    return self.gl.projects.get(self.id_project).labels.list()

Improved code:

def get_repo_labels(self):
    labels = self.gl.projects.get(self.id_project).labels.list()
    return labels if labels else []

@hussam789 hussam789 merged commit 2a8c2e4 into main Dec 13, 2023
3 checks passed
@hussam789 hussam789 deleted the hl/native_labels_gitlab branch December 13, 2023 15:36
yochail pushed a commit to yochail/pr-agent that referenced this pull request Feb 11, 2024
feat: Add repository labels retrieval function in gitlab_provider.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants