Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,24 @@ git pre-commit check failed: file core/core.services.yml should be 644 not 777
4. Decide if there are any additional branches to merge to
5. Run the command:
````
git drmr <issue_type> <merge_request_id> [additional_branches]
git drmr [--apply|--commit] <issue_type> <merge_request_id> [additional_branches]
````
The merge request ID can be either the numeric ID (e.g. `9395`) or the full GitLab URL (e.g. `https://git.drupalcode.org/project/drupal/-/merge_requests/9395`).

### Flags

By default the command applies the MR diff and immediately commits. Two flags allow splitting these steps:

- `--apply` — Applies the MR diff to the current branch and exits without committing. Useful when you want to review or amend the changes before committing. The contribution record does not need to be updated before using this flag.
- `--commit` — Skips applying the diff and goes straight to creating the commit message, committing to the current branch, and cherry-picking to any additional branches. Use this after `--apply` once the contribution record is ready.

Example two-step workflow:
````
git drmr --apply fix 9395
# Review changes, update contribution record on drupal.org...
git drmr --commit fix 9395 11.x,10.3.x
````

## Troubleshooting

### Using core's Coder dev dependency
Expand Down
42 changes: 35 additions & 7 deletions git-drmr
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,30 @@

set -euo pipefail

MODE="default"

while [[ $# -gt 0 ]]; do
case "$1" in
--apply)
MODE="apply"
shift
;;
--commit)
MODE="commit"
shift
;;
*)
break
;;
esac
done

if [ $# -lt 2 ]; then
echo "Usage: git drmr <issue_type> <merge_request_id> [additional_branches]" 1>&2
echo "Usage: git drmr [--apply|--commit] <issue_type> <merge_request_id> [additional_branches]" 1>&2
exit 1
fi

if [ ! -z "$(git status --untracked-files=no --porcelain)" ]; then
if [ "$MODE" != "commit" ] && [ ! -z "$(git status --untracked-files=no --porcelain)" ]; then
echo "Error: Working directory is not clean." 1>&2
exit 1
fi
Expand Down Expand Up @@ -36,6 +54,15 @@ PROJECT=$(curl --silent https://git.drupalcode.org/api/v4/projects/project%2Fdru
ISSUE=$(curl --silent "https://git.drupalcode.org/api/v4/projects/${PROJECT}" | jq -r '.path | capture("(?<id>[0-9]+)$").id')
echo "Issue: https://www.drupal.org/project/drupal/issues/${ISSUE}"

MRURL="https://git.drupalcode.org/project/drupal/-/merge_requests/${MR}"

if [ "$MODE" = "apply" ]; then
echo "Applying patch from $MRURL"
echo
curl --silent --fail ${MRURL}.diff | git apply -v --index
exit 0
fi

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" --cookie _cachebuster=$(date +%s))
AUTHORS=$(echo $CRDATA | jq -r '
Expand All @@ -50,11 +77,12 @@ if [ -z "$AUTHORS" ]; then
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
if [ "$MODE" = "default" ]; then
echo "Applying patch from $MRURL"
echo
curl --silent --fail ${MRURL}.diff | git apply -v --index
echo
fi

MESSAGE="${TYPE}: #${ISSUE} $(echo $CRDATA | jq -r .data[0].attributes.title)

Expand Down