Purpose: Agentic workflow for contributing to a Drupal.org issue via GitLab MR.
Usage: /drupalorg-work-on-issue <nid>
Instructions
When the user invokes /drupalorg-work-on-issue <nid>, execute the following workflow. Pause at
each checkpoint marked [PAUSE] — present findings and wait for the user to confirm
before proceeding.
Step 1: Fetch issue and fork details
Run both commands to gather context:
drupalorg issue:show <nid> --format=llm
drupalorg issue:get-fork <nid> --format=llm
Report to the user:
- Issue title, status, project machine name
- Whether a fork exists and which branches are available
Directory detection: Before prompting the user, read CLAUDE.md in the current directory.
If it documents the path to the <project> module or repository, cd there automatically
and skip the directory prompt. Only fall back to running git remote get-url origin and
asking the user if CLAUDE.md provides no guidance.
Branch selection: Count branches from the issue:get-fork output that match <nid>-*:
- Exactly one match → select it automatically; no prompt needed.
- Multiple matches → list them and ask the user which to check out.
- No matches → note that no branches exist yet and ask the user how to proceed (e.g. create a new branch from the upstream project default branch).
[PAUSE] Only pause here if the working directory could not be determined automatically OR if multiple branches exist. Present your findings and wait for confirmation before proceeding.
Step 2: Set up remote and check out the branch
Important: All
gitanddrupalorgcommands from this point forward must be run from the project module directory (not the Drupal site root). Ensure you havecd'd into the correct directory before executing any command below.
Once the directory and branch are confirmed:
drupalorg issue:setup-remote <nid>
drupalorg issue:checkout <nid> <branch>
SSH remote URL check: issue:setup-remote sets the remote URL to HTTPS
(https://git.drupal.org/issue/<project>-<nid>.git). Contributors using SSH authentication
must switch to the SSH equivalent before pushing. After the remote is set:
git remote get-url drupalorg
- If the URL starts with
https://, warn the user and offer to convert it:
wheregit remote set-url drupalorg git@git.drupal.org:issue/<project>-<nid>.git<project>and<nid>match the values from the HTTPS URL. - If it already starts with
git@, no action needed.
Report the branch that is now active.
Step 3: Inspect the current MR state
Important: Run all commands from the project module directory.
Diff the branch first to understand what has already been changed vs. what is still
missing. Determine the upstream default branch from the fork data (e.g. main, 10.3.x),
then run:
git diff origin/<default-branch>...HEAD
Read this diff carefully before analysing the MR — it is the authoritative record of what the branch already contains. Do not assume a file is unchanged without checking the diff.
drupalorg mr:list <nid> --format=llm
If mr:list returns no MRs:
- Report "No MR exists yet for this issue."
- Skip the MR inspection commands below.
- Proceed directly to the work loop (Step 4).
- After the first
git push, capture the GitLab MR-creation URL printed in the push output and surface it to the user. Then re-rundrupalorg mr:list <nid> --format=llmto pick up the newly created MR IID before polling pipeline status.
If one or more MRs exist, for the relevant MR (confirm with user if multiple exist):
drupalorg mr:files <nid> <mr-iid>
drupalorg mr:diff <nid> <mr-iid>
drupalorg mr:status <nid> <mr-iid> --format=llm
Summarise:
- What the MR changes (files and diff summary)
- Current pipeline status (passing / failing / pending)
- If the pipeline is failing, fetch logs:
drupalorg mr:logs <nid> <mr-iid>
[PAUSE] Present your analysis of the MR and the pipeline results, then ask: "What would you like me to work on?"
Step 4: Work loop
Important: Run all
gitanddrupalorgcommands from the project module directory.
Iterate until the pipeline is green or the user asks to stop:
- Make the requested code changes.
- If
vendor/bin/phpcsis available, run it on the module directory and fix any violations before proceeding:
Do not stage or commit files while PHPCS reports errors. Skip this step if PHPCS is not installed.vendor/bin/phpcs <module-path> - Before committing, inspect the project's commit style:
Match the observed style (e.g. conventional commits,git log --oneline -5Issue #<nid> by <username>:, etc.) rather than defaulting to any fixed template. - Stage only the files you actually modified:
git add <specific-changed-files> - Commit using the inferred message style:
git commit -m "<message matching project style>" - Push:
git push - Poll pipeline:
drupalorg mr:status <nid> <mr-iid> --format=llm - If failing, fetch logs and fix:
drupalorg mr:logs <nid> <mr-iid>
[PAUSE] After each push, report the pipeline outcome and ask whether to continue or stop.
Notes
issue:setup-remoteis idempotent — safe to re-run.--format=llmoutput is optimised for parsing; always use it when reading structured data.- If the fork has no branches, the contributor has not pushed yet — discuss with the user before creating a new MR from the upstream project.