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

Support using the merge ref instead of the head ref in a pull request #601

Merged
merged 3 commits into from
Jul 12, 2021
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ check:
PYTHONPATH=$(CURDIR) PYTHONDONTWRITEBYTECODE=1 pytest --verbose --showlocals $(TEST_TARGET)

check-in-container:
podman run --rm -it -v $(CURDIR):/src:Z -w /src $(OGR_IMAGE) make check
podman run --rm -it -v $(CURDIR):/src:Z -w /src $(OGR_IMAGE) make -e GITHUB_TOKEN=$(GITHUB_TOKEN) GITLAB_TOKEN=$(GITLAB_TOKEN) check

shell:
podman run --rm -ti -v $(CURDIR):/src:Z -w /src $(OGR_IMAGE) bash
Expand Down
34 changes: 25 additions & 9 deletions ogr/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,23 @@ class PRStatus(IntEnum):
all = 4


class CommitStatus(Enum):
pending = 1
success = 2
failure = 3
error = 4
canceled = 5
running = 6


class MergeCommitStatus(Enum):
can_be_merged = 1
cannot_be_merged = 2
unchecked = 3
checking = 4
cannot_be_merged_recheck = 5


class PullRequest(OgrAbstractClass):
@deprecate_and_set_removal(
since="0.9.0",
Expand Down Expand Up @@ -404,6 +421,14 @@ def patch(self) -> bytes:
def head_commit(self) -> str:
raise NotImplementedError

@property
def merge_commit_sha(self) -> str:
raise NotImplementedError()

@property
def merge_commit_status(self) -> MergeCommitStatus:
raise NotImplementedError()

@property
def source_project(self) -> "GitProject":
raise NotImplementedError()
Expand Down Expand Up @@ -588,15 +613,6 @@ def get_statuses(self) -> List["CommitFlag"]:
raise NotImplementedError()


class CommitStatus(Enum):
pending = 1
success = 2
failure = 3
error = 4
canceled = 5
running = 6


class CommitFlag(OgrAbstractClass):
_states: Dict[str, CommitStatus] = dict()

Expand Down
13 changes: 12 additions & 1 deletion ogr/services/github/pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from github.IssueComment import IssueComment as _GithubIssueComment
from github.PullRequestComment import PullRequestComment as _GithubPullRequestComment

from ogr.abstract import PRComment, PRStatus, PullRequest
from ogr.abstract import PRComment, PRStatus, PullRequest, MergeCommitStatus
from ogr.exceptions import GithubAPIException
from ogr.services import github as ogr_github
from ogr.services.base import BasePullRequest
Expand Down Expand Up @@ -109,6 +109,17 @@ def commits_url(self) -> str:
def head_commit(self) -> str:
return self._raw_pr.head.sha

@property
def merge_commit_sha(self) -> str:
return self._raw_pr.merge_commit_sha

@property
def merge_commit_status(self) -> MergeCommitStatus:
if self._raw_pr.mergeable:
return MergeCommitStatus.can_be_merged
else:
return MergeCommitStatus.cannot_be_merged

@property
def source_project(self) -> "ogr_github.GithubProject":
if self._source_project is None:
Expand Down
23 changes: 21 additions & 2 deletions ogr/services/gitlab/pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
# SOFTWARE.

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

from gitlab.v4.objects import MergeRequest as _GitlabMergeRequest

from ogr.abstract import PullRequest, PRComment, PRStatus
from ogr.abstract import PullRequest, PRComment, PRStatus, MergeCommitStatus
from ogr.exceptions import GitlabAPIException
from ogr.services import gitlab as ogr_gitlab
from ogr.services.base import BasePullRequest
Expand All @@ -36,6 +36,13 @@ class GitlabPullRequest(BasePullRequest):
_raw_pr: _GitlabMergeRequest
_target_project: "ogr_gitlab.GitlabProject"
_source_project: "ogr_gitlab.GitlabProject" = None
_merge_commit_status: Dict[str, MergeCommitStatus] = {
"can_be_merged": MergeCommitStatus.can_be_merged,
"cannot_be_merged": MergeCommitStatus.cannot_be_merged,
"unchecked": MergeCommitStatus.unchecked,
"checking": MergeCommitStatus.checking,
"cannot_be_merged_recheck": MergeCommitStatus.cannot_be_merged_recheck,
}

@property
def title(self) -> str:
Expand Down Expand Up @@ -103,6 +110,18 @@ def commits_url(self) -> str:
def head_commit(self) -> str:
return self._raw_pr.sha

@property
def merge_commit_sha(self) -> str:
return self._raw_pr.merge_commit_sha

@property
def merge_commit_status(self) -> MergeCommitStatus:
status = self._raw_pr.merge_status
if status in self._merge_commit_status:
return self._merge_commit_status[status]
else:
raise GitlabAPIException(f"Invalid merge_status {status}")

@property
def source_project(self) -> "ogr_gitlab.GitlabProject":
if self._source_project is None:
Expand Down
Loading