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
4 changes: 4 additions & 0 deletions docs/source/actions/backport.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ Options
- ``true``
- Whether to create the pull requests even if they are conflicts when
cherry-picking the commits.
* - ``labels``
- list of string
- ``[]``
- The list of labels to add to the created pull requests.
* - ``label_conflicts``
- string
- ``conflicts``
Expand Down
4 changes: 4 additions & 0 deletions docs/source/actions/copy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ Options
- ``true``
- Whether to create the pull requests even if they are conflicts when
cherry-picking the commits.
* - ``labels``
- list of string
- ``[]``
- The list of labels to add to the created pull requests.
* - ``label_conflicts``
- string
- ``conflicts``
Expand Down
2 changes: 2 additions & 0 deletions mergify_engine/actions/copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class CopyAction(actions.Action):
voluptuous.Required("branches", default=[]): [str],
voluptuous.Required("regexes", default=[]): [voluptuous.Coerce(Regex)],
voluptuous.Required("ignore_conflicts", default=True): bool,
voluptuous.Required("labels", default=[]): [str],
voluptuous.Required("label_conflicts", default="conflicts"): str,
}

Expand Down Expand Up @@ -77,6 +78,7 @@ async def _copy(self, ctxt, branch_name):
new_pull = await duplicate_pull.duplicate(
ctxt,
branch_name,
self.config["labels"],
self.config["label_conflicts"],
self.config["ignore_conflicts"],
self.KIND,
Expand Down
12 changes: 11 additions & 1 deletion mergify_engine/duplicate_pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import dataclasses
import functools
import typing
from typing import List

import tenacity

Expand Down Expand Up @@ -211,6 +212,7 @@ def get_destination_branch_name(
async def duplicate(
ctxt: context.Context,
branch_name: str,
labels: typing.Optional[List[str]] = None,
label_conflicts: typing.Optional[str] = None,
ignore_conflicts: bool = False,
kind: KindT = "backport",
Expand All @@ -220,6 +222,7 @@ async def duplicate(
:param pull: The pull request.
:type pull: py:class:mergify_engine.context.Context
:param branch: The branch to copy to.
:param labels: The list of labels to add to the created PR.
:param label_conflicts: The label to add to the created PR when cherry-pick failed.
:param ignore_conflicts: Whether to commit the result if the cherry-pick fails.
:param kind: is a backport or a copy
Expand Down Expand Up @@ -333,10 +336,17 @@ async def duplicate(
raise DuplicateNotNeeded(e.message)
raise

effective_labels = []
if labels is not None:
effective_labels.extend(labels)

if cherry_pick_fail and label_conflicts is not None:
effective_labels.append(label_conflicts)

if len(effective_labels) > 0:
await ctxt.client.post(
f"{ctxt.base_url}/issues/{duplicate_pr['number']}/labels",
json={"labels": [label_conflicts]},
json={"labels": effective_labels},
)

return duplicate_pr
18 changes: 15 additions & 3 deletions mergify_engine/tests/functional/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ async def test_backport_no_branch(self):
== checks[0]["output"]["summary"]
)

async def _do_backport_conflicts(self, ignore_conflicts):
async def _do_backport_conflicts(self, ignore_conflicts, labels=None):
stable_branch = self.get_full_branch_name("stable/#3.1")
rules = {
"pull_request_rules": [
Expand All @@ -242,6 +242,8 @@ async def _do_backport_conflicts(self, ignore_conflicts):
},
]
}
if labels is not None:
rules["pull_request_rules"][1]["actions"]["backport"]["labels"] = labels

await self.setup_repo(yaml.dump(rules), test_branches=[stable_branch])

Expand Down Expand Up @@ -310,7 +312,7 @@ async def test_backport_conflicts(self):

async def test_backport_ignore_conflicts(self):
stable_branch = self.get_full_branch_name("stable/#3.1")
p, checks = await self._do_backport_conflicts(True)
p, checks = await self._do_backport_conflicts(True, ["backported"])

pull = (await self.get_pulls(base=stable_branch))[0]

Expand All @@ -325,7 +327,10 @@ async def test_backport_ignore_conflicts(self):
)
== checks[0]["output"]["summary"]
)
assert [label["name"] for label in pull["labels"]] == ["conflicts"]
assert sorted(label["name"] for label in pull["labels"]) == [
"backported",
"conflicts",
]

async def _do_test_backport(self, method, config=None):
stable_branch = self.get_full_branch_name("stable/#3.1")
Expand Down Expand Up @@ -403,6 +408,13 @@ async def _do_test_backport(self, method, config=None):
assert [f"refs/heads/mergify/bp/{stable_branch}/pr-{p['number']}"] == refs
return await self.get_pull(pulls[0]["number"])

async def test_backport_with_labels(self):
stable_branch = self.get_full_branch_name("stable/#3.1")
p = await self._do_test_backport(
"merge", config={"branches": [stable_branch], "labels": ["backported"]}
)
assert [label["name"] for label in p["labels"]] == ["backported"]

async def test_backport_merge_commit(self):
p = await self._do_test_backport("merge")
assert 2 == p["commits"]
Expand Down
1 change: 1 addition & 0 deletions mergify_engine/tests/unit/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ def test_command_loader():
"branches": ["branch-3.1", "branch-3.2"],
"regexes": [],
"ignore_conflicts": True,
"labels": [],
"label_conflicts": "conflicts",
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20210402100024
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"args": ["init"], "kwargs": {}, "out": "hint: Using 'master' as the name for the initial branch. This default branch name\nhint: is subject to change. To configure the initial branch name to use in all\nhint: of your new repositories, which will suppress this warning, call:\nhint: \nhint: \tgit config --global init.defaultBranch <name>\nhint: \nhint: Names commonly chosen instead of 'master' are 'main', 'trunk' and\nhint: 'development'. The just-created branch can be renamed via this command:\nhint: \nhint: \tgit branch -m <name>\nInitialized empty Git repository in /tmp/mergify-gitter7ku4bvt6/.git/\n"}, {"args": ["config", "user.name", "mergify-bot"], "kwargs": {}, "out": ""}, {"args": ["config", "user.email", "noreply@mergify.io"], "kwargs": {}, "out": ""}, {"args": ["config", "credential.useHttpPath", "true"], "kwargs": {}, "out": ""}, {"args": ["config", "credential.helper", "cache --timeout=300 --socket=/tmp/mergify-gitter<random>/.git/creds/socket"], "kwargs": {}, "out": ""}, {"args": ["credential", "approve"], "kwargs": {"_input": "url=https://<TOKEN>:@github.com/mergifyio-testing/functional-testing-repo\n\n"}, "out": ""}, {"args": ["credential", "approve"], "kwargs": {"_input": "url=https://<TOKEN>:@github.com/mergify-test2/functional-testing-repo\n\n"}, "out": ""}, {"args": ["config", "user.name", "mergify-tester"], "kwargs": {}, "out": ""}, {"args": ["remote", "add", "main", "https://github.com/mergifyio-testing/functional-testing-repo"], "kwargs": {}, "out": ""}, {"args": ["remote", "add", "fork", "https://github.com/mergify-test2/functional-testing-repo"], "kwargs": {}, "out": ""}, {"args": ["add", ".mergify.yml"], "kwargs": {}, "out": ""}, {"args": ["commit", "--no-edit", "-m", "initial commit"], "kwargs": {}, "out": "[master (root-commit) 7f3f159] initial commit\n 1 file changed, 19 insertions(+)\n create mode 100644 .mergify.yml\n"}, {"args": ["branch", "-M", "20210402100024/test_backport_with_labels/master"], "kwargs": {}, "out": ""}, {"args": ["branch", "20210402100024/test_backport_with_labels/stable/#3.1", "20210402100024/test_backport_with_labels/master"], "kwargs": {}, "out": ""}, {"args": ["push", "--quiet", "main", "20210402100024/test_backport_with_labels/master", "20210402100024/test_backport_with_labels/stable/#3.1"], "kwargs": {}, "out": ""}, {"args": ["push", "--quiet", "fork", "20210402100024/test_backport_with_labels/master", "20210402100024/test_backport_with_labels/stable/#3.1"], "kwargs": {}, "out": ""}, {"args": ["checkout", "--quiet", "fork/20210402100024/test_backport_with_labels/master", "-b", "20210402100024/test_backport_with_labels/fork/pr1"], "kwargs": {}, "out": ""}, {"args": ["add", "test1"], "kwargs": {}, "out": ""}, {"args": ["commit", "--no-edit", "-m", "test_backport_with_labels: pull request n1 from fork"], "kwargs": {}, "out": "[20210402100024/test_backport_with_labels/fork/pr1 be2026b] test_backport_with_labels: pull request n1 from fork\n 1 file changed, 0 insertions(+), 0 deletions(-)\n create mode 100644 test1\n"}, {"args": ["mv", "test1", "test1-moved"], "kwargs": {}, "out": ""}, {"args": ["commit", "--no-edit", "-m", "test_backport_with_labels: pull request n1 from fork, moved"], "kwargs": {}, "out": "[20210402100024/test_backport_with_labels/fork/pr1 94c4007] test_backport_with_labels: pull request n1 from fork, moved\n 1 file changed, 0 insertions(+), 0 deletions(-)\n rename test1 => test1-moved (100%)\n"}, {"args": ["push", "--quiet", "fork", "20210402100024/test_backport_with_labels/fork/pr1"], "kwargs": {}, "out": "remote: \nremote: Create a pull request for '20210402100024/test_backport_with_labels/fork/pr1' on GitHub by visiting: \nremote: https://github.com/mergify-test2/functional-testing-repo/pull/new/20210402100024/test_backport_with_labels/fork/pr1 \nremote: \n"}, {"args": ["checkout", "--quiet", "fork/20210402100024/test_backport_with_labels/stable/#3.1", "-b", "20210402100024/test_backport_with_labels/fork/pr2"], "kwargs": {}, "out": ""}, {"args": ["add", "test2"], "kwargs": {}, "out": ""}, {"args": ["commit", "--no-edit", "-m", "test_backport_with_labels: pull request n2 from fork"], "kwargs": {}, "out": "[20210402100024/test_backport_with_labels/fork/pr2 74c2d60] test_backport_with_labels: pull request n2 from fork\n 1 file changed, 0 insertions(+), 0 deletions(-)\n create mode 100644 test2\n"}, {"args": ["push", "--quiet", "fork", "20210402100024/test_backport_with_labels/fork/pr2"], "kwargs": {}, "out": "remote: \nremote: Create a pull request for '20210402100024/test_backport_with_labels/fork/pr2' on GitHub by visiting: \nremote: https://github.com/mergify-test2/functional-testing-repo/pull/new/20210402100024/test_backport_with_labels/fork/pr2 \nremote: \n"}, {"args": ["credential-cache", "--socket=/tmp/mergify-gitter<random>/.git/creds/socket", "exit"], "kwargs": {}, "out": ""}]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"args": ["init"], "kwargs": {}, "out": "hint: Using 'master' as the name for the initial branch. This default branch name\nhint: is subject to change. To configure the initial branch name to use in all\nhint: of your new repositories, which will suppress this warning, call:\nhint: \nhint: \tgit config --global init.defaultBranch <name>\nhint: \nhint: Names commonly chosen instead of 'master' are 'main', 'trunk' and\nhint: 'development'. The just-created branch can be renamed via this command:\nhint: \nhint: \tgit branch -m <name>\nInitialized empty Git repository in /tmp/mergify-gittermzcijr2t/.git/\n"}, {"args": ["config", "user.name", "mergify-bot"], "kwargs": {}, "out": ""}, {"args": ["config", "user.email", "noreply@mergify.io"], "kwargs": {}, "out": ""}, {"args": ["config", "credential.useHttpPath", "true"], "kwargs": {}, "out": ""}, {"args": ["config", "credential.helper", "cache --timeout=300 --socket=/tmp/mergify-gitter<random>/.git/creds/socket"], "kwargs": {}, "out": ""}, {"args": ["credential", "approve"], "kwargs": {"_input": "url=https://<TOKEN>:@github.com/mergifyio-testing/functional-testing-repo\n\n"}, "out": ""}, {"args": ["remote", "add", "origin", "https://github.com/mergifyio-testing/functional-testing-repo"], "kwargs": {}, "out": ""}, {"args": ["fetch", "--quiet", "origin", "pull/10242/head"], "kwargs": {}, "out": ""}, {"args": ["fetch", "--quiet", "origin", "20210402100024/test_backport_with_labels/master"], "kwargs": {}, "out": ""}, {"args": ["fetch", "--quiet", "origin", "20210402100024/test_backport_with_labels/stable/#3.1"], "kwargs": {}, "out": ""}, {"args": ["checkout", "--quiet", "-b", "mergify/bp/20210402100024/test_backport_with_labels/stable/#3.1/pr-10242", "origin/20210402100024/test_backport_with_labels/stable/#3.1"], "kwargs": {}, "out": ""}, {"args": ["cherry-pick", "-x", "be2026b0852335994e33a23d0ac84f2ad4db8795"], "kwargs": {}, "out": "[mergify/bp/20210402100024/test_backport_with_labels/stable/#3.1/pr-10242 1c1ea86] test_backport_with_labels: pull request n1 from fork\n Author: mergify-tester <noreply@mergify.io>\n Date: Fri Apr 2 12:00:31 2021 +0200\n 1 file changed, 0 insertions(+), 0 deletions(-)\n create mode 100644 test1\n"}, {"args": ["cherry-pick", "-x", "94c40074ad0916af99013cf0e6e4d1db5f33caf1"], "kwargs": {}, "out": "Removing test1\n[mergify/bp/20210402100024/test_backport_with_labels/stable/#3.1/pr-10242 9062dab] test_backport_with_labels: pull request n1 from fork, moved\n Author: mergify-tester <noreply@mergify.io>\n Date: Fri Apr 2 12:00:31 2021 +0200\n 1 file changed, 0 insertions(+), 0 deletions(-)\n rename test1 => test1-moved (100%)\n"}, {"args": ["push", "origin", "mergify/bp/20210402100024/test_backport_with_labels/stable/#3.1/pr-10242"], "kwargs": {}, "out": "remote: \nremote: Create a pull request for 'mergify/bp/20210402100024/test_backport_with_labels/stable/#3.1/pr-10242' on GitHub by visiting: \nremote: https://github.com/mergifyio-testing/functional-testing-repo/pull/new/mergify/bp/20210402100024/test_backport_with_labels/stable/%233.1/pr-10242 \nremote: \nTo https://github.com/mergifyio-testing/functional-testing-repo\n * [new branch] mergify/bp/20210402100024/test_backport_with_labels/stable/#3.1/pr-10242 -> mergify/bp/20210402100024/test_backport_with_labels/stable/#3.1/pr-10242\n"}, {"args": ["credential-cache", "--socket=/tmp/mergify-gitter<random>/.git/creds/socket", "exit"], "kwargs": {}, "out": ""}]
Loading