From 22363a26d65889419cbbc9368bb4327700909470 Mon Sep 17 00:00:00 2001 From: Dave Long Date: Mon, 24 Nov 2025 12:19:32 +0000 Subject: [PATCH 1/3] Add git-d8mr command to simplify commit of merge requests. --- git-d8mr | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 git-d8mr diff --git a/git-d8mr b/git-d8mr new file mode 100755 index 0000000..ab96d8f --- /dev/null +++ b/git-d8mr @@ -0,0 +1,73 @@ +#!/bin/bash + +set -euo pipefail + +if [ $# -lt 2 ]; then + echo "Usage: git d8mr [additional_branches]" 1>&2 + exit 1 +fi + +if [ ! -z "$(git status --untracked-files=no --porcelain)" ]; then + echo "Error: Working directory is not clean." 1>&2 + exit 1 +fi + +TYPE=$1 +if [[ ! "$TYPE" =~ ^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|task|test)$ ]]; then + echo "Error: Invalid issue type, see https://github.com/pvdlg/conventional-changelog-metahub#commit-types" 1>&2 + exit 1 +fi + +MR=$2 +ISSUE=$(curl --silent https://git.drupalcode.org/api/v4/projects/project%2Fdrupal/merge_requests/${MR} | jq -r .source_branch | cut -d- -f1) +echo "Issue: https://www.drupal.org/project/drupal/issues/${ISSUE}" + +CRURL=$(curl -Ls -w %{url_effective} -o /dev/null https://new.drupal.org/contribution-record?source_link=https%3A//www.drupal.org/node/${ISSUE}) +CRDATA=$(curl --silent --globoff "https://www.drupal.org/jsonapi/node/contribution_record?filter[nid]=${CRURL##*/}&include=field_contributors,field_contributors.field_contributor_user") +AUTHORS=$(echo $CRDATA | jq -r ' + INDEX(.included[] | select(.type=="user--user"); .id) as $users + | .included[] + | select(.attributes.field_credit_this_contributor) + | "By: " + $users[.relationships.field_contributor_user.data.id].attributes.display_name +') + +if [ -z "$AUTHORS" ]; then + echo "Error: No credits found, update the contribution record first: $CRURL" 1>&2 + exit 1 +fi + +MRURL="https://git.drupalcode.org/project/drupal/-/merge_requests/${MR}" +echo "Applying patch from $MRURL" +echo +curl --silent --fail ${MRURL}.diff | git apply -v --index +echo + +MESSAGE="${TYPE}: #${ISSUE} $(echo $CRDATA | jq -r .data[0].attributes.title) + +$AUTHORS" +echo "$MESSAGE" +echo +git commit -m "$MESSAGE" + +branches=$(echo $3 | tr "," "\n") +first_branch=`git rev-parse --abbrev-ref HEAD` +commit_hash=`git log -n 1 --pretty=format:"%H"` +short_commit_hash=`git log -n 1 --pretty=format:"%h"` +thanks_message="Committed and pushed $short_commit_hash to $first_branch" +push_message="Use the following command to push the changes: git push origin $first_branch" + +for branch in $branches +do + # Cherry pick to the other branches. The -x option adds an additional line to the commit message linking back to the original commit. + git checkout $branch + git pull --rebase + git cherry-pick -x $commit_hash + branch_hash=`git log -n 1 --pretty=format:"%h"` + thanks_message="$thanks_message and $branch_hash to $branch" + push_message="$push_message $branch" +done + +git checkout $first_branch +echo "$push_message" + +echo "$thanks_message. Thanks!" | pbcopy From 5428067ac14cdcdfb7ce18429bfdc1ef11cfeb62 Mon Sep 17 00:00:00 2001 From: Dave Long Date: Mon, 24 Nov 2025 14:57:47 +0000 Subject: [PATCH 2/3] JSON:API is cached by Varnish, send a cookie to bypass cache for when the contribution record was recently updated. --- git-d8mr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-d8mr b/git-d8mr index ab96d8f..999426a 100755 --- a/git-d8mr +++ b/git-d8mr @@ -23,7 +23,7 @@ ISSUE=$(curl --silent https://git.drupalcode.org/api/v4/projects/project%2Fdrupa echo "Issue: https://www.drupal.org/project/drupal/issues/${ISSUE}" CRURL=$(curl -Ls -w %{url_effective} -o /dev/null https://new.drupal.org/contribution-record?source_link=https%3A//www.drupal.org/node/${ISSUE}) -CRDATA=$(curl --silent --globoff "https://www.drupal.org/jsonapi/node/contribution_record?filter[nid]=${CRURL##*/}&include=field_contributors,field_contributors.field_contributor_user") +CRDATA=$(curl --silent --globoff "https://www.drupal.org/jsonapi/node/contribution_record?filter[nid]=${CRURL##*/}&include=field_contributors,field_contributors.field_contributor_user" --cookie _cachebuster=$(date +%s)) AUTHORS=$(echo $CRDATA | jq -r ' INDEX(.included[] | select(.type=="user--user"); .id) as $users | .included[] From 07242fde25ccddfe5a84024b790aa49f6a91d919 Mon Sep 17 00:00:00 2001 From: Dave Long Date: Mon, 24 Nov 2025 15:19:56 +0000 Subject: [PATCH 3/3] Find issue URL from source project. --- git-d8mr | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/git-d8mr b/git-d8mr index 999426a..6d71b4e 100755 --- a/git-d8mr +++ b/git-d8mr @@ -19,7 +19,8 @@ if [[ ! "$TYPE" =~ ^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|tas fi MR=$2 -ISSUE=$(curl --silent https://git.drupalcode.org/api/v4/projects/project%2Fdrupal/merge_requests/${MR} | jq -r .source_branch | cut -d- -f1) +PROJECT=$(curl --silent https://git.drupalcode.org/api/v4/projects/project%2Fdrupal/merge_requests/${MR} | jq -r .source_project_id) +ISSUE=$(curl --silent https://git.drupalcode.org/api/v4/projects/${PROJECT} | jq -r .path | cut -d- -f2) echo "Issue: https://www.drupal.org/project/drupal/issues/${ISSUE}" CRURL=$(curl -Ls -w %{url_effective} -o /dev/null https://new.drupal.org/contribution-record?source_link=https%3A//www.drupal.org/node/${ISSUE})