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

Add GitlabPullRequest.patch property #614

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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