From 2a1c6ae784799193e7071dde8a324abd2b43bb42 Mon Sep 17 00:00:00 2001 From: Matt Hammerly Date: Tue, 15 Apr 2025 13:21:47 -0700 Subject: [PATCH 1/3] dummy commit to test a pr migration script --- apps/worker/tasks/base.py | 4 ++++ apps/worker/tasks/upload.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/apps/worker/tasks/base.py b/apps/worker/tasks/base.py index 08d64a9375..4678235995 100644 --- a/apps/worker/tasks/base.py +++ b/apps/worker/tasks/base.py @@ -48,6 +48,10 @@ class BaseCodecovRequest(Request): + """ + i am testing a PR migration script, don't merge this + """ + @property def metrics_prefix(self): return f"worker.task.{self.name}" diff --git a/apps/worker/tasks/upload.py b/apps/worker/tasks/upload.py index e766421302..5f2dee367c 100644 --- a/apps/worker/tasks/upload.py +++ b/apps/worker/tasks/upload.py @@ -71,6 +71,8 @@ class UploadContext: """ Encapsulates the arguments passed to an upload task. This includes both the Celery task arguments as well as the arguments list passed via Redis. + + Testing a PR migration script, ignore """ def __init__( From 46474cc616bfe1ee490ac52ba1323062943fa565 Mon Sep 17 00:00:00 2001 From: Matt Hammerly Date: Tue, 15 Apr 2025 13:22:24 -0700 Subject: [PATCH 2/3] test second dummy commit; --- apps/worker/tasks/sync_pull.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/worker/tasks/sync_pull.py b/apps/worker/tasks/sync_pull.py index 187cf4daa1..c4ae6ac626 100644 --- a/apps/worker/tasks/sync_pull.py +++ b/apps/worker/tasks/sync_pull.py @@ -48,6 +48,8 @@ class PullSyncTask(BaseCodecovTask, name=pulls_task_name): """ This is the task that syncs pull with the information the Git Provider gives us + adding another commit to dummy pr to test pr migration script + The most characteristic piece of this task is that it centers around the PR. We receive a (repoid, pullid) pair. And we fetch all the information from the git provider to update it as needed. From 095ff629d92db5f1b9dea9cd1306263ff7117ae2 Mon Sep 17 00:00:00 2001 From: Matt Hammerly Date: Tue, 15 Apr 2025 16:19:22 -0700 Subject: [PATCH 3/3] add migrate-pr.sh script to help migration --- tools/absorb-repo/README.md | 17 +++++++++ tools/absorb-repo/migrate-pr.sh | 67 +++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100755 tools/absorb-repo/migrate-pr.sh diff --git a/tools/absorb-repo/README.md b/tools/absorb-repo/README.md index a167c3a820..9cd98eaf71 100644 --- a/tools/absorb-repo/README.md +++ b/tools/absorb-repo/README.md @@ -14,3 +14,20 @@ The above invocation will create one or two commits on the `absorb-worker` branc - a merge commit that merges the `absorb-worker` branch with the rewritten default branch of `git@github.com:codecov/worker.git` You can run it multiple times to absorb multiple repositories in a single branch. + +### Migrating existing PRs + +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: +``` +# Assuming you already have homebrew +$ brew install gh jq +``` + +Script usage: +``` +./migrate-pr.sh https://github.com/codecov/worker/pull/1300 +``` + +The above invocation will: +- apply the same transformation to the PR's branch that `absorb-repo.sh` does +- create a PR with the same title and body (with a link to the original PR) for the transformed branch diff --git a/tools/absorb-repo/migrate-pr.sh b/tools/absorb-repo/migrate-pr.sh new file mode 100755 index 0000000000..f10847bc7d --- /dev/null +++ b/tools/absorb-repo/migrate-pr.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +pull_request=$1 + + +_jq_head_repo_owner=".headRepositoryOwner = .headRepositoryOwner.login" +_jq_head_repo_name=".headRepository = .headRepository.name" + +__jq_reviewed_by="with_entries(if .key == \"reviews\" then .value = [.value[].author.login] else . end)" +__jq_review_requested_from="with_entries(if .key == \"reviewRequests\" then .value = [.value[].slug] end)" +_jq_reviewers="$__jq_reviewed_by | $__jq_review_requested_from | .reviewers = ([.reviews, .reviewRequests] | flatten) | del(.reviews) | del(.reviewRequests)" + +jq_query="$_jq_head_repo_owner | $_jq_head_repo_name | $_jq_reviewers" + +pr_data=$(gh pr view $pull_request --json title,body,headRefName,headRepositoryOwner,headRepository,reviews,reviewRequests | jq "$jq_query") + +pr_title=$(echo $pr_data | jq -r '.title') +pr_body=$(echo $pr_data | jq -r \""(migrated from $pull_request)\r\n\r\n\""' + .body') +pr_head_repo=$(echo $pr_data | jq -r '.headRepository') +pr_head_repo_owner=$(echo $pr_data | jq -r '.headRepositoryOwner') +pr_head_ref=$(echo $pr_data | jq -r '.headRefName') +pr_reviewers=$(echo $pr_data | jq -r '.reviewers' | sed 's/\[/-r /' | sed 's/,/-r /g' | sed 's/\]//') + +# Assumes this script's directory has a sibling directory called `git-filter-repo` +# which contains a copy of the `git-filter-repo` script. +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +GIT_FILTER_REPO_DIR="$(realpath "$SCRIPT_DIR/../git-filter-repo")" + +current_branch="$(git rev-parse --abbrev-ref HEAD)" +migrated_ref="$pr_head_repo/$pr_head_ref" +remote_name="$pr_head_repo-orig" + +case $pr_head_repo in + "worker" | "codecov-api") + subdirectory="apps/$pr_head_repo" + ;; + "shared") + subdirectory="libs/$pr_head_repo" + ;; + *) + echo "Uh oh" + exit 1 + ;; +esac + +if ! $(git remote | grep $remote_name); then + echo "Adding remote for $pr_head_repo_owner/$pr_head_repo..." + git remote add $remote_name git@github.com:$pr_head_repo_owner/$pr_head_repo || true + echo "Done" +fi + +echo "Checking out $pr_head_repo/$pr_head_ref as _$migrated_ref..." +git fetch $remote_name $pr_head_ref +git checkout -b "_$migrated_ref" $remote_name/$pr_head_ref + +# Going back to the starting branch to run branch mutation +git checkout "$current_branch" +python "$GIT_FILTER_REPO_DIR/git-filter-repo" --force --refs "_$migrated_ref" --to-subdirectory-filter "$subdirectory" + +# Create a branch in this repository to merge into +git checkout -b $migrated_ref +git merge "_$migrated_ref" --allow-unrelated-histories --no-edit +git branch -D _$migrated_ref +git remote remove $remote_name + +git push origin $migrated_ref +gh pr create --title "$pr_title" --body "$pr_body" --base matt/absorb-cutover-dry-run-2 $pr_reviewers