From 8b8b3e6a20ba902d7b3695286131519958e9a0d5 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jan 06 2021 16:07:48 +0000 Subject: Allow updating the target branch when editing a PR With this commit we will be able to update a PR to change its target branch in cases that branch disappears. For example, you have a PR opened against the "master" branch but the project decides to change its default branch to "main" and delete the "master" branch to avoid confusion. Now, the PR that was opened against "master" will error saying it cannot find the target branch for the PR (and the diff of the PR will thus be empty). With this commit, one will be able to edit the PR and change the target branch from "master" to "main", thus allowing the review to continue. Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/forms.py b/pagure/forms.py index a7ff9d9..458a74a 100644 --- a/pagure/forms.py +++ b/pagure/forms.py @@ -330,6 +330,28 @@ class RequestPullForm(PagureForm): ) +class RequestPullEditForm(RequestPullForm): + """ Form to edit a pull request. """ + + branch_to = wtforms.SelectField( + "Target branch", + [wtforms.validators.Required()], + choices=[], + coerce=convert_value, + ) + + def __init__(self, *args, **kwargs): + """Calls the default constructor with the normal argument but + uses the list of collection provided to fill the choices of the + drop-down list. + """ + super(RequestPullEditForm, self).__init__(*args, **kwargs) + if "branches" in kwargs: + self.branch_to.choices = [ + (branch, branch) for branch in kwargs["branches"] + ] + + class RemoteRequestPullForm(RequestPullForm): """ Form to create a remote pull request. """ diff --git a/pagure/templates/pull_request_title.html b/pagure/templates/pull_request_title.html index ecbfce7..817b77a 100644 --- a/pagure/templates/pull_request_title.html +++ b/pagure/templates/pull_request_title.html @@ -51,6 +51,9 @@
+ {{ render_bootstrap_field( + form.branch_to, + field_description="branch in which the pull-request should be merged") }}