Skip to content
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
1 change: 1 addition & 0 deletions COMPATIBILITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ In case you find any error, please [create a new issue](https://github.com/packi
| `add_label` | ✔ | ✔ | ✘ | ✔ |
| `get_all_commits` | ✔ | ✔ | ✘ | ✔ |
| `closed_by` | ✘ | ✘ | ✔ | ✔ |
| `allow_maintainer_edit` | ✔ | ✔ | ✘ | ✔ |

## Release

Expand Down
4 changes: 4 additions & 0 deletions ogr/abstract/git_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ def create_pr(
target_branch: str,
source_branch: str,
fork_username: Optional[str] = None,
allow_maintainer_edit: Optional[bool] = None,
) -> "_abstract.PullRequest":
"""
Create new pull request.
Expand All @@ -477,6 +478,9 @@ def create_pr(
fork_username: The username of forked repository.

Defaults to `None`.
allow_maintainer_edit: Defines whether to allow maintainer edits.

Defaults to `None`.

Returns:
Object that represents newly created pull request.
Expand Down
13 changes: 13 additions & 0 deletions ogr/abstract/pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ def id(self) -> int:
"""ID of the pull request."""
raise NotImplementedError()

@property
def allow_maintainer_edit(self) -> bool:
"""Whether to allow maintainer edits."""
raise NotImplementedError()

@property
def status(self) -> PRStatus:
"""Status of the pull request."""
Expand Down Expand Up @@ -163,6 +168,7 @@ def create(
target_branch: str,
source_branch: str,
fork_username: Optional[str] = None,
allow_maintainer_edit: Optional[bool] = None,
) -> "PullRequest":
"""
Create new pull request.
Expand All @@ -175,6 +181,9 @@ def create(
merged.
source_branch: Branch from which the changes are being pulled.
fork_username: The username/namespace of the forked repository.
allow_maintainer_edit: Defines whether to allow maintainer edits.

Defaults to `None`, which means no explicit setting.

Returns:
Object that represents newly created pull request.
Expand Down Expand Up @@ -218,6 +227,7 @@ def update_info(
self,
title: Optional[str] = None,
description: Optional[str] = None,
allow_maintainer_edit: Optional[bool] = None,
) -> "PullRequest":
"""
Update pull request information.
Expand All @@ -229,6 +239,9 @@ def update_info(
description: The new description of the pull request.

Defaults to `None`, which means no updating.
allow_maintainer_edit: Defines whether to allow maintainer edits.

Defaults to `None`, which means no updating.

Returns:
Pull request itself.
Expand Down
1 change: 1 addition & 0 deletions ogr/services/forgejo/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ def create_pr(
target_branch: str,
source_branch: str,
fork_username: Optional[str] = None,
allow_maintainer_edit: Optional[bool] = None,
) -> "PullRequest":
pass

Expand Down
23 changes: 20 additions & 3 deletions ogr/services/forgejo/pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
from collections.abc import Iterable
from functools import cached_property, partial
from typing import Optional, Union
from typing import Any, Optional, Union

import httpx
from pyforgejo import NotFoundError
Expand All @@ -18,7 +18,7 @@
PRStatus,
PullRequest,
)
from ogr.exceptions import ForgejoAPIException, OgrNetworkError
from ogr.exceptions import ForgejoAPIException, OgrNetworkError, OperationNotSupported
from ogr.services import forgejo
from ogr.services.base import BasePullRequest
from ogr.services.forgejo.comments import ForgejoPRComment
Expand Down Expand Up @@ -61,6 +61,10 @@ def title(self, new_title: str) -> None:
def id(self) -> int:
return self._raw_pr.number

@property
def allow_maintainer_edit(self) -> bool:
return self._raw_pr.allow_maintainer_edit

@property
def status(self) -> PRStatus:
return PRStatus.merged if self._raw_pr.merged else PRStatus[self._raw_pr.state]
Expand Down Expand Up @@ -161,9 +165,18 @@ def create(
target_branch: str,
source_branch: str,
fork_username: Optional[str] = None,
allow_maintainer_edit: Optional[bool] = None,
) -> "PullRequest":
target_project = project

if allow_maintainer_edit is not None:
raise OperationNotSupported(
"Forgejo doesn't support setting allow_maintainer_edit"
" directly as part of the request for creating a PR."
" Create the PR first and then call update_info() to"
" set it.",
)

if project.is_fork and fork_username is None:
# handles fork -> upstream (called on fork)
source_branch = f"{project.namespace}:{source_branch}"
Expand Down Expand Up @@ -233,13 +246,17 @@ def update_info(
self,
title: Optional[str] = None,
description: Optional[str] = None,
allow_maintainer_edit: Optional[bool] = None,
) -> "PullRequest":
try:
data = {"title": title if title else self.title}
data: dict[str, Any] = {"title": title if title else self.title}

if description is not None:
data["body"] = description

if allow_maintainer_edit is not None:
data["allow_maintainer_edit"] = allow_maintainer_edit

updated_pr = self._target_project.api.repo_edit_pull_request(
owner=self.target_project.namespace,
repo=self.target_project.repo,
Expand Down
1 change: 1 addition & 0 deletions ogr/services/github/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ def create_pr(
target_branch: str,
source_branch: str,
fork_username: Optional[str] = None,
allow_maintainer_edit: Optional[bool] = None,
) -> PullRequest:
pass

Expand Down
23 changes: 21 additions & 2 deletions ogr/services/github/pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import datetime
import logging
from collections.abc import Iterable
from typing import Optional, Union
from typing import Any, Optional, Union

import github
import requests
Expand Down Expand Up @@ -42,6 +42,10 @@ def title(self, new_title: str) -> None:
def id(self) -> int:
return self._raw_pr.number

@property
def allow_maintainer_edit(self) -> bool:
return self._raw_pr.maintainer_can_modify

@property
def status(self) -> PRStatus:
return (
Expand Down Expand Up @@ -144,6 +148,7 @@ def create(
target_branch: str,
source_branch: str,
fork_username: Optional[str] = None,
allow_maintainer_edit: Optional[bool] = None,
) -> "PullRequest":
"""
The default behavior is the pull request is made to the immediate parent repository
Expand All @@ -167,11 +172,16 @@ def create(
project.parent.github_repo,
)

kwargs: dict[str, Any] = {}
if allow_maintainer_edit is not None:
kwargs["maintainer_can_modify"] = allow_maintainer_edit

created_pr = github_repo.create_pull(
title=title,
body=body,
base=target_branch,
head=source_branch,
**kwargs,
)
logger.info(f"PR {created_pr.id} created: {target_branch}<-{source_branch}")
return GithubPullRequest(created_pr, target_project)
Expand Down Expand Up @@ -219,9 +229,18 @@ def update_info(
self,
title: Optional[str] = None,
description: Optional[str] = None,
allow_maintainer_edit: Optional[bool] = None,
) -> "PullRequest":
try:
self._raw_pr.edit(title=title, body=description)
kwargs: dict[str, Any] = {}
if title is not None:
kwargs["title"] = title
if description is not None:
kwargs["body"] = description
if allow_maintainer_edit is not None:
kwargs["maintainer_can_modify"] = allow_maintainer_edit

self._raw_pr.edit(**kwargs)
logger.info(f"PR updated: {self._raw_pr.url}")
return self
except Exception as ex:
Expand Down
1 change: 1 addition & 0 deletions ogr/services/gitlab/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ def create_pr(
target_branch: str,
source_branch: str,
fork_username: Optional[str] = None,
allow_maintainer_edit: Optional[bool] = None,
) -> "PullRequest":
pass

Expand Down
15 changes: 13 additions & 2 deletions ogr/services/gitlab/pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import datetime
from collections.abc import Iterable
from typing import ClassVar, Optional
from typing import Any, ClassVar, Optional

import gitlab
import requests
Expand Down Expand Up @@ -43,6 +43,10 @@ def title(self, new_title: str) -> None:
def id(self) -> int:
return self._raw_pr.iid

@property
def allow_maintainer_edit(self) -> bool:
return self._raw_pr.allow_collaboration

@property
def status(self) -> PRStatus:
return (
Expand Down Expand Up @@ -153,6 +157,7 @@ def create(
target_branch: str,
source_branch: str,
fork_username: Optional[str] = None,
allow_maintainer_edit: Optional[bool] = None,
) -> "PullRequest":
"""
How to create PR:
Expand All @@ -163,7 +168,7 @@ def create(
- fork -> other_fork - call on fork, fork_username set to other_fork owner
"""
repo = project.gitlab_repo
parameters = {
parameters: dict[str, Any] = {
"source_branch": source_branch,
"target_branch": target_branch,
"title": title,
Expand Down Expand Up @@ -196,6 +201,9 @@ def create(
if target_id is not None:
parameters["target_project_id"] = target_id

if allow_maintainer_edit is not None:
parameters["allow_collaboration"] = allow_maintainer_edit

mr = repo.mergerequests.create(parameters)
return GitlabPullRequest(mr, target_project)

Expand Down Expand Up @@ -257,11 +265,14 @@ def update_info(
self,
title: Optional[str] = None,
description: Optional[str] = None,
allow_maintainer_edit: Optional[bool] = None,
) -> "PullRequest":
if title:
self._raw_pr.title = title
if description:
self._raw_pr.description = description
if allow_maintainer_edit is not None:
self._raw_pr.allow_collaboration = allow_maintainer_edit

self._raw_pr.save()
return self
Expand Down
1 change: 1 addition & 0 deletions ogr/services/pagure/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ def create_pr(
target_branch: str,
source_branch: str,
fork_username: Optional[str] = None,
allow_maintainer_edit: Optional[bool] = None,
) -> PullRequest:
pass

Expand Down
15 changes: 14 additions & 1 deletion ogr/services/pagure/pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
PRStatus,
PullRequest,
)
from ogr.exceptions import PagureAPIException
from ogr.exceptions import OperationNotSupported, PagureAPIException
from ogr.services import pagure as ogr_pagure
from ogr.services.base import BasePullRequest
from ogr.services.pagure.comments import PagurePRComment
Expand Down Expand Up @@ -165,7 +165,14 @@ def create(
target_branch: str,
source_branch: str,
fork_username: Optional[str] = None,
allow_maintainer_edit: Optional[bool] = None,
) -> "PullRequest":

if allow_maintainer_edit is not None:
raise OperationNotSupported(
"Pagure doesn't support allowing maintainer edits on PRs.",
)

data = {
"title": title,
"branch_to": target_branch,
Expand Down Expand Up @@ -279,7 +286,13 @@ def update_info(
self,
title: Optional[str] = None,
description: Optional[str] = None,
allow_maintainer_edit: Optional[bool] = None,
) -> "PullRequest":
if allow_maintainer_edit is not None:
raise OperationNotSupported(
"Pagure doesn't support allowing maintainer edits on PRs.",
)

try:
data = {"title": title if title else self.title}

Expand Down
Loading
Loading