Skip to content

feat: Bitbucket Pipelines logs for --logs and get_failed_logs - #28

Merged
devblac merged 1 commit into
mainfrom
feat/pipelines-logs
Nov 6, 2026
Merged

devblac merged 1 commit into
mainfrom
feat/pipelines-logs

Conversation

@devblac

@devblac devblac commented Nov 1, 2026

Copy link
Copy Markdown
Owner

What

  • prw checks --logs, prw wait --logs and MCP get_failed_logs now show, for each failed Bitbucket Pipelines build, the output of the script command that failed in its first failed step.
  • How: build number from the status link → GET /pipelines/{N}/steps/ → first FAILED/ERROR step → GET /pipelines/{pipeline}/steps/{step}/log (tail 4 MiB) → from the last + <script command> line up to the teardown.
  • No log (token without the pipeline scope, or a timeout) → the step's error message, e.g. "Exceeded build time limit of 120 minutes."
  • Jenkins and other CI keep showing their link.
  • github.Client.GetText (raw GET), and GetJobLog now counts toward the requests-per-hour figure.

Test plan

  • go test -race ./..., go vet ./...
  • Unit tests: log extraction (known/unknown commands, truncation, plain logs), steps + log requests, 404 with and without a step error, Pipelines and Jenkins runs through FailedJobLogs
  • Live, anonymous: prw checks --logs on atlassian/atlassian-connect-express PR 552 shows the timeout reason of pipeline #2435
  • With the owner's token: a real failed step log (logs need the pipeline scope; the parser is tested on a constructed log)

🤖 Generated with Claude Code

The Bitbucket client now implements github.RunLogReader: for a failed build
status linking to a Pipelines result, it lists the pipeline's steps by build
number, downloads the log of the first failed step, and keeps the output of
the last script command ("+ <command>") up to the teardown. When there is no
log (no pipeline scope, or a timeout), the step's error message is shown
instead. Other CI systems are listed with their link, as before.

Also: github.Client gets GetText (raw GET, tail-limited, counted), and
GetJobLog now counts its request too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T03:48:00.644292Z 802c2ab PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 802c2ab076

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}
reason := step.State.Result.Error.Message // e.g. "Exceeded build time limit of 120 minutes."

logPath := fmt.Sprintf("%s/pipelines/%s/steps/%s/log", repoPath(workspace, repo), url.PathEscape(step.Pipeline.UUID), url.PathEscape(step.UUID))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Use the known pipeline identifier when constructing the log URL

For a steps response matching the documented Bitbucket API schema, the step has its own uuid but no embedded pipeline.uuid. Consequently, step.Pipeline.UUID remains empty and this constructs /pipelines//steps/{step}/log, preventing log retrieval even with the correct token scope. The new fixture supplies an embedded pipeline that masks this case. Reuse the pipeline identifier used to list the steps, or explicitly retrieve its UUID, rather than requiring it in each step.

Useful? React with 👍 / 👎.

Comment on lines +157 to +160
end := len(lines)
for i := start; i < len(lines); i++ {
if teardownLine.MatchString(lines[i]) {
end = i

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Exclude after-script output before selecting the failure excerpt

For steps with after-script, Bitbucket runs those commands even when the main script fails. This extraction only stops at test-report or artifact-scanning messages, so cleanup output remains in the excerpt and sufficiently verbose cleanup pushes the actual failure out of the last maxLines lines. When command matching falls back to any + line, it can instead select a cleanup command outright. Identify the after-script boundary before selecting the failed command and trimming its output so --logs and get_failed_logs retain the actual failure.

Useful? React with 👍 / 👎.

@devblac
devblac merged commit a0b3bc9 into main Nov 6, 2026
2 checks passed
@devblac
devblac deleted the feat/pipelines-logs branch November 6, 2026 23:20
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.

1 participant