Skip to content

Commit

Permalink
Merge pull request #614 from nikromen/GitlabPullRequest.patch
Browse files Browse the repository at this point in the history
Add GitlabPullRequest.patch property

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.
Implementation for #416

Reviewed-by: Jiri Popelka <None>
Reviewed-by: Matej Focko <None>
  • Loading branch information
softwarefactory-project-zuul[bot] authored Jul 15, 2021
2 parents 9332bf8 + 8baf426 commit 3d2c776
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 3d2c776

Please sign in to comment.