bmsdna-devtools 0.51.0__tar.gz → 0.52.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/PKG-INFO +13 -2
  2. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/README.md +12 -1
  3. bmsdna_devtools-0.52.0/bmsdna/devtools/ado_auth.py +177 -0
  4. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/azure_auth.py +6 -2
  5. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/cli.py +144 -43
  6. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/gh_pr.py +146 -10
  7. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/pr_build.py +258 -13
  8. bmsdna_devtools-0.52.0/bmsdna/devtools/pr_cancel.py +146 -0
  9. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/pr_info.py +45 -12
  10. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/pyproject.toml +1 -1
  11. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/skills/bmsdna-devtools/SKILL.md +3 -0
  12. bmsdna_devtools-0.52.0/tests/test_ado_auth.py +233 -0
  13. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_cli_commit.py +1 -1
  14. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_cli_issue.py +9 -9
  15. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_cli_pr_create.py +1 -1
  16. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_cli_pr_id.py +3 -3
  17. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_issue_for_me.py +4 -3
  18. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_pr_build.py +3 -3
  19. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_pr_build_flow.py +3 -3
  20. bmsdna_devtools-0.52.0/tests/test_pr_cancel_build.py +718 -0
  21. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_pr_choice.py +7 -6
  22. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_pr_description_not_truncated.py +1 -1
  23. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_pr_info.py +10 -6
  24. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_wait_timeout.py +1 -1
  25. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/uv.lock +1 -1
  26. bmsdna_devtools-0.51.0/bmsdna/devtools/ado_auth.py +0 -28
  27. bmsdna_devtools-0.51.0/tests/test_ado_auth.py +0 -71
  28. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/.github/workflows/auto-release.yml +0 -0
  29. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/.github/workflows/python-publish.yml +0 -0
  30. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/.github/workflows/python-test.yml +0 -0
  31. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/.gitignore +0 -0
  32. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/.python-version +0 -0
  33. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/__init__.py +0 -0
  34. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/_api_dump.py +0 -0
  35. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/ado_issue.py +0 -0
  36. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/agent_mentions.py +0 -0
  37. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/api_usage.py +0 -0
  38. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/app_service_logs.py +0 -0
  39. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/azure_arm.py +0 -0
  40. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/bdt_config.py +0 -0
  41. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/business_user.py +0 -0
  42. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/ci_plan.py +0 -0
  43. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/ci_plan_env.py +0 -0
  44. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/cli_tools.py +0 -0
  45. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/commit.py +0 -0
  46. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/dead_code.py +0 -0
  47. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/env_config.py +0 -0
  48. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/env_files.py +0 -0
  49. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/find_injection.py +0 -0
  50. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/find_repo.py +0 -0
  51. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/gh_args.py +0 -0
  52. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/gh_issue.py +0 -0
  53. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/github_api.py +0 -0
  54. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/gitrepo.py +0 -0
  55. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/injection_frontend.py +0 -0
  56. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/injection_python.py +0 -0
  57. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/issue_do.py +0 -0
  58. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/issue_show.py +0 -0
  59. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/issue_watch.py +0 -0
  60. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/lint.py +0 -0
  61. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/lint_findings.py +0 -0
  62. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/lint_models.py +0 -0
  63. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/lint_sql.py +0 -0
  64. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/lint_sql_files.py +0 -0
  65. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/lint_tooling.py +0 -0
  66. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/lint_typescript.py +0 -0
  67. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/logs.py +0 -0
  68. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/pr_choice.py +0 -0
  69. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/pr_create_args.py +0 -0
  70. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/pr_issue_link.py +0 -0
  71. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/pr_labels.py +0 -0
  72. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/pr_markdown.py +0 -0
  73. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/pr_merge_defaults.py +0 -0
  74. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/pr_ref.py +0 -0
  75. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/pull.py +0 -0
  76. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/testdb.py +0 -0
  77. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/translate.py +0 -0
  78. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/usage/__init__.py +0 -0
  79. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/usage/cli.py +0 -0
  80. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/usage/pipeline.py +0 -0
  81. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/usage/pricing.py +0 -0
  82. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/usage/report.py +0 -0
  83. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/usage/sql/00_schema.sql +0 -0
  84. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/usage/sql/01_ingest_claude.sql +0 -0
  85. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/usage/sql/01_ingest_codex.sql +0 -0
  86. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/usage/sql/02_messages.sql +0 -0
  87. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/usage/sql/03_markers.sql +0 -0
  88. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/usage/sql/04_facts.sql +0 -0
  89. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/usage/sql/05_views.sql +0 -0
  90. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/bmsdna/devtools/worktree.py +0 -0
  91. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/justfile +0 -0
  92. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/conftest.py +0 -0
  93. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/fake_github.py +0 -0
  94. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_ado_issue.py +0 -0
  95. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_ado_issue_flow.py +0 -0
  96. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_agent_mentions.py +0 -0
  97. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_api_usage.py +0 -0
  98. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_app_service_logs.py +0 -0
  99. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_azure_arm.py +0 -0
  100. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_bdt_config.py +0 -0
  101. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_business_user.py +0 -0
  102. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_ci_plan.py +0 -0
  103. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_ci_plan_env.py +0 -0
  104. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_cli_cleanup.py +0 -0
  105. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_cli_pull.py +0 -0
  106. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_cli_tools.py +0 -0
  107. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_cli_version.py +0 -0
  108. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_commit.py +0 -0
  109. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_env_config.py +0 -0
  110. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_env_files.py +0 -0
  111. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_find_injection.py +0 -0
  112. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_find_repo.py +0 -0
  113. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_gh_issue.py +0 -0
  114. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_gh_pr.py +0 -0
  115. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_github_api.py +0 -0
  116. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_gitrepo.py +0 -0
  117. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_issue_do.py +0 -0
  118. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_issue_show.py +0 -0
  119. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_issue_watch.py +0 -0
  120. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_lint.py +0 -0
  121. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_lint_models.py +0 -0
  122. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_lint_sql.py +0 -0
  123. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_lint_sql_files.py +0 -0
  124. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_lint_tooling.py +0 -0
  125. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_lint_typescript.py +0 -0
  126. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_logs.py +0 -0
  127. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_pr_build_create_options.py +0 -0
  128. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_pr_create_args.py +0 -0
  129. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_pr_issue_link.py +0 -0
  130. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_pr_labels.py +0 -0
  131. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_pr_markdown.py +0 -0
  132. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_pr_merge_defaults.py +0 -0
  133. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_pull.py +0 -0
  134. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_testdb.py +0 -0
  135. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_translate.py +0 -0
  136. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_usage.py +0 -0
  137. {bmsdna_devtools-0.51.0 → bmsdna_devtools-0.52.0}/tests/test_worktree_clean.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: bmsdna-devtools
