Skip to content

Commit

Permalink
Add GitlabPullRequest.patch property
Browse files Browse the repository at this point in the history
Implementated for GitlabPullRequest.

It returns bytes in case there's some binary blob in the patch.
It uses requests to get content from patch's URL.
  • Loading branch information
nikromen committed Jul 15, 2021
1 parent 9332bf8 commit 8baf426
Show file tree
Hide file tree
Showing 3 changed files with 466 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ogr/services/gitlab/pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# SOFTWARE.

import datetime
import requests
from typing import Dict, List, Optional

from gitlab.v4.objects import MergeRequest as _GitlabMergeRequest
Expand Down Expand Up @@ -106,6 +107,17 @@ def diff_url(self) -> str:
def commits_url(self) -> str:
return f"{self._raw_pr.web_url}/commits"

@property
def patch(self) -> bytes:
response = requests.get(f"{self.url}.patch")

if not response.ok:
raise GitlabAPIException(
f"Couldn't get patch from {self.url}.patch because {response.reason}."
)

return response.content

@property
def head_commit(self) -> str:
return self._raw_pr.sha
Expand Down
Loading

0 comments on commit 8baf426

Please sign in to comment.