Skip to content

Commit

Permalink
updates gitlab to handle changes to their API
Browse files Browse the repository at this point in the history
  • Loading branch information
apoclyps committed Feb 6, 2022
1 parent 026864b commit 280630f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions reviews/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Dict, List, Tuple, Union

from github.PullRequest import PullRequest as ghPullRequest
from gitlab.v4.objects.merge_requests import MergeRequest as GitlabMergeRequest
from gitlab.v4.objects import ProjectMergeRequest as GitlabMergeRequest
from rich.console import Group
from rich.panel import Panel
from rich.table import Table
Expand Down Expand Up @@ -146,8 +146,9 @@ def update_pull_requests(self, project_id: str, namespace: str) -> List[PullRequ
def _get_reviews(pull_request: GitlabMergeRequest) -> Dict[str, str]:
"""Inner function to retrieve reviews for a pull request"""
reviews = pull_request.approvals.get()
approvers = getattr(reviews, "approvers", [])

return {reviewer["user"]["username"]: "approved" for reviewer in reviews.approvers}
return {approver["user"]["username"]: "approved" for approver in approvers} if approvers else {}

# ProjectMergeRequest
pull_requests = self.client.get_pull_requests(project_id=project_id, namespace=namespace)
Expand Down
4 changes: 2 additions & 2 deletions reviews/source_control/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from github.PullRequest import PullRequest
from github.Repository import Repository
from gitlab import Gitlab
from gitlab.v4.objects.merge_requests import MergeRequest as GitlabMergeRequest
from gitlab.v4.objects import ProjectMergeRequest as GitlabMergeRequest
from gitlab.v4.objects.projects import Project as GitlabRepository

from .. import config
Expand Down Expand Up @@ -71,4 +71,4 @@ def _get_pull_requests(
def get_pull_requests(self, project_id: str, namespace: str) -> List[GitlabMergeRequest]:
"""Returns a list of pull requests for a given organization and repository."""
repository = self.get_repository(project_id=project_id, namespace=namespace) # type: ignore
return repository.mergerequests.get(id=project_id, state="opened", order_by="created_at", sort="asc") # type: ignore
return repository.mergerequests.list(state="opened", order_by="created_at", sort="asc") # type: ignore

0 comments on commit 280630f

Please sign in to comment.