Skip to content

Fix mr:logs 404 by reading jobs and traces from the issue fork - #383

Merged
mglaman merged 3 commits into
mainfrom
fix/mr-logs-fork-project
Sep 16, 2026
Merged

mglaman merged 3 commits into
mainfrom
fix/mr-logs-fork-project

Conversation

@mglaman

@mglaman mglaman commented Sep 16, 2026

Copy link
Copy Markdown
Owner

Fixes #378.

mr:logs failed with a 404 on every drupal.org merge request, and after that was fixed it printed (trace unavailable) for every failed job when run without a GitLab token.

What changed

  • Jobs and traces are fetched from the pipeline's project ($pipeline->project_id), which is the issue fork. Only the pipelines call belongs on the target project.
  • When the API trace endpoint rejects the request, the action reads <job web_url>/raw instead. That endpoint serves the same log anonymously. Guzzle follows the redirect to object storage and drops the Authorization header across origins.
  • Log excerpts are cleaned by a new JobLog::clean(): runner timestamp prefixes, ANSI color codes, and section_start/section_end markers are removed so the last 100 lines read like terminal output.

Each change is its own commit.

Testing

Unit tests pin the jobs and trace calls to the pipeline's project id, cover the raw-log fallback, the double-failure case, and the log cleaner against real runner output.

Live, without a token:

drupalorg mr:logs https://git.drupalcode.org/project/poll/-/merge_requests/95 --no-cache

Prints the failing phpunit and phpstan job excerpts from pipeline 947467 on issue/poll-3620831.

🤖 Generated with Claude Code

mglaman and others added 3 commits September 16, 2026 09:50
Merge request pipelines on drupal.org run on the issue fork, not the
target project. mr:logs passed the target project id to the jobs and
trace endpoints, which answer 404 for every merge request.

Fixes #378 (part 1)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…race is denied

The API trace endpoint answers 401 without a GitLab token, and the CLI
runs without one for most users. The catch block turned that into
"(trace unavailable)" for every failed job. The job's web URL plus /raw
serves the same log anonymously, so the action falls back to it.

Fixes #378 (part 2)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…ob log excerpts

Raw GitLab job logs prefix every line with a timestamp and stream flag,
wrap text in ANSI color codes, and carry section_start/section_end
markers. The excerpt in mr:logs is read by people and agents, so it
drops all three.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@mglaman
mglaman merged commit 6de3a1e into main Sep 16, 2026
9 checks passed
@mglaman
mglaman deleted the fix/mr-logs-fork-project branch September 16, 2026 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mr:logs: 404 because pipeline jobs and traces live on the issue fork, not the project

1 participant