Skip to content

Clean up stale Bitbucket steps when switching to pre-commit#1293

Closed
Copilot wants to merge 3 commits intomainfrom
copilot/fix-stale-bitbucket-steps
Closed

Clean up stale Bitbucket steps when switching to pre-commit#1293
Copilot wants to merge 3 commits intomainfrom
copilot/fix-stale-bitbucket-steps

Conversation

Copy link
Contributor

Copilot AI commented Feb 10, 2026

Plan to Fix Stale Bitbucket Steps Issue

Problem: Tool.update_bitbucket_steps() returns early when is_pre_commit_used() is true (line 683-684), which prevents cleanup of previously-added Bitbucket steps. This leaves stale steps in bitbucket-pipelines.yml after switching to pre-commit.

Solution: Before returning early when pre-commit is used, remove any managed Bitbucket steps for this tool.

Checklist:

  • Write test case that reproduces the stale steps issue
    • Create test that adds Bitbucket steps for a tool
    • Enable pre-commit and re-run update_bitbucket_steps()
    • Verify that stale steps are removed
  • Fix the bug in Tool.update_bitbucket_steps()
    • Call remove_bitbucket_steps() when pre-commit is used before returning
    • Ensure this only runs when Bitbucket is actually used
    • Add check for self.is_used() to prevent removing steps for unused tools
  • Add test to verify steps are NOT removed when tool is not used
  • Run broader test suite to ensure no regressions (119 passed, 1 skipped)
  • Request code review
  • Run CodeQL security checker

Security Summary

No security vulnerabilities were discovered during analysis.

Original prompt

This section details on the original issue you should resolve

<issue_title>Test and fix issue with stael</issue_title>
<issue_description>Per copilot review of #1286

Tool.update_bitbucket_steps() returns early when pre-commit is used, which prevents cleanup of any previously-added Bitbucket steps for this tool. This can leave stale per-tool CI steps in bitbucket-pipelines.yml after a project switches to running QA via pre-commit (or after use_ci_bitbucket() is re-run), causing duplicated CI work. Consider removing this tool’s managed Bitbucket steps when is_pre_commit_used() is true (or otherwise ensuring stale steps are cleaned up) before returning.

Tests should be written for this case, and the bug fixed.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix issue with stale Bitbucket steps in CI Clean up stale Bitbucket steps when switching to pre-commit Feb 10, 2026
# don't add Bitbucket steps (the tool will run via pre-commit instead)
if is_pre_commit_used():
# Remove any stale Bitbucket steps before returning
if is_bitbucket_used():
Copy link
Collaborator

Choose a reason for hiding this comment

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

@copilot this doesn't make sense to me - won't this introduce a bug where we remove steps even when they don't need to be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're absolutely right! The original code would remove steps even when the tool wasn't being used, which is incorrect.

Fixed in 54dab02 by adding self.is_used() check. Now steps are only removed when:

  1. Pre-commit is enabled
  2. Bitbucket is used
  3. The tool is actually configured/used in the project

Also added a test to verify steps are NOT removed when the tool isn't used.

@nathanjmcdougall
Copy link
Collaborator

:\

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.

Test and fix issue with stale CI step cleanup

2 participants