3
- Version: 0.51.0
3
+ Version: 0.52.0
4
4
  Summary: Shared Azure DevOps / GitHub / git / Azure Monitor developer tooling for BMS projects
5
5
  Requires-Python: >=3.14
6
6
  Requires-Dist: azure-identity>=1.19.0
@@ -126,7 +126,7 @@ bdt pr info [--json] [--pr-id PR]... [--target-branch BRANCH] [--all]
126
126
  ```
127
127
 
128
128
  One-shot summary of the current branch's PR: link, state (open/merged/closed, draft), aggregate
129
- build state (`passing`, `failing`, `pending`, `waiting` for a manual approval, `none`) and the
129
+ build state (`passing`, `failing`, `cancelled`, `pending`, `waiting` for a manual approval, `none`) and the
130
130
  issue(s)/work item(s) it closes, with links. Exits 1 when the branch has no PR. `--json` is what
131
131
  a status integration reads (e.g. the Claude Code mod planned in bmsuisse/skills#61). Build state is judged the way `bdt pr status` does: on GitHub from
132
132
  the check rollup (only a failed check fails it; skipped/cancelled ones don't count), on Azure DevOps
@@ -185,6 +185,17 @@ by a GitHub Actions run (e.g. a legacy commit status from an external CI)
185
185
  can't be retried this way and are skipped; if none of the failing checks are
186
186
  retryable, the command exits with an error.
187
187
 
188
+ ## `bdt pr cancel-build` / `requeue-build` / `abandon`
189
+
190
+ ```bash
191
+ bdt pr cancel-build --reason "..." [--session ID_OR_URL] [--pr-id N] # comment "CANCELLED BUILD: ..."
192
+ bdt pr requeue-build [--all] [--pr-id N] # new build; `retry` only reruns failed stages
193
+ bdt pr abandon --reason "..." [--session ID_OR_URL] [--pr-id N] # comment "ABANDONED PR: ..."
194
+ ```
195
+
196
+ `bdt pr info` / `bdt pr status` show the reason (and agent session) of a cancelled build or abandoned PR; run
197
+ `--help` for details.
198
+
188
199
  ## `bdt pr watch-deploy`
189
200
 
190
201
  Many pipelines have a second build/stage that only runs on the *target*
@@ -108,7 +108,7 @@ bdt pr info [--json] [--pr-id PR]... [--target-branch BRANCH] [--all]
108
108
  ```
109
109
 
110
110
  One-shot summary of the current branch's PR: link, state (open/merged/closed, draft), aggregate
111
- build state (`passing`, `failing`, `pending`, `waiting` for a manual approval, `none`) and the
111
+ build state (`passing`, `failing`, `cancelled`, `pending`, `waiting` for a manual approval, `none`) and the
112
112
  issue(s)/work item(s) it closes, with links. Exits 1 when the branch has no PR. `--json` is what
