Skip to content

Commit 48d162a

Browse files
committed
add migrate-pr.sh script to help migration
1 parent 6e96c69 commit 48d162a

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

tools/absorb-repo/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,20 @@ The above invocation will create one or two commits on the `absorb-worker` branc
1414
- a merge commit that merges the `absorb-worker` branch with the rewritten default branch of `git@github.com:codecov/worker.git`
1515

1616
You can run it multiple times to absorb multiple repositories in a single branch.
17+
18+
### Migrating existing PRs
19+
20+
Pull requests that weren't ready to be merged before the cutover can be migrated to `umbrella` using `migrate-pr.sh`. In order to use it, you need to have `gh` and `jq` installed. The simplest way to get them is with homebrew:
21+
```
22+
# Assuming you already have homebrew
23+
$ brew install gh jq
24+
```
25+
26+
Script usage:
27+
```
28+
./migrate-pr.sh https://github.com/codecov/worker/pull/1300
29+
```
30+
31+
The above invocation will:
32+
- apply the same transformation to the PR's branch that `absorb-repo.sh` does
33+
- create a PR with the same title and body (with a link to the original PR) for the transformed branch

tools/absorb-repo/migrate-pr.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
3+
pull_request=$1
4+
5+
#pr_data=$(gh pr view $pull_request --json title,body,headRefName,headRepositoryOwner,headRepository | jq '.headRepository = .headRepositoryOwner.login + "/" + .headRepository.name | del(.headRepositoryOwner)')
6+
pr_data=$(gh pr view $pull_request --json title,body,headRefName,headRepositoryOwner,headRepository | jq '.headRepositoryOwner = .headRepositoryOwner.login | .headRepository = .headRepository.name')
7+
8+
pr_title=$(echo $pr_data | jq '.title')
9+
pr_body=$(echo $pr_data | jq \""(migrated from $pull_request)\r\n\r\n\""' + .body')
10+
pr_head_repo=$(echo $pr_data | jq -r '.headRepository')
11+
pr_head_repo_owner=$(echo $pr_data | jq -r '.headRepositoryOwner')
12+
pr_head_ref=$(echo $pr_data | jq -r '.headRefName')
13+
14+
# Assumes this script's directory has a sibling directory called `git-filter-repo`
15+
# which contains a copy of the `git-filter-repo` script.
16+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
17+
GIT_FILTER_REPO_DIR="$(realpath "$SCRIPT_DIR/../git-filter-repo")"
18+
19+
current_branch="$(git rev-parse --abbrev-ref HEAD)"
20+
migrated_ref="$pr_head_repo/$pr_head_ref"
21+
22+
case $pr_head_repo in
23+
"worker" | "codecov-api")
24+
subdirectory="apps/$pr_head_repo"
25+
;;
26+
"shared")
27+
subdirectory="libs/$pr_head_repo"
28+
;;
29+
*)
30+
echo "Uh oh"
31+
exit 1
32+
;;
33+
esac
34+
35+
if ! $(git remote | grep $pr_head_repo); then
36+
echo "Adding remote for $pr_head_repo_owner/$pr_head_repo..."
37+
git remote add $pr_head_repo git@github.com:$pr_head_repo_owner/$pr_head_repo
38+
echo "Done"
39+
fi
40+
41+
echo "Checking out $pr_head_repo/$pr_head_ref as $migrated_ref..."
42+
git fetch $pr_head_repo $pr_head_ref
43+
git checkout -b "$migrated_ref" $pr_head_repo/$pr_head_ref
44+
45+
# Going back to the starting branch to run branch mutation
46+
git checkout "$current_branch"
47+
python "$GIT_FILTER_REPO_DIR/git-filter-repo" --force --refs "$migrated_ref" --to-subdirectory-filter "$subdirectory"
48+
49+
# Try to create a PR
50+
git checkout $migrated_ref
51+
gh pr create --title $pr_title --body $pr_body

0 commit comments

Comments
 (0)