Skip to content

Commit

Permalink
Add Contributed backport command (#22643)
Browse files Browse the repository at this point in the history
This PR provides a contributed backport command to help create backports
for Gitea.

It represents a significant improvement on my previously described
shell-script.

It can be installed using `go install contrib/backport/backport.go`.

Signed-off-by: Andrew Thornton <art27@cantab.net>
  • Loading branch information
zeripath authored Jan 31, 2023
1 parent 519939f commit f1f0430
Show file tree
Hide file tree
Showing 3 changed files with 481 additions and 18 deletions.
20 changes: 2 additions & 18 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,26 +267,10 @@ with the rest of the summary matching the original PR. Similarly for frontports

---

The below is a script that may be helpful in creating backports. YMMV.
A command to help create backports can be found in `contrib/backport` and can be installed (from inside the gitea repo root directory) using:

```bash
#!/bin/sh
PR="$1"
SHA="$2"
VERSION="$3"

if [ -z "$SHA" ]; then
SHA=$(gh api /repos/go-gitea/gitea/pulls/$PR -q '.merge_commit_sha')
fi

if [ -z "$VERSION" ]; then
VERSION="v1.16"
fi

echo git checkout origin/release/"$VERSION" -b backport-$PR-$VERSION
git checkout origin/release/"$VERSION" -b backport-$PR-$VERSION
git cherry-pick $SHA && git commit --amend && git push zeripath backport-$PR-$VERSION && xdg-open https://github.com/go-gitea/gitea/compare/release/"$VERSION"...zeripath:backport-$PR-$VERSION

go install contrib/backport/backport.go
```

## Developer Certificate of Origin (DCO)
Expand Down
41 changes: 41 additions & 0 deletions contrib/backport/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
`backport`
==========

`backport` is a command to help create backports of PRs. It backports a
provided PR from main on to a released version.

It will create a backport branch, cherry-pick the PR's merge commit, adjust
the commit message and then push this back up to your fork's remote.

The default version will read from `docs/config.yml`. You can override this
using the option `--version`.

The upstream branches will be fetched, using the remote `origin`. This can
be overrided using `--upstream`, and fetching can be avoided using
`--no-fetch`.

By default the branch created will be called `backport-$PR-$VERSION`. You
can override this using the option `--backport-branch`. This branch will
be created from `--release-branch` which is `release/$(VERSION)`
by default and will be pulled from `$(UPSTREAM)`.

The merge-commit as determined by the github API will be used as the SHA to
cherry-pick. You can override this using `--cherry-pick`.

The commit message will be amended to add the `Backport` header.
`--no-amend-message` can be set to stop this from happening.

If cherry-pick is successful the backported branch will be pushed up to your
fork using your remote. These will be determined using `git remote -v`. You
can set your fork name using `--fork-user` and your remote name using
`--remote`. You can avoid pushing using `--no-push`.

If the push is successful, `xdg-open` will be called to open a backport url.
You can stop this using `--no-xdg-open`.

Installation
============

```bash
go install contrib/backport/backport.go
```
Loading

0 comments on commit f1f0430

Please sign in to comment.