113
113
  a status integration reads (e.g. the Claude Code mod planned in bmsuisse/skills#61). Build state is judged the way `bdt pr status` does: on GitHub from
114
114
  the check rollup (only a failed check fails it; skipped/cancelled ones don't count), on Azure DevOps
@@ -167,6 +167,17 @@ by a GitHub Actions run (e.g. a legacy commit status from an external CI)
167
167
  can't be retried this way and are skipped; if none of the failing checks are
168
168
  retryable, the command exits with an error.
169
169
 
170
+ ## `bdt pr cancel-build` / `requeue-build` / `abandon`
171
+
172
+ ```bash
173
+ bdt pr cancel-build --reason "..." [--session ID_OR_URL] [--pr-id N] # comment "CANCELLED BUILD: ..."
174
+ bdt pr requeue-build [--all] [--pr-id N] # new build; `retry` only reruns failed stages
175
+ bdt pr abandon --reason "..." [--session ID_OR_URL] [--pr-id N] # comment "ABANDONED PR: ..."
176
+ ```
177
+
178
+ `bdt pr info` / `bdt pr status` show the reason (and agent session) of a cancelled build or abandoned PR; run
179
+ `--help` for details.
180
+
170
181
  ## `bdt pr watch-deploy`
171
182
 
172
183
  Many pipelines have a second build/stage that only runs on the *target*
@@ -0,0 +1,177 @@
1
+ """Azure DevOps auth: explicit PAT (`--pat` / AZURE_DEVOPS_EXT_PAT / AZURE_DEVOPS_PAT), or a token from
2
+ `DefaultAzureCredential` (see `azure_auth`)."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import base64
7
+ import re
8
+ from urllib.parse import parse_qs, urlparse
9
+
10
+ import requests
11
+
12
+ from .azure_auth import get_azure_token
13
+ from .pr_cancel import one_line
14
+ from .gitrepo import AdoRemote, current_remote
15
+
16
+ # Well-known Azure DevOps resource ID; `<id>/.default` is its AAD scope.
17
+ ADO_RESOURCE_ID = "499b84ac-1321-427f-aa17-267ca6975798"
18
+
19
+ PAT_SOURCES = "--pat / AZURE_DEVOPS_EXT_PAT / AZURE_DEVOPS_PAT"
20
+ # What a PAT needs for everything `bdt` does against Azure DevOps (PRs, builds, work items).
21
+ BDT_PAT_SCOPES = "Code (Read & write), Build (Read & execute), Work Items (Read & write)"
22
+
23
+ # REST API area -> the PAT scope a call into it needs at least
24
+ _SCOPE_BY_API = (
25
+ ("/_apis/build/", "Build (Read & execute)"),
26
+ ("/_apis/git/", "Code (Read & write)"),
27
+ ("/_apis/policy/", "Code (Read & write)"),
28
+ ("/_apis/wit/", "Work Items (Read & write)"),
29
+ ("/_apis/userentitlements/", "MemberEntitlement Management (Read)"),
30
+ ("/_apis/identities", "Identity (Read)"),
31
+ ("/_apis/graph/", "Graph (Read)"),
32
+ )
33
+ _ORG_RE = re.compile(r"^/([^/]+)")
34
+
35
+
36
+ class AdoAuthError(requests.HTTPError):
37
+ """Azure DevOps rejected the credentials (401), or accepted them but refuses the call (403): the message
38
+ already says which PAT scope / login to fix, so it is meant to be shown as is."""
39
+
40
+
41
+ def pat_settings_url(org: str | None) -> str:
42
+ if org:
43
+ return f"https://dev.azure.com/{org}/_usersSettings/tokens"
44
+ return "https://dev.azure.com/ (user settings > Personal access tokens)"
45
+
46
+
47
+ def _remote_org() -> str | None:
48
+ """The org of the current checkout's `origin`, if it is an Azure DevOps one (best effort: auth also fails
49
+ outside a checkout)."""
50
+ try:
51
+ remote = current_remote()
52
+ except Exception: # noqa: BLE001 -- not a git checkout / unknown remote: just no org to name
53
+ return None
54
+ return remote.org if isinstance(remote, AdoRemote) else None
55
+
56
+
57
+ def get_az_devops_token() -> str:
58
+ org = _remote_org()
59
+ hint = (
60
+ "No Azure DevOps credentials: no PAT was given (--pat, AZURE_DEVOPS_EXT_PAT and AZURE_DEVOPS_PAT are all unset) "
61
+ "and there is no usable `az login`.\n"
62
+ "Fix it with either:\n"
63
+ f" - a PAT: create one at {pat_settings_url(org)} (scopes: {BDT_PAT_SCOPES}), then "
64
+ "`export AZURE_DEVOPS_EXT_PAT=<token>` or pass --pat\n"
65
+ " - `az login` as a user with access to the organization"
66
+ )
67
+ return get_azure_token(f"{ADO_RESOURCE_ID}/.default", hint=hint)
68
+
69
+
70
+ def auth_header(pat: str | None) -> dict[str, str]:
71
+ """Basic-auth header for an explicit PAT, else Bearer via `DefaultAzureCredential`.
72
+
73
+ Never hardcode a PAT literal in a caller — pass it in from an env var
74
+ (e.g. AZURE_DEVOPS_EXT_PAT) or a CLI flag, or omit it and let azure-identity supply a
75
+ short-lived token from the operator's own login.
76
+ """
77
+ if pat:
78
+ token = base64.b64encode(f":{pat}".encode()).decode()
79
+ return {"Authorization": f"Basic {token}"}
80
+ return {"Authorization": f"Bearer {get_az_devops_token()}"}
81
+
82
+
83
+ def _ado_message(response: requests.Response) -> str | None:
84
+ try:
85
+ message = response.json().get("message")
86
+ except (ValueError, AttributeError):
87
+ return None
88
+ return one_line(message) if isinstance(message, str) and message.strip() else None
89
+
90
+
91
+ def _is_sign_in_url(url: str) -> bool:
92
+ return urlparse(url).path.rstrip("/").endswith("/_signin")
93
+
94
+
95
+ def _requested_url(response: requests.Response) -> str:
96
+ """The URL that was asked for. A rejected PAT is redirected to a sign-in page, which is what `response.url` is then
97
+ (and `response.history` is only filled in once the whole redirect chain is done, after the hook ran); the page
98
+ carries the original URL as `reply_to`."""
99
+ if response.history:
100
+ return response.history[0].url
101
+ if _is_sign_in_url(response.url):
102
+ reply_to = parse_qs(urlparse(response.url).query).get("reply_to")
103
+ if reply_to:
104
+ return reply_to[0]
105
+ return response.url
106
+
107
+
108
+ def auth_failure_message(response: requests.Response, pat_used: bool) -> str:
109
+ """Why `response` (a 401/403 from Azure DevOps) happened and how to fix it, for the credentials in use."""
110
+ parsed = urlparse(_requested_url(response))
111
+ org_match = _ORG_RE.match(parsed.path) if parsed.netloc == "dev.azure.com" else None
112
+ org = org_match.group(1) if org_match else _remote_org()
113
+ scope = next((s for api, s in _SCOPE_BY_API if api in parsed.path), None)
114
+ where = f"{parsed.scheme}://{parsed.netloc}{parsed.path}"
115
+ lines = []
116
+ if response.status_code == 403:
117
+ lines.append(f"Azure DevOps refused the call (HTTP 403) -- {where}")
118
+ else:
119
+ lines.append(f"Azure DevOps did not accept the credentials (HTTP 401) -- {where}")
120
+ says = _ado_message(response)
121
+ if says:
122
+ lines.append(f"Azure DevOps says: {says}")
123
+ if pat_used:
124
+ lines.append(f"Credentials: the PAT from {PAT_SOURCES}.")
125
+ causes: list[str] = ["it lacks the scope this call needs" + (f" ({scope})" if scope else "")]
126
+ if response.status_code != 403:
127
+ causes += ["it has expired or was revoked", "it was created for a different organization" + (f" than '{org}'" if org else "")]
128
+ else:
129
+ causes += ["your account itself lacks the permission"]
130
+ lines.append("Most likely " + ", or ".join(causes) + ".")
131
+ lines.append(f"Fix or recreate it at {pat_settings_url(org)} (scopes bdt needs: {BDT_PAT_SCOPES}).")
132
+ else:
133
+ lines.append("Credentials: your `az login` token (no PAT given).")
134
+ lines.append(
135
+ "Run `az login` as a user with access to " + (f"organization '{org}'" if org else "the organization")
136
+ + f", or use a PAT instead: create one at {pat_settings_url(org)} (scopes: {BDT_PAT_SCOPES}) and set AZURE_DEVOPS_EXT_PAT / pass --pat."
137
+ )
138
+ return "\n".join(lines)
139
+
140
+
141
+ def _is_sign_in_page(response: requests.Response) -> bool:
142
+ """Azure DevOps answers credentials it does not recognise by redirecting to a sign-in page (so 203, or 200 with
143
+ HTML) -- for its REST API, which otherwise only ever speaks JSON/text."""
144
+ if "/_apis/" not in _requested_url(response):
145
+ return False
146
+ if _is_sign_in_url(response.url):
147
+ return True
148
+ if response.status_code == 203:
149
+ return True
150
+ return response.status_code == 200 and "text/html" in response.headers.get("Content-Type", "")
151
+
152
+
153
+ def _check_auth_hook(pat_used: bool):
154
+ def hook(response: requests.Response, *args, **kwargs) -> requests.Response:
155
+ if _is_sign_in_page(response):
156
+ # one status for "not signed in", however Azure DevOps phrased it, so callers' `>= 400` checks agree
157
+ response.status_code = 401
158
+ if response.status_code in (401, 403):
159
+ error = AdoAuthError(auth_failure_message(response, pat_used), response=response)
160
+
161
+ def raise_for_status() -> None:
162
+ raise error
163
+
164
+ # replaces the generic "401 Client Error: Unauthorized for url" `raise_for_status` would raise
165
+ setattr(response, "raise_for_status", raise_for_status)
166
+ return response
167
+
168
+ return hook
169
+
170
+
171
+ def ado_session(pat: str | None) -> requests.Session:
172
+ """A `requests.Session` authenticated for Azure DevOps whose rejected calls fail with an `AdoAuthError`
173
+ (from `raise_for_status`) explaining which PAT / scope / login to fix, instead of a bare HTTP error."""
174
+ session = requests.Session()
175
+ session.headers.update(auth_header(pat))
176
+ session.hooks["response"].append(_check_auth_hook(bool(pat)))
177
+ return session
@@ -18,8 +18,9 @@ def _credential():
18
18
  return DefaultAzureCredential(process_timeout=CLI_TIMEOUT_SECS)
19
19
 
20
20
 
21
- def get_azure_token(scope: str) -> str:
22
- """A bearer token for `scope` (e.g. `https://management.azure.com/.default`)."""
21
+ def get_azure_token(scope: str, hint: str | None = None) -> str:
22
+ """A bearer token for `scope` (e.g. `https://management.azure.com/.default`). `hint` replaces the generic
23
+ "try `az login`" advice when the failing caller knows better (see `ado_auth`)."""
23
24
  try:
24
25
  from azure.core.exceptions import ClientAuthenticationError
25
26
  except ImportError: # pragma: no cover -- a declared dependency
@@ -27,4 +28,7 @@ def get_azure_token(scope: str) -> str:
27
28
  try:
28
29
  return _credential().get_token(scope).token
29
30
  except ClientAuthenticationError as e:
31
+ if hint:
32
+ # the credential chain's report lists every credential tried, one block each: the first line says it all
33
+ sys.exit(f"{hint}\n\n(azure-identity: {str(e).strip().splitlines()[0]})")
30
34
  sys.exit(f"Azure authentication failed (try `az login`, or set AZURE_DEVOPS_EXT_PAT for Azure DevOps):\n{e}")
@@ -35,8 +35,8 @@ from . import find_injection as find_injection_mod
35
35
  from . import lint as lint_mod
36
36
  from . import logs as logs_mod
37
37
  from . import translate as translate_mod
38
- from . import pr_build, pr_info as pr_info_mod, pr_issue_link, pr_merge_defaults, pr_ref, pr_labels, pull as pull_mod, worktree as worktree_mod
39
- from .ado_auth import auth_header
38
+ from . import pr_build, pr_cancel, pr_info as pr_info_mod, pr_issue_link, pr_merge_defaults, pr_ref, pr_labels, pull as pull_mod, worktree as worktree_mod
39
+ from .ado_auth import AdoAuthError, ado_session, auth_header
40
40
  from .bdt_config import find_pyproject, load_bdt_table
41
41
  from .cli_tools import CLI_TIMEOUT_SECS, EXIT_WAIT_TIMEOUT, detect_agent_session, require_gh
42
42
  from .github_api import GitHubClient
@@ -71,7 +71,18 @@ DEFAULT_TARGET_BRANCH = "dev"
71
71
  # `issue watch` on Azure DevOps without a PAT: re-fetch the short-lived Bearer token this often.
72
72
  ADO_TOKEN_REFRESH_SECS = 1800.0
73
73
 
74
- app = typer.Typer(
74
+ class _BdtTyper(typer.Typer):
75
+ """Shows an `AdoAuthError` (which says by itself what to fix) as plain text, not a traceback."""
76
+
77
+ def __call__(self, *args, **kwargs):
78
+ try:
79
+ return super().__call__(*args, **kwargs)
80
+ except AdoAuthError as e:
81
+ print(e, file=sys.stderr)
82
+ sys.exit(1)
83
+
84
+
85
+ app = _BdtTyper(
75
86
  name="bdt",
76
87
  help=f"Shared BMS developer tooling: PRs/builds (Azure DevOps or GitHub), worktrees, commits, logs (v{__version__})",
77
88
  )
@@ -161,8 +172,7 @@ def _resolve_ado_pr(pat: str | None, remote: AdoRemote, target: str | None, pr_i
161
172
  so this works even without that PR's branch checked out locally), else by searching for
162
173
  the current branch's PR into `target`, as before.
163
174
  """
164
- session = requests.Session()
165
- session.headers.update(auth_header(pat))
175
+ session = ado_session(pat)
166
176
  if pr_id is not None:
167
177
  pr = pr_build.get_pr_by_id(session, remote, pr_id)
168
178
  else:
@@ -174,7 +184,7 @@ def _current_pr_info(pr_id: int | None, target_branch: str | None, pat: str | No
174
184
  remote = current_remote()
175
185
  if isinstance(remote, GitHubRemote):
176
186
  gh = require_gh()
177
- return pr_info_mod.github_info(gh_pr.get_pr(gh, gh_pr.resolve_pr_id(gh, pr_id, target_branch), fields=gh_pr.PR_INFO_FIELDS), remote)
187
+ return pr_info_mod.github_info(gh_pr.get_pr(gh, gh_pr.resolve_pr_id(gh, pr_id, target_branch), fields=gh_pr.PR_INFO_FIELDS), remote, gh)
178
188
  session, pr = _resolve_ado_pr(pat, remote, target_branch, pr_id=pr_id)
179
189
  return pr_info_mod.ado_info(session, pr, remote)
180
190
 
@@ -185,11 +195,10 @@ def _open_prs_info(target_branch: str | None, pat: str | None) -> list[pr_info_m
185
195
  if isinstance(remote, GitHubRemote):
186
196
  gh = require_gh()
187
197
  return [
188
- pr_info_mod.github_info(gh_pr.get_pr(gh, number, fields=gh_pr.PR_INFO_FIELDS), remote)
198
+ pr_info_mod.github_info(gh_pr.get_pr(gh, number, fields=gh_pr.PR_INFO_FIELDS), remote, gh)
189
199
  for number in gh_pr.open_pr_numbers(gh, target_branch)
190
200
  ]
191
- session = requests.Session()
192
- session.headers.update(auth_header(pat))
201
+ session = ado_session(pat)
193
202
  return [pr_info_mod.ado_info(session, pr, remote) for pr in pr_build.get_active_prs(session, remote, current_branch(), target_branch)]
194
203
 
195
204
 
@@ -216,10 +225,9 @@ def _ref_pr_info(ref: pr_ref.PrRef, pat: str | None, clients: dict) -> pr_info_m
216
225
  clients["gh"] = require_gh()
217
226
  base = clients["gh"]
218
227
  gh = base if ref.remote is None else base.for_repo(remote.owner, remote.repo)
219
- return pr_info_mod.github_info(gh_pr.get_pr(gh, ref.pr_id, fields=gh_pr.PR_INFO_FIELDS), remote)
228
+ return pr_info_mod.github_info(gh_pr.get_pr(gh, ref.pr_id, fields=gh_pr.PR_INFO_FIELDS), remote, gh)
220
229
  if "session" not in clients:
221
- clients["session"] = requests.Session()
222
- clients["session"].headers.update(auth_header(pat))
230
+ clients["session"] = ado_session(pat)
223
231
  session = clients["session"]
224
232
  return pr_info_mod.ado_info(session, pr_build.get_pr_by_id(session, remote, ref.pr_id), remote)
225
233
 
@@ -474,8 +482,7 @@ def pr_create(
474
482
  remote,
475
483
  **{k: v for k, v in (("org", options.organization), ("project", options.ado_project), ("repo", options.repository)) if v},
476
484
  )
477
- session = requests.Session()
478
- session.headers.update(auth_header(pat))
485
+ session = ado_session(pat)
479
486
  if options.dry_run:
480
487
  body = pr_build.build_create_body(
481
488
  session, ado, source_branch, target, draft=draft, labels=label, title=title, description=description,
@@ -588,7 +595,12 @@ def pr_status(
588
595
  def _info_text(info: pr_info_mod.PrInfo, with_repo: bool = False) -> str:
589
596
  flags = ", ".join([info.state, *(["draft"] if info.draft else []), f"build: {info.build}"])
590
597
  name = f"PR {info.repo}#{info.number}" if with_repo and info.repo else f"PR #{info.number}"
591
- return "\n".join([f"{name}: {info.title} ({flags})", info.url, *(f"Issue #{i.number}: {i.url}" for i in info.issues)])
598
+ lines = [f"{name}: {info.title} ({flags})", info.url]
599
+ if info.abandon_reason:
600
+ lines.append(pr_cancel.abandoned_notice(pr_cancel.Reason(info.abandon_reason, info.abandon_session)))
601
+ if info.build == pr_info_mod.BUILD_CANCELLED:
602
+ lines.append(pr_cancel.cancelled_notice(pr_cancel.Reason(info.cancel_reason, info.cancel_session) if info.cancel_reason else None))
603
+ return "\n".join([*lines, *(f"Issue #{i.number}: {i.url}" for i in info.issues)])
592
604
 
593
605
 
594
606
  def _echo_infos(infos: list[pr_info_mod.PrInfo], as_json: bool, with_repo: bool) -> None:
@@ -689,6 +701,108 @@ def pr_retry(
689
701
  pr_build.retry(remote, pat, target_branch, pr_id=pr_id)
690
702
 
691
703
 
704
+ @pr_app.command("cancel-build")
705
+ def pr_cancel_build(
706
+ reason: str = typer.Option(
707
+ ...,
708
+ "--reason",
709
+ help=f"Why the build is cancelled. Posted on the PR as a '{pr_cancel.PREFIX} <reason>' comment, which `bdt pr info` / `bdt pr status` show",
710
+ ),
711
+ session: str | None = typer.Option(
712
+ None,
713
+ "--session",
714
+ help="Id or URL of the agent session (Claude, Codex, ...) that cancels, recorded in the comment and shown by `bdt pr info` / "
715
+ "`bdt pr status`. Default: the session bdt is running under, if it detects one",
716
+ ),
717
+ target_branch: str | None = typer.Option(None, "--target-branch", help=_LOOKUP_TARGET_HELP),
718
+ pr_id: int | None = typer.Option(None, "--pr-id", help=_PR_ID_HELP),
719
+ pat: str | None = typer.Option(
720
+ None,
721
+ "--pat",
722
+ envvar=["AZURE_DEVOPS_EXT_PAT", "AZURE_DEVOPS_PAT"],
723
+ help="Azure DevOps PAT (else uses DefaultAzureCredential, e.g. your `az login`)",
724
+ ),
725
+ ) -> None:
726
+ """Cancel the running build(s) of the PR opened from the current branch, or --pr-id directly
727
+ (Azure DevOps or GitHub, auto-detected), and record --reason on the PR. Queue it again with
728
+ `bdt pr requeue-build`.
729
+ """
730
+ if session is not None:
731
+ try:
732
+ pr_cancel.resolve_session(session)
733
+ except ValueError as e:
734
+ raise typer.BadParameter(str(e), param_hint="--session") from None
735
+ remote = current_remote()
736
+ if isinstance(remote, GitHubRemote):
737
+ gh = require_gh()
738
+ gh_pr.cancel(gh, reason, pr_id=gh_pr.resolve_pr_id(gh, pr_id, target_branch), session_id=session)
739
+ return
740
+ pr_build.cancel(remote, pat, target_branch, reason, pr_id=pr_id, session_id=session)
741
+
742
+
743
+ @pr_app.command("abandon")
744
+ def pr_abandon(
745
+ reason: str = typer.Option(
746
+ ...,
747
+ "--reason",
748
+ help=f"Why the PR is abandoned. Posted on the PR as an '{pr_cancel.ABANDON_PREFIX} <reason>' comment, which `bdt pr info` / `bdt pr status` show",
749
+ ),
750
+ session: str | None = typer.Option(
751
+ None,
752
+ "--session",
753
+ help="Id or URL of the agent session (Claude, Codex, ...) that abandons, recorded in the comment and shown by `bdt pr info` / "
754
+ "`bdt pr status`. Default: the session bdt is running under, if it detects one",
755
+ ),
756
+ target_branch: str | None = typer.Option(None, "--target-branch", help=_LOOKUP_TARGET_HELP),
757
+ pr_id: int | None = typer.Option(None, "--pr-id", help=_PR_ID_HELP),
758
+ pat: str | None = typer.Option(
759
+ None,
760
+ "--pat",
761
+ envvar=["AZURE_DEVOPS_EXT_PAT", "AZURE_DEVOPS_PAT"],
762
+ help="Azure DevOps PAT (else uses DefaultAzureCredential, e.g. your `az login`)",
763
+ ),
764
+ ) -> None:
765
+ """Abandon (Azure DevOps) / close (GitHub) the PR opened from the current branch, or --pr-id directly, and
766
+ record --reason on it. `bdt pr status --wait` stops on an abandoned PR instead of waiting for CI.
767
+ """
768
+ if session is not None:
769
+ try:
770
+ pr_cancel.resolve_session(session)
771
+ except ValueError as e:
772
+ raise typer.BadParameter(str(e), param_hint="--session") from None
773
+ remote = current_remote()
774
+ if isinstance(remote, GitHubRemote):
775
+ gh = require_gh()
776
+ gh_pr.abandon(gh, reason, pr_id=gh_pr.resolve_pr_id(gh, pr_id, target_branch), session_id=session)
777
+ return
778
+ pr_build.abandon(remote, pat, target_branch, reason, pr_id=pr_id, session_id=session)
779
+
780
+
781
+ @pr_app.command("requeue-build")
782
+ def pr_requeue_build(
783
+ include_succeeded: bool = typer.Option(False, "--all", help="Also requeue pipelines/workflows whose latest build succeeded (default: only cancelled or failed ones)"),
784
+ target_branch: str | None = typer.Option(None, "--target-branch", help=_LOOKUP_TARGET_HELP),
785
+ pr_id: int | None = typer.Option(None, "--pr-id", help=_PR_ID_HELP),
786
+ pat: str | None = typer.Option(
787
+ None,
788
+ "--pat",
789
+ envvar=["AZURE_DEVOPS_EXT_PAT", "AZURE_DEVOPS_PAT"],
790
+ help="Azure DevOps PAT (else uses DefaultAzureCredential, e.g. your `az login`)",
791
+ ),
792
+ ) -> None:
793
+ """Queue a new build for the PR opened from the current branch, or --pr-id directly (Azure DevOps or
794
+ GitHub, auto-detected): every pipeline whose latest build was cancelled or failed, run again from the start.
795
+ Unlike `bdt pr retry`, which re-runs only the failed stage(s)/job(s) of a failed build in place (and can't do
796
+ anything with a cancelled one).
797
+ """
798
+ remote = current_remote()
799
+ if isinstance(remote, GitHubRemote):
800
+ gh = require_gh()
801
+ gh_pr.requeue(gh, include_succeeded, pr_id=gh_pr.resolve_pr_id(gh, pr_id, target_branch))
802
+ return
803
+ pr_build.requeue(remote, pat, target_branch, include_succeeded, pr_id=pr_id)
804
+
805
+
692
806
  @pr_app.command("watch-deploy")
693
807
  def pr_watch_deploy(
694
808
  target_branch: str = typer.Option(DEFAULT_TARGET_BRANCH, "--target-branch", help="Branch to watch for a directly-triggered build/workflow run (e.g. a post-merge deployment pipeline)"),
@@ -874,8 +988,7 @@ def issue_create(
874
988
  parent=parent, blocked_by=blocked_by,
875
989
  )
876
990
  else:
877
- session = requests.Session()
878
- session.headers.update(auth_header(pat))
991
+ session = ado_session(pat)
879
992
  resolved_board = ado_issue.check_board(ado_issue.resolve_board(board), creating=True)
880
993
  ado_issue.create(
881
994
  session, remote, type_, title, description, resolved_board, tags_or_labels, screenshot, file,
@@ -1054,8 +1167,7 @@ def issue_search(
1054
1167
  )
1055
1168
  found = (_github_item_remote(items[0]) if org_wide else remote, items[0]["number"]) if items else None
1056
1169
  else:
1057
- session = requests.Session()
1058
- session.headers.update(auth_header(pat))
1170
+ session = ado_session(pat)
1059
1171
  resolved_board = ado_issue.resolve_board(board)
1060
1172
  if business_user:
1061
1173
  detector = detector or business_user_mod.BusinessUserDetector(session, remote, commit_depth)
@@ -1184,8 +1296,7 @@ def issue_do(
1184
1296
  if isinstance(remote, GitHubRemote):
1185
1297
  title, body = issue_do_mod.fetch_github(require_gh(), number)
1186
1298
  else:
1187
- session = requests.Session()
1188
- session.headers.update(auth_header(pat))
1299
+ session = ado_session(pat)
1189
1300
  title, body = issue_do_mod.fetch_ado(session, remote, number)
1190
1301
  extra = list(ctx.args)
1191
1302
  # claude can be given the session id up front, so the "Taken by" comment can link the session that will exist
@@ -1256,8 +1367,7 @@ def _take(
1256
1367
  def _last_comment(remote: AdoRemote | GitHubRemote, number: int, pat: str | None) -> str | None:
1257
1368
  if isinstance(remote, GitHubRemote):
1258
1369
  return gh_issue.last_comment(require_gh(), remote.owner, remote.repo, number)
1259
- session = requests.Session()
1260
- session.headers.update(auth_header(pat))
1370
+ session = ado_session(pat)
1261
1371
  return ado_issue.last_comment(session, remote, number)
1262
1372
 
1263
1373
 
@@ -1265,8 +1375,7 @@ def _comment_on_issue(remote: AdoRemote | GitHubRemote, number: int, message: st
1265
1375
  if isinstance(remote, GitHubRemote):
1266
1376
  gh_issue.comment(require_gh(), remote.owner, remote.repo, number, message, [], agent_note=agent_note)
1267
1377
  else:
1268
- session = requests.Session()
1269
- session.headers.update(auth_header(pat))
1378
+ session = ado_session(pat)
1270
1379
  ado_issue.comment_with_screenshots(session, remote, number, message, [], [], agent_note=agent_note)
1271
1380
 
1272
1381
 
@@ -1348,17 +1457,16 @@ def issue_watch(
1348
1457
  def fetch() -> list[issue_watch_mod.Comment]:
1349
1458
  return issue_watch_mod.to_comments(gh_issue.list_comments(gh, remote.owner, remote.repo, number))
1350
1459
  else:
1351
- ado_session = requests.Session()
1352
- ado_session.headers.update(auth_header(pat))
1460
+ watch_session = ado_session(pat)
1353
1461
  header_age = time.monotonic()
1354
1462
 
1355
1463
  def fetch() -> list[issue_watch_mod.Comment]:
1356
1464
  nonlocal header_age
1357
1465
  # A `az login` token lives about an hour, a `--follow` runs for longer; a PAT never expires mid-run
1358
1466
  if not pat and time.monotonic() - header_age > ADO_TOKEN_REFRESH_SECS:
1359
- ado_session.headers.update(auth_header(pat))
1467
+ watch_session.headers.update(auth_header(pat))
1360
1468
  header_age = time.monotonic()
1361
- return issue_watch_mod.to_comments(ado_issue.list_comments(ado_session, remote, number), is_html=True)
1469
+ return issue_watch_mod.to_comments(ado_issue.list_comments(watch_session, remote, number), is_html=True)
1362
1470
 
1363
1471
  own_session = detect_agent_session() if skip_own else None
1364
1472
  accept = issue_watch_mod.build_accept(
@@ -1416,8 +1524,7 @@ def issue_show(
1416
1524
  if isinstance(remote, GitHubRemote):
1417
1525
  details = gh_issue.get_details(require_gh(), remote.owner, remote.repo, number)
1418
1526
  else:
1419
- session = requests.Session()
1420
- session.headers.update(auth_header(pat))
1527
+ session = ado_session(pat)
1421
1528
  details = ado_issue.get_details(session, remote, number, business_user_mod.BusinessUserDetector(session, remote))
1422
1529
  typer.echo(issue_show_mod.format_details(details, as_json=as_json))
1423
1530
 
@@ -1490,8 +1597,7 @@ def issue_update(
1490
1597
  _reject_ado_only_options(iteration=iteration)
1491
1598
  gh_issue.update(require_gh(), number, title, description, tags_or_labels, removals, state, parent, blocked_by)
1492
1599
  else:
1493
- session = requests.Session()
1494
- session.headers.update(auth_header(pat))
1600
+ session = ado_session(pat)
1495
1601
  ado_issue.update(
1496
1602
  session, remote, number, title, description, ado_issue.check_board(board), tags_or_labels, removals, state,
1497
1603
  iteration=iteration, parent=parent, blocked_by=blocked_by,
@@ -1521,8 +1627,7 @@ def issue_delete(
1521
1627
  if isinstance(remote, GitHubRemote):
1522
1628
  gh_issue.delete(require_gh(), number)
1523
1629
  else:
1524
- session = requests.Session()
1525
- session.headers.update(auth_header(pat))
1630
+ session = ado_session(pat)
1526
1631
  ado_issue.delete(session, remote, number)
1527
1632
 
1528
1633
 
@@ -1557,8 +1662,7 @@ def issue_comment_add(
1557
1662
  if isinstance(remote, GitHubRemote):
1558
1663
  gh_issue.comment(require_gh(), remote.owner, remote.repo, number, message, screenshot, file)
1559
1664
  else:
1560
- session = requests.Session()
1561
- session.headers.update(auth_header(pat))
1665
+ session = ado_session(pat)
1562
1666
  ado_issue.comment_with_screenshots(session, remote, number, message, screenshot, file)
1563
1667
 
1564
1668
 
@@ -1579,8 +1683,7 @@ def issue_comment_update(
1579
1683
  if isinstance(remote, GitHubRemote):
1580
1684
  gh_issue.update_comment(require_gh(), remote.owner, remote.repo, str(comment_id), message)
1581
1685
  else:
1582
- session = requests.Session()
1583
- session.headers.update(auth_header(pat))
1686
+ session = ado_session(pat)
1584
1687
  ado_issue.update_comment(session, remote, number, comment_id, message)
1585
1688
 
1586
1689
 
@@ -1604,8 +1707,7 @@ def issue_comment_delete(
1604
1707
  if isinstance(remote, GitHubRemote):
1605
1708
  gh_issue.delete_comment(require_gh(), remote.owner, remote.repo, str(comment_id))
1606
1709
  else:
1607
- session = requests.Session()
1608
- session.headers.update(auth_header(pat))
1710
+ session = ado_session(pat)
1609
1711
  ado_issue.delete_comment(session, remote, number, comment_id)
1610
1712
 
1611
1713
 
@@ -1973,8 +2075,7 @@ def _draft_feat_pr(target: str | None, pat: str | None) -> None:
1973
2075
  if isinstance(remote, GitHubRemote):
1974
2076
  converted = gh_pr.set_draft(require_gh(), target=target)
1975
2077
  else:
1976
- session = requests.Session()
1977
- session.headers.update(auth_header(pat))
2078
+ session = ado_session(pat)
1978
2079
  pr = pr_build.get_pr(session, remote, current_branch(), target)
1979
2080
  converted = pr_build.set_draft(session, remote, pr)
1980
2081
  except (Exception, SystemExit):