bmsdna-devtools 0.58.0__tar.gz → 1.0.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.
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/.github/workflows/python-test.yml +2 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/PKG-INFO +13 -1
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/README.md +12 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/_api_dump.py +12 -6
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/ado_auth.py +15 -10
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/ado_issue.py +97 -30
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/agent_mentions.py +1 -2
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/api_usage.py +52 -20
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/app_service_logs.py +2 -3
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/azure_arm.py +6 -4
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/azure_auth.py +6 -2
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/business_user.py +12 -4
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/ci_plan.py +25 -89
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/ci_plan_env.py +11 -30
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/cli.py +520 -143
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/cli_tools.py +109 -17
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/commit.py +53 -20
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/dead_code.py +13 -6
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/deps/advisories.py +9 -14
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/deps/cli.py +15 -10
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/deps/cooldown.py +3 -3
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/deps/lockfiles.py +2 -2
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/deps/osv.py +3 -3
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/env_config.py +2 -5
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/find_injection.py +45 -27
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/find_repo.py +40 -14
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/gh_args.py +4 -5
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/gh_issue.py +38 -18
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/gh_pr.py +81 -35
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/github_api.py +18 -8
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/gitrepo.py +2 -8
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/injection_frontend.py +2 -2
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/injection_python.py +14 -5
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/issue_do.py +12 -6
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/issue_show.py +1 -1
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/issue_watch.py +32 -8
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/lint.py +11 -8
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/lint_models.py +5 -3
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/lint_sql.py +118 -42
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/lint_sql_files.py +6 -2
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/lint_tooling.py +20 -8
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/lint_typescript.py +15 -4
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/logs.py +9 -8
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/pr_build.py +181 -50
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/pr_cancel.py +1 -1
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/pr_create_args.py +3 -1
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/pr_drift.py +23 -12
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/pr_info.py +32 -13
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/pr_issue_link.py +19 -6
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/pr_labels.py +5 -4
- bmsdna_devtools-1.0.0/bmsdna/devtools/pr_list.py +95 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/pr_markdown.py +3 -1
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/pr_merge_defaults.py +6 -3
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/pr_ref.py +5 -3
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/pull.py +25 -9
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/testdb.py +8 -7
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/translate.py +9 -25
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/usage/cli.py +45 -15
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/usage/pipeline.py +46 -35
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/usage/report.py +197 -77
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/worktree.py +51 -23
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/justfile +7 -1
- bmsdna_devtools-1.0.0/prek.toml +31 -0
- bmsdna_devtools-1.0.0/pyproject.toml +114 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/skills/bmsdna-devtools/SKILL.md +1 -2
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/fake_github.py +8 -3
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_ado_auth.py +19 -6
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_ado_issue.py +50 -14
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_ado_issue_flow.py +78 -18
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_agent_mentions.py +7 -1
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_api_usage.py +46 -13
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_azure_arm.py +7 -2
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_business_user.py +47 -9
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_ci_plan.py +25 -86
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_ci_plan_env.py +19 -60
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_cli_cleanup.py +3 -1
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_cli_commit.py +17 -5
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_cli_issue.py +194 -21
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_cli_pr_create.py +58 -21
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_cli_pr_id.py +14 -5
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_commit.py +4 -1
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_deps_advisories.py +2 -2
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_env_config.py +2 -2
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_env_files.py +2 -2
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_find_injection.py +19 -6
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_find_repo.py +78 -20
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_gh_issue.py +109 -31
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_gh_pr.py +174 -40
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_github_api.py +7 -3
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_gitrepo.py +4 -1
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_issue_do.py +4 -1
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_issue_for_me.py +83 -24
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_issue_show.py +14 -3
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_issue_watch.py +14 -9
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_lint.py +3 -1
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_lint_models.py +10 -10
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_lint_sql.py +177 -161
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_lint_sql_files.py +13 -4
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_lint_typescript.py +9 -3
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_logs.py +1 -1
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_pr_build.py +22 -6
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_pr_build_create_options.py +22 -6
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_pr_build_flow.py +56 -22
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_pr_cancel_build.py +231 -52
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_pr_choice.py +41 -11
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_pr_create_args.py +20 -3
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_pr_description_not_truncated.py +34 -5
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_pr_drift.py +47 -11
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_pr_info.py +151 -30
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_pr_labels.py +3 -9
- bmsdna_devtools-1.0.0/tests/test_pr_list.py +174 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_pr_markdown.py +3 -1
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_pull.py +3 -1
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_testdb.py +21 -7
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_translate.py +2 -6
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_usage.py +288 -77
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_wait_timeout.py +279 -22
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_worktree_clean.py +46 -26
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/uv.lock +43 -43
- bmsdna_devtools-0.58.0/pyproject.toml +0 -56
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/.github/workflows/auto-release.yml +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/.github/workflows/python-publish.yml +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/.gitignore +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/.python-version +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/__init__.py +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/bdt_config.py +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/deps/__init__.py +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/deps/versions.py +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/env_files.py +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/lint_findings.py +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/pr_choice.py +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/usage/__init__.py +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/usage/pricing.py +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/usage/sql/00_schema.sql +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/usage/sql/01_ingest_claude.sql +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/usage/sql/01_ingest_codex.sql +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/usage/sql/02_messages.sql +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/usage/sql/03_markers.sql +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/usage/sql/04_facts.sql +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/bmsdna/devtools/usage/sql/05_views.sql +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/conftest.py +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_app_service_logs.py +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_bdt_config.py +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_cli_deps.py +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_cli_pull.py +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_cli_tools.py +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_cli_version.py +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_deps_cooldown.py +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_deps_lockfiles.py +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_deps_osv.py +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_deps_versions.py +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_lint_tooling.py +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_pr_issue_link.py +0 -0
- {bmsdna_devtools-0.58.0 → bmsdna_devtools-1.0.0}/tests/test_pr_merge_defaults.py +0 -0
|
@@ -30,6 +30,8 @@ jobs:
|
|
|
30
30
|
run: uv sync --all-extras --all-groups
|
|
31
31
|
- name: Lint (ruff)
|
|
32
32
|
run: uv run ruff check bmsdna tests
|
|
33
|
+
- name: Format check (ruff)
|
|
34
|
+
run: uv run ruff format --check bmsdna tests
|
|
33
35
|
- name: Type check (ty)
|
|
34
36
|
run: uv run ty check bmsdna
|
|
35
37
|
- name: Test with pytest
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: bmsdna-devtools
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 1.0.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
|
|
@@ -132,6 +132,18 @@ locally at all (it also settles which PR when several are open for the branch).
|
|
|
132
132
|
all accept the same option, for the same reason. (`pr watch-deploy` doesn't:
|
|
133
133
|
it watches a branch-triggered build/workflow run, not any particular PR.)
|
|
134
134
|
|
|
135
|
+
## `bdt pr list`
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
bdt pr list [--state open|merged|closed|all] [--limit N] [--json]
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
The active PRs of the current repo (Azure DevOps or GitHub), newest first: id, state, name (title) and tags
|
|
142
|
+
(labels), one per line: `#42 open (draft) feat: widgets [bug, test-full]`. Only open PRs unless `--state` says
|
|
143
|
+
otherwise (`open` = active; `closed` = abandoned, i.e. not merged); `--limit` defaults to 30. `--json` prints a list of
|
|
144
|
+
`{number, title, state, draft, labels, url}` (`[]` when there is none). No build or merge state per PR, as that
|
|
145
|
+
is a request each: `bdt pr info --pr-id N` has it.
|
|
146
|
+
|
|
135
147
|
## `bdt pr info`
|
|
136
148
|
|
|
137
149
|
```bash
|
|
@@ -113,6 +113,18 @@ locally at all (it also settles which PR when several are open for the branch).
|
|
|
113
113
|
all accept the same option, for the same reason. (`pr watch-deploy` doesn't:
|
|
114
114
|
it watches a branch-triggered build/workflow run, not any particular PR.)
|
|
115
115
|
|
|
116
|
+
## `bdt pr list`
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
bdt pr list [--state open|merged|closed|all] [--limit N] [--json]
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The active PRs of the current repo (Azure DevOps or GitHub), newest first: id, state, name (title) and tags
|
|
123
|
+
(labels), one per line: `#42 open (draft) feat: widgets [bug, test-full]`. Only open PRs unless `--state` says
|
|
124
|
+
otherwise (`open` = active; `closed` = abandoned, i.e. not merged); `--limit` defaults to 30. `--json` prints a list of
|
|
125
|
+
`{number, title, state, draft, labels, url}` (`[]` when there is none). No build or merge state per PR, as that
|
|
126
|
+
is a request each: `bdt pr info --pr-id N` has it.
|
|
127
|
+
|
|
116
128
|
## `bdt pr info`
|
|
117
129
|
|
|
118
130
|
```bash
|
|
@@ -10,13 +10,15 @@ ship its own top-level `bmsdna` package (CCMT2 does) that would shadow ours. `ap
|
|
|
10
10
|
import importlib
|
|
11
11
|
import json
|
|
12
12
|
import sys
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
from typing import Any
|
|
13
15
|
|
|
14
16
|
HTTP_METHODS = ("get", "post", "put", "patch", "delete", "options", "head")
|
|
15
17
|
|
|
16
18
|
|
|
17
|
-
def ops_from_doc(doc, mount=""):
|
|
19
|
+
def ops_from_doc(doc: dict[str, Any], mount: str = "") -> list[dict[str, Any]]:
|
|
18
20
|
"""Operations of one OpenAPI document as dicts, with `mount` prepended to every path."""
|
|
19
|
-
ops = []
|
|
21
|
+
ops: list[dict[str, Any]] = []
|
|
20
22
|
for path, item in (doc.get("paths") or {}).items():
|
|
21
23
|
for method, op in item.items():
|
|
22
24
|
if method in HTTP_METHODS and isinstance(op, dict):
|
|
@@ -32,7 +34,7 @@ def ops_from_doc(doc, mount=""):
|
|
|
32
34
|
return ops
|
|
33
35
|
|
|
34
36
|
|
|
35
|
-
def collect(app, mount=""):
|
|
37
|
+
def collect(app: Any, mount: str = "") -> list[dict[str, Any]]:
|
|
36
38
|
"""Operations of `app` and, recursively, of every mounted sub-app. Uses only `app.openapi()` and the
|
|
37
39
|
`.path`/`.app` attributes of mount routes -- not FastAPI internals, which change between releases (FastAPI 0.141 wraps
|
|
38
40
|
included routers in lazy objects that `app.routes` no longer lists as plain routes)."""
|
|
@@ -42,15 +44,19 @@ def collect(app, mount=""):
|
|
|
42
44
|
ops = ops_from_doc(openapi(), mount)
|
|
43
45
|
for route in getattr(app, "routes", None) or []:
|
|
44
46
|
sub = getattr(route, "app", None)
|
|
45
|
-
if
|
|
47
|
+
if (
|
|
48
|
+
sub is not None
|
|
49
|
+
and callable(getattr(sub, "openapi", None))
|
|
50
|
+
and isinstance(getattr(route, "path", None), str)
|
|
51
|
+
):
|
|
46
52
|
ops.extend(collect(sub, mount + route.path.rstrip("/")))
|
|
47
53
|
return ops
|
|
48
54
|
|
|
49
55
|
|
|
50
|
-
def main(argv):
|
|
56
|
+
def main(argv: list[str]) -> None:
|
|
51
57
|
module_name, _, attr = argv[0].partition(":")
|
|
52
58
|
app = getattr(importlib.import_module(module_name), attr)
|
|
53
|
-
with
|
|
59
|
+
with Path(argv[1]).open("w", encoding="utf-8") as out:
|
|
54
60
|
json.dump(collect(app), out)
|
|
55
61
|
|
|
56
62
|
|
|
@@ -5,13 +5,14 @@ from __future__ import annotations
|
|
|
5
5
|
|
|
6
6
|
import base64
|
|
7
7
|
import re
|
|
8
|
+
from collections.abc import Callable
|
|
8
9
|
from urllib.parse import parse_qs, urlparse
|
|
9
10
|
|
|
10
11
|
import requests
|
|
11
12
|
|
|
12
|
-
from .azure_auth import get_azure_token
|
|
13
|
-
from .
|
|
14
|
-
from .
|
|
13
|
+
from bmsdna.devtools.azure_auth import get_azure_token
|
|
14
|
+
from bmsdna.devtools.gitrepo import AdoRemote, current_remote
|
|
15
|
+
from bmsdna.devtools.pr_cancel import one_line
|
|
15
16
|
|
|
16
17
|
# Well-known Azure DevOps resource ID; `<id>/.default` is its AAD scope.
|
|
17
18
|
ADO_RESOURCE_ID = "499b84ac-1321-427f-aa17-267ca6975798"
|
|
@@ -49,7 +50,7 @@ def _remote_org() -> str | None:
|
|
|
49
50
|
outside a checkout)."""
|
|
50
51
|
try:
|
|
51
52
|
remote = current_remote()
|
|
52
|
-
except Exception:
|
|
53
|
+
except Exception:
|
|
53
54
|
return None
|
|
54
55
|
return remote.org if isinstance(remote, AdoRemote) else None
|
|
55
56
|
|
|
@@ -83,7 +84,7 @@ def auth_header(pat: str | None) -> dict[str, str]:
|
|
|
83
84
|
def _ado_message(response: requests.Response) -> str | None:
|
|
84
85
|
try:
|
|
85
86
|
message = response.json().get("message")
|
|
86
|
-
except
|
|
87
|
+
except ValueError, AttributeError:
|
|
87
88
|
return None
|
|
88
89
|
return one_line(message) if isinstance(message, str) and message.strip() else None
|
|
89
90
|
|
|
@@ -124,7 +125,10 @@ def auth_failure_message(response: requests.Response, pat_used: bool) -> str:
|
|
|
124
125
|
lines.append(f"Credentials: the PAT from {PAT_SOURCES}.")
|
|
125
126
|
causes: list[str] = ["it lacks the scope this call needs" + (f" ({scope})" if scope else "")]
|
|
126
127
|
if response.status_code != 403:
|
|
127
|
-
causes += [
|
|
128
|
+
causes += [
|
|
129
|
+
"it has expired or was revoked",
|
|
130
|
+
"it was created for a different organization" + (f" than '{org}'" if org else ""),
|
|
131
|
+
]
|
|
128
132
|
else:
|
|
129
133
|
causes += ["your account itself lacks the permission"]
|
|
130
134
|
lines.append("Most likely " + ", or ".join(causes) + ".")
|
|
@@ -132,7 +136,8 @@ def auth_failure_message(response: requests.Response, pat_used: bool) -> str:
|
|
|
132
136
|
else:
|
|
133
137
|
lines.append("Credentials: your `az login` token (no PAT given).")
|
|
134
138
|
lines.append(
|
|
135
|
-
"Run `az login` as a user with access to "
|
|
139
|
+
"Run `az login` as a user with access to "
|
|
140
|
+
+ (f"organization '{org}'" if org else "the organization")
|
|
136
141
|
+ 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
142
|
)
|
|
138
143
|
return "\n".join(lines)
|
|
@@ -150,8 +155,8 @@ def _is_sign_in_page(response: requests.Response) -> bool:
|
|
|
150
155
|
return response.status_code == 200 and "text/html" in response.headers.get("Content-Type", "")
|
|
151
156
|
|
|
152
157
|
|
|
153
|
-
def _check_auth_hook(pat_used: bool):
|
|
154
|
-
def hook(response: requests.Response, *args, **kwargs) -> requests.Response:
|
|
158
|
+
def _check_auth_hook(pat_used: bool) -> Callable[..., requests.Response]:
|
|
159
|
+
def hook(response: requests.Response, *args: object, **kwargs: object) -> requests.Response:
|
|
155
160
|
if _is_sign_in_page(response):
|
|
156
161
|
# one status for "not signed in", however Azure DevOps phrased it, so callers' `>= 400` checks agree
|
|
157
162
|
response.status_code = 401
|
|
@@ -162,7 +167,7 @@ def _check_auth_hook(pat_used: bool):
|
|
|
162
167
|
raise error
|
|
163
168
|
|
|
164
169
|
# replaces the generic "401 Client Error: Unauthorized for url" `raise_for_status` would raise
|
|
165
|
-
|
|
170
|
+
response.raise_for_status = raise_for_status
|
|
166
171
|
return response
|
|
167
172
|
|
|
168
173
|
return hook
|
|
@@ -49,14 +49,14 @@ from urllib.parse import quote
|
|
|
49
49
|
|
|
50
50
|
import requests
|
|
51
51
|
|
|
52
|
-
from .bdt_config import load_bdt_table
|
|
53
|
-
from .business_user import BusinessUserDetector
|
|
54
|
-
from .cli_tools import ensure_agent_session_note
|
|
55
|
-
from .gitrepo import AdoRemote
|
|
56
|
-
from .issue_show import IssueDetails
|
|
57
|
-
from .issue_watch import html_to_text, to_comments
|
|
58
|
-
from .pr_issue_link import PR_AVAILABLE_LABEL
|
|
59
|
-
from .pr_markdown import build_comment_content_html
|
|
52
|
+
from bmsdna.devtools.bdt_config import load_bdt_table
|
|
53
|
+
from bmsdna.devtools.business_user import BusinessUserDetector
|
|
54
|
+
from bmsdna.devtools.cli_tools import ensure_agent_session_note
|
|
55
|
+
from bmsdna.devtools.gitrepo import AdoRemote
|
|
56
|
+
from bmsdna.devtools.issue_show import IssueDetails
|
|
57
|
+
from bmsdna.devtools.issue_watch import html_to_text, to_comments
|
|
58
|
+
from bmsdna.devtools.pr_issue_link import PR_AVAILABLE_LABEL
|
|
59
|
+
from bmsdna.devtools.pr_markdown import build_comment_content_html
|
|
60
60
|
|
|
61
61
|
COMMENTS_API_VERSION = "7.1-preview.4"
|
|
62
62
|
|
|
@@ -95,7 +95,9 @@ def check_board(board: str | None, start: Path | None = None, *, creating: bool
|
|
|
95
95
|
allowed = config.get("allowed_boards", [])
|
|
96
96
|
# An explicitly configured but empty list is a misconfiguration, not "no restriction" — silently
|
|
97
97
|
# allowing every board would defeat the point of having configured an allowlist.
|
|
98
|
-
if "allowed_boards" in config and (
|
|
98
|
+
if "allowed_boards" in config and (
|
|
99
|
+
not isinstance(allowed, list) or not allowed or not all(isinstance(a, str) for a in allowed)
|
|
100
|
+
):
|
|
99
101
|
sys.exit("[tool.bdt.ado].allowed_boards in pyproject.toml must be a non-empty list of board/team names.")
|
|
100
102
|
require = config.get("require_board", False)
|
|
101
103
|
if not isinstance(require, bool):
|
|
@@ -109,7 +111,9 @@ def check_board(board: str | None, start: Path | None = None, *, creating: bool
|
|
|
109
111
|
if board and allowed:
|
|
110
112
|
match = next((a for a in allowed if a.casefold() == board.casefold()), None)
|
|
111
113
|
if match is None:
|
|
112
|
-
sys.exit(
|
|
114
|
+
sys.exit(
|
|
115
|
+
f"Board '{board}' isn't allowed here (see [tool.bdt.ado].allowed_boards). Allowed boards: {', '.join(allowed)}."
|
|
116
|
+
)
|
|
113
117
|
return match
|
|
114
118
|
return board
|
|
115
119
|
|
|
@@ -129,7 +133,9 @@ def get_team_area_path(session: requests.Session, remote: AdoRemote, team: str)
|
|
|
129
133
|
params={"api-version": "7.1"},
|
|
130
134
|
)
|
|
131
135
|
if r.status_code == 404:
|
|
132
|
-
sys.exit(
|
|
136
|
+
sys.exit(
|
|
137
|
+
f"Board/team '{team}' not found in project '{remote.project}'. Check --board / [tool.bdt.ado].board in pyproject.toml."
|
|
138
|
+
)
|
|
133
139
|
r.raise_for_status()
|
|
134
140
|
return r.json()["defaultValue"]
|
|
135
141
|
|
|
@@ -194,18 +200,34 @@ def build_relation_ops(
|
|
|
194
200
|
current = [(i, rel) for i, rel in enumerate(existing) if rel.get("rel") == PARENT_REL]
|
|
195
201
|
if not any(_relation_target_id(rel) == parent for _, rel in current):
|
|
196
202
|
ops += [{"op": "remove", "path": f"/relations/{i}"} for i, _ in reversed(current)]
|
|
197
|
-
ops.append(
|
|
203
|
+
ops.append(
|
|
204
|
+
{
|
|
205
|
+
"op": "add",
|
|
206
|
+
"path": "/relations/-",
|
|
207
|
+
"value": {"rel": PARENT_REL, "url": _work_item_api_url(remote, parent)},
|
|
208
|
+
}
|
|
209
|
+
)
|
|
198
210
|
already_blocked_by = {_relation_target_id(rel) for rel in existing if rel.get("rel") == BLOCKED_BY_REL}
|
|
199
211
|
for blocker in dict.fromkeys(blocked_by or []):
|
|
200
212
|
if blocker not in already_blocked_by:
|
|
201
|
-
ops.append(
|
|
213
|
+
ops.append(
|
|
214
|
+
{
|
|
215
|
+
"op": "add",
|
|
216
|
+
"path": "/relations/-",
|
|
217
|
+
"value": {"rel": BLOCKED_BY_REL, "url": _work_item_api_url(remote, blocker)},
|
|
218
|
+
}
|
|
219
|
+
)
|
|
202
220
|
return ops
|
|
203
221
|
|
|
204
222
|
|
|
205
223
|
def build_attach_ops(images: list[tuple[str, str]]) -> list[dict]:
|
|
206
224
|
"""The JSON Patch document body for linking already-uploaded attachments via 'AttachedFile' relations."""
|
|
207
225
|
return [
|
|
208
|
-
{
|
|
226
|
+
{
|
|
227
|
+
"op": "add",
|
|
228
|
+
"path": "/relations/-",
|
|
229
|
+
"value": {"rel": "AttachedFile", "url": url, "attributes": {"comment": name}},
|
|
230
|
+
}
|
|
209
231
|
for name, url in images
|
|
210
232
|
]
|
|
211
233
|
|
|
@@ -276,7 +298,9 @@ def update_work_item(
|
|
|
276
298
|
) -> dict:
|
|
277
299
|
ops = build_update_ops(title, description, area_path, tags, state, iteration_path, relation_ops)
|
|
278
300
|
if not ops:
|
|
279
|
-
sys.exit(
|
|
301
|
+
sys.exit(
|
|
302
|
+
"Nothing to update — provide at least one of --title, --description, --board, --iteration, --tag, --state, --parent, --blocked-by."
|
|
303
|
+
)
|
|
280
304
|
|
|
281
305
|
r = session.patch(
|
|
282
306
|
f"{_base_url(remote)}/_apis/wit/workitems/{work_item_id}",
|
|
@@ -415,7 +439,9 @@ def delete_work_item(session: requests.Session, remote: AdoRemote, work_item_id:
|
|
|
415
439
|
r.raise_for_status()
|
|
416
440
|
|
|
417
441
|
|
|
418
|
-
def upload_attachment(
|
|
442
|
+
def upload_attachment(
|
|
443
|
+
session: requests.Session, remote: AdoRemote, attachment_name: str, file_path: str
|
|
444
|
+
) -> tuple[str, str]:
|
|
419
445
|
"""Upload `file_path` as a work item attachment named `attachment_name`; returns (id, download url).
|
|
420
446
|
|
|
421
447
|
Azure DevOps' WIT attachment-download endpoint only infers Content-Type/Content-Disposition
|
|
@@ -452,7 +478,9 @@ def _upload_attachments(session: requests.Session, remote: AdoRemote, paths: lis
|
|
|
452
478
|
]
|
|
453
479
|
|
|
454
480
|
|
|
455
|
-
def link_attachments(
|
|
481
|
+
def link_attachments(
|
|
482
|
+
session: requests.Session, remote: AdoRemote, work_item_id: int, images: list[tuple[str, str]]
|
|
483
|
+
) -> None:
|
|
456
484
|
"""Link already-uploaded attachments to a work item so they show up in its Attachments tab."""
|
|
457
485
|
ops = build_attach_ops(images)
|
|
458
486
|
r = session.patch(
|
|
@@ -581,7 +609,9 @@ def add_attachments(
|
|
|
581
609
|
)
|
|
582
610
|
|
|
583
611
|
|
|
584
|
-
def add_screenshots(
|
|
612
|
+
def add_screenshots(
|
|
613
|
+
session: requests.Session, remote: AdoRemote, work_item_id: int, screenshot_paths: list[str]
|
|
614
|
+
) -> None:
|
|
585
615
|
"""Upload+link screenshots as attachments, then post a comment embedding them as HTML `<img>` tags."""
|
|
586
616
|
add_attachments(session, remote, work_item_id, screenshot_paths=screenshot_paths)
|
|
587
617
|
|
|
@@ -677,8 +707,7 @@ def build_search_wiql(
|
|
|
677
707
|
f"([System.Title] Contains Words '{_escape_wiql_string(k)}' OR [System.Description] Contains Words '{_escape_wiql_string(k)}')"
|
|
678
708
|
for k in keywords
|
|
679
709
|
]
|
|
680
|
-
for tag in tags or []
|
|
681
|
-
clauses.append(f"[System.Tags] Contains '{_escape_wiql_string(tag)}'")
|
|
710
|
+
clauses.extend(f"[System.Tags] Contains '{_escape_wiql_string(tag)}'" for tag in tags or [])
|
|
682
711
|
if since:
|
|
683
712
|
clauses.append(f"[System.ChangedDate] >= '{since}T00:00:00Z'")
|
|
684
713
|
if area_path:
|
|
@@ -742,7 +771,11 @@ _COMMENT_FILTER_POOL = 200
|
|
|
742
771
|
|
|
743
772
|
|
|
744
773
|
def _filter_by_last_comment(
|
|
745
|
-
session: requests.Session,
|
|
774
|
+
session: requests.Session,
|
|
775
|
+
remote: AdoRemote,
|
|
776
|
+
items: list[dict],
|
|
777
|
+
top: int,
|
|
778
|
+
comment_filter: Callable[[str | None], bool],
|
|
746
779
|
) -> list[dict]:
|
|
747
780
|
"""The first `top` of `items` (in order) whose newest comment `comment_filter` accepts. An
|
|
748
781
|
item from another project (org-wide search) is looked up in its own project."""
|
|
@@ -794,7 +827,13 @@ def search(
|
|
|
794
827
|
area_path = get_team_area_path(session, remote, board) if board else None
|
|
795
828
|
wiql = build_search_wiql(keywords, since, area_path, state, org_wide=org_wide, tags=tags)
|
|
796
829
|
filtered = comment_filter or business_users
|
|
797
|
-
ids = run_wiql(
|
|
830
|
+
ids = run_wiql(
|
|
831
|
+
session,
|
|
832
|
+
remote,
|
|
833
|
+
wiql,
|
|
834
|
+
min((scan_limit or top) * 10, _COMMENT_FILTER_POOL) if filtered else top,
|
|
835
|
+
org_wide=org_wide,
|
|
836
|
+
)
|
|
798
837
|
items = get_work_items(session, remote, ids, org_wide=org_wide, with_creator=business_users is not None)
|
|
799
838
|
if business_users:
|
|
800
839
|
items = [i for i in items if business_users.verdict(i["fields"].get("System.CreatedBy")).business_user]
|
|
@@ -830,7 +869,9 @@ def create(
|
|
|
830
869
|
area_path = get_team_area_path(session, remote, board) if board else None
|
|
831
870
|
description = ensure_agent_session_note(description, also_check=title)
|
|
832
871
|
relation_ops = build_relation_ops(remote, parent, blocked_by)
|
|
833
|
-
work_item = create_work_item(
|
|
872
|
+
work_item = create_work_item(
|
|
873
|
+
session, remote, work_item_type, title, description, area_path, tags, iteration, relation_ops
|
|
874
|
+
)
|
|
834
875
|
work_item_id = work_item["id"]
|
|
835
876
|
|
|
836
877
|
print(f"Created {work_item_type} #{work_item_id}: {title}")
|
|
@@ -904,8 +945,13 @@ def update(
|
|
|
904
945
|
has_tag_change = tags is not None or bool(remove_tags)
|
|
905
946
|
has_link_change = parent is not None or bool(blocked_by)
|
|
906
947
|
if (
|
|
907
|
-
title is None
|
|
908
|
-
and
|
|
948
|
+
title is None
|
|
949
|
+
and description is None
|
|
950
|
+
and area_path is None
|
|
951
|
+
and iteration is None
|
|
952
|
+
and not has_tag_change
|
|
953
|
+
and not has_link_change
|
|
954
|
+
and applied_state is None
|
|
909
955
|
):
|
|
910
956
|
if state is not None:
|
|
911
957
|
print(f"Work item #{work_item_id}: '{state}' isn't a valid state here — noted in a comment.")
|
|
@@ -919,7 +965,9 @@ def update(
|
|
|
919
965
|
if has_link_change:
|
|
920
966
|
if work_item_id == parent or work_item_id in (blocked_by or []):
|
|
921
967
|
sys.exit(f"Work item #{work_item_id} can't be linked to itself.")
|
|
922
|
-
relation_ops = build_relation_ops(
|
|
968
|
+
relation_ops = build_relation_ops(
|
|
969
|
+
remote, parent, blocked_by, get_work_item(session, remote, work_item_id).get("relations")
|
|
970
|
+
)
|
|
923
971
|
|
|
924
972
|
if remove_tags:
|
|
925
973
|
removal_set = {t.casefold() for t in remove_tags}
|
|
@@ -932,16 +980,33 @@ def update(
|
|
|
932
980
|
filtered_tags = [t for t in current_tags if t.casefold() not in removal_set]
|
|
933
981
|
if filtered_tags != current_tags:
|
|
934
982
|
tags = filtered_tags
|
|
935
|
-
elif
|
|
983
|
+
elif (
|
|
984
|
+
title is None
|
|
985
|
+
and description is None
|
|
986
|
+
and area_path is None
|
|
987
|
+
and iteration is None
|
|
988
|
+
and applied_state is None
|
|
989
|
+
and not relation_ops
|
|
990
|
+
):
|
|
936
991
|
# None of `remove_tags` were actually present, and nothing else was given either --
|
|
937
992
|
# mirrors `add_tag`'s own idempotency check (same file) so this doesn't needlessly
|
|
938
993
|
# bump the work item's revision/history with a same-value System.Tags PATCH.
|
|
939
|
-
print(
|
|
994
|
+
print(
|
|
995
|
+
f"Work item #{work_item_id}: none of the given --remove-tag value(s) were present — nothing to do."
|
|
996
|
+
)
|
|
940
997
|
return None
|
|
941
998
|
# else: leave `tags` as None -- other given fields still get their own ops below,
|
|
942
999
|
# without forcing a redundant, unchanged System.Tags op alongside them.
|
|
943
1000
|
|
|
944
|
-
if
|
|
1001
|
+
if (
|
|
1002
|
+
title is None
|
|
1003
|
+
and description is None
|
|
1004
|
+
and area_path is None
|
|
1005
|
+
and iteration is None
|
|
1006
|
+
and tags is None
|
|
1007
|
+
and applied_state is None
|
|
1008
|
+
and not relation_ops
|
|
1009
|
+
):
|
|
945
1010
|
# only --parent / --blocked-by were given, and the work item already has those links
|
|
946
1011
|
if state is not None:
|
|
947
1012
|
print(f"Work item #{work_item_id}: '{state}' isn't a valid state here — noted in a comment.")
|
|
@@ -951,7 +1016,9 @@ def update(
|
|
|
951
1016
|
if description is not None:
|
|
952
1017
|
description = ensure_agent_session_note(description, also_check=title)
|
|
953
1018
|
|
|
954
|
-
work_item = update_work_item(
|
|
1019
|
+
work_item = update_work_item(
|
|
1020
|
+
session, remote, work_item_id, title, description, area_path, tags, applied_state, iteration, relation_ops
|
|
1021
|
+
)
|
|
955
1022
|
print(f"Updated work item #{work_item_id}")
|
|
956
1023
|
return work_item
|
|
957
1024
|
|
|
@@ -34,8 +34,7 @@ _ENV_PREFIXES: tuple[tuple[str, str], ...] = (
|
|
|
34
34
|
def normalize_agent(name: str) -> str:
|
|
35
35
|
"""The mention handle for an agent name or tag: 'Claude' / 'claude-code_2-1_agent' -> 'claude',
|
|
36
36
|
'Codex CLI' -> 'codex', '@Goose' -> 'goose'."""
|
|
37
|
-
|
|
38
|
-
return tag
|
|
37
|
+
return re.split(r"[\s_-]+", name.strip().lstrip("@").lower(), maxsplit=1)[0]
|
|
39
38
|
|
|
40
39
|
|
|
41
40
|
def detect_agent(env: Mapping[str, str] | None = None, override: str | None = None) -> str | None:
|
|
@@ -44,10 +44,10 @@ from dataclasses import dataclass, field
|
|
|
44
44
|
from fnmatch import fnmatch
|
|
45
45
|
from pathlib import Path
|
|
46
46
|
|
|
47
|
-
from . import _api_dump
|
|
48
|
-
from .lint import _DEFAULT_EXCLUDE_DIR_NAMES, _iter_files
|
|
49
|
-
from .lint_findings import Finding
|
|
50
|
-
from .lint_typescript import _mask, is_excluded_ts_file
|
|
47
|
+
from bmsdna.devtools import _api_dump
|
|
48
|
+
from bmsdna.devtools.lint import _DEFAULT_EXCLUDE_DIR_NAMES, _iter_files
|
|
49
|
+
from bmsdna.devtools.lint_findings import Finding
|
|
50
|
+
from bmsdna.devtools.lint_typescript import _mask, is_excluded_ts_file
|
|
51
51
|
|
|
52
52
|
RULE = "api-route-uncalled"
|
|
53
53
|
RULE_STALE_BASELINE = "api-route-baseline-stale"
|
|
@@ -63,7 +63,9 @@ _TEST_DIR_NAMES = frozenset({"tests", "test", "__tests__"})
|
|
|
63
63
|
_TEST_FILE_RE = re.compile(r"^(?:test_.*|.*_test|conftest)\.py$")
|
|
64
64
|
DEFAULT_URL_FOR_FUNCTIONS = ("url_for", "url_path_for")
|
|
65
65
|
_APP_IMPORT_TIMEOUT_SECONDS = 300
|
|
66
|
-
_MAX_TEMPLATE_CHARS =
|
|
66
|
+
_MAX_TEMPLATE_CHARS = (
|
|
67
|
+
4000 # a URL template longer than this is not a URL; also bounds the rescan of an unclosed backtick
|
|
68
|
+
)
|
|
67
69
|
_MAX_TEMPLATE_DEPTH = 20
|
|
68
70
|
|
|
69
71
|
# Bounded character classes keep these linear on garbage input (a lone `'${` must not scan to end of file).
|
|
@@ -72,7 +74,9 @@ _TEMPLATE_START_RE = re.compile(r"`(?=(?:\$\{[^}`\n]*\})*/)")
|
|
|
72
74
|
_FETCH_METHOD_RE = re.compile(r"\.(GET|POST|PUT|PATCH|DELETE)\s*(?:<[^()]*?>)?\(\s*$")
|
|
73
75
|
_IDENT_RE = re.compile(r"[A-Za-z_$][\w$]*")
|
|
74
76
|
_SDK_FN_RE = re.compile(r"export const (\w+) = ")
|
|
75
|
-
_SDK_URL_RE = re.compile(
|
|
77
|
+
_SDK_URL_RE = re.compile(
|
|
78
|
+
r"""\.(get|post|put|patch|delete|head|options)\b[^;]{0,4000}?url:\s*["']([^"']+)["']""", re.DOTALL
|
|
79
|
+
)
|
|
76
80
|
|
|
77
81
|
|
|
78
82
|
class ApiUsageError(Exception):
|
|
@@ -119,9 +123,12 @@ def load_app_operations(app_spec: str, *, cwd: Path, env: dict[str, str] | None
|
|
|
119
123
|
text=True,
|
|
120
124
|
encoding="utf-8",
|
|
121
125
|
timeout=_APP_IMPORT_TIMEOUT_SECONDS,
|
|
126
|
+
check=False,
|
|
122
127
|
)
|
|
123
128
|
except subprocess.TimeoutExpired as exc:
|
|
124
|
-
raise ApiUsageError(
|
|
129
|
+
raise ApiUsageError(
|
|
130
|
+
f"importing '{app_spec}' took longer than {_APP_IMPORT_TIMEOUT_SECONDS}s (cwd {cwd})"
|
|
131
|
+
) from exc
|
|
125
132
|
if proc.returncode != 0 or not out.is_file():
|
|
126
133
|
tail = "\n".join((proc.stderr or proc.stdout).strip().splitlines()[-15:])
|
|
127
134
|
raise ApiUsageError(f"could not load operations from '{app_spec}' (cwd {cwd}):\n{tail}")
|
|
@@ -194,7 +201,9 @@ class FrontendUsage:
|
|
|
194
201
|
identifiers: set[str] = field(default_factory=set)
|
|
195
202
|
fetch_calls: set[tuple[str, str]] = field(default_factory=set) # (METHOD, normalized path) from `.GET("/x"`
|
|
196
203
|
literals: set[str] = field(default_factory=set) # normalized path-like string/template literals
|
|
197
|
-
suffix_literals: set[str] = field(
|
|
204
|
+
suffix_literals: set[str] = field(
|
|
205
|
+
default_factory=set
|
|
206
|
+
) # literals usable for url-sfx matching (derived, see scan_frontend)
|
|
198
207
|
|
|
199
208
|
|
|
200
209
|
@dataclass(slots=True)
|
|
@@ -226,8 +235,10 @@ def scan_frontend(files: list[Path]) -> FrontendUsage:
|
|
|
226
235
|
usage.files += 1
|
|
227
236
|
usage.identifiers.update(_IDENT_RE.findall(text))
|
|
228
237
|
found: list[tuple[int, str]] = [(m.start(), m.group("body")) for m in _QUOTED_PATH_RE.finditer(text)]
|
|
229
|
-
|
|
230
|
-
|
|
238
|
+
found.extend(
|
|
239
|
+
(m.start(), _read_template(text, m.start(), min(len(text), m.start() + _MAX_TEMPLATE_CHARS))[0])
|
|
240
|
+
for m in _TEMPLATE_START_RE.finditer(text)
|
|
241
|
+
)
|
|
231
242
|
for pos, body in found:
|
|
232
243
|
normalized = normalize_path(body)
|
|
233
244
|
call = _FETCH_METHOD_RE.search(text[max(0, pos - 40) : pos])
|
|
@@ -253,7 +264,7 @@ def read_sdk_functions(directory: Path) -> dict[str, tuple[str, str]]:
|
|
|
253
264
|
if "sdk.gen.ts" not in filenames:
|
|
254
265
|
continue
|
|
255
266
|
text = Path(dirpath, "sdk.gen.ts").read_text(encoding="utf-8", errors="ignore")
|
|
256
|
-
for chunk in re.split(r"(?=^export const \w+ = )", text, flags=re.
|
|
267
|
+
for chunk in re.split(r"(?=^export const \w+ = )", text, flags=re.MULTILINE):
|
|
257
268
|
name, url = _SDK_FN_RE.match(chunk), _SDK_URL_RE.search(chunk)
|
|
258
269
|
if name and url:
|
|
259
270
|
functions[name.group(1)] = (url.group(1).upper(), normalize_path(url.group(2)))
|
|
@@ -272,7 +283,9 @@ def read_referenced_route_names(directory: Path, functions: tuple[str, ...] = DE
|
|
|
272
283
|
"""Route names passed as a string literal to one of `functions` (`request.url_for("x")`, `app.url_path_for(name="x")`,
|
|
273
284
|
`{{ url_for('x', id=1) }}`) in the non-test Python files and templates under `directory`. A mounted sub-app's
|
|
274
285
|
`"mount:x"` yields `x`. Regex based, so a call in a comment counts too (that only ever hides a dead route, never invents one)."""
|
|
275
|
-
pattern = re.compile(
|
|
286
|
+
pattern = re.compile(
|
|
287
|
+
r"\b(?:" + "|".join(map(re.escape, functions)) + r")\(\s*(?:\w+\s*=\s*)?(['\"])(?P<name>[^'\"\n]+)\1"
|
|
288
|
+
)
|
|
276
289
|
files, _ = _iter_files([directory], _EXCLUDE_DIR_NAMES | _TEST_DIR_NAMES, _NAME_SOURCE_SUFFIXES)
|
|
277
290
|
names: set[str] = set()
|
|
278
291
|
for path in files:
|
|
@@ -291,7 +304,8 @@ def is_named_by(op: Operation, names: set[str]) -> bool:
|
|
|
291
304
|
return False
|
|
292
305
|
path = op.path[len(op.mount) :] if op.mount and op.path.startswith(op.mount) else op.path
|
|
293
306
|
return any(
|
|
294
|
-
op.operation_id in (n, re.sub(r"\W", "_", n + path) + "_" + op.method.lower())
|
|
307
|
+
op.operation_id in (n, re.sub(r"\W", "_", n + path) + "_" + op.method.lower())
|
|
308
|
+
or op.operation_id.endswith("-" + n)
|
|
295
309
|
for n in names
|
|
296
310
|
)
|
|
297
311
|
|
|
@@ -371,7 +385,9 @@ def parse_config(table: dict) -> list[AppConfig]:
|
|
|
371
385
|
for i, raw in enumerate(apps):
|
|
372
386
|
name = str(raw.get("name") or raw.get("app") or raw.get("openapi") or f"app{i}")
|
|
373
387
|
if bool(raw.get("app")) == bool(raw.get("openapi")):
|
|
374
|
-
raise ApiUsageError(
|
|
388
|
+
raise ApiUsageError(
|
|
389
|
+
f"dead_code app '{name}': set exactly one of `app` (module:attr) and `openapi` (path to openapi.json)"
|
|
390
|
+
)
|
|
375
391
|
frontends = _str_list(raw, "frontends", name)
|
|
376
392
|
if not frontends:
|
|
377
393
|
raise ApiUsageError(f"dead_code app '{name}': `frontends` (list of frontend source dirs/globs) is required")
|
|
@@ -415,11 +431,17 @@ def _resolve_frontend_dirs(repo_root: Path, patterns: list[str]) -> list[Path]:
|
|
|
415
431
|
def read_baseline(path: Path) -> set[str]:
|
|
416
432
|
if not path.is_file():
|
|
417
433
|
return set()
|
|
418
|
-
return {
|
|
434
|
+
return {
|
|
435
|
+
line.strip()
|
|
436
|
+
for line in path.read_text(encoding="utf-8").splitlines()
|
|
437
|
+
if line.strip() and not line.lstrip().startswith("#")
|
|
438
|
+
}
|
|
419
439
|
|
|
420
440
|
|
|
421
441
|
def write_baseline(path: Path, keys: list[str]) -> None:
|
|
422
|
-
header =
|
|
442
|
+
header = (
|
|
443
|
+
"# Backend operations known to be unused (bdt dead-code). Remove a line once the route is deleted or called.\n"
|
|
444
|
+
)
|
|
423
445
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
424
446
|
path.write_text(header + "".join(f"{k}\n" for k in sorted(keys)), encoding="utf-8")
|
|
425
447
|
|
|
@@ -445,11 +467,17 @@ def check_app(config: AppConfig, *, repo_root: Path, update_baseline: bool = Fal
|
|
|
445
467
|
]
|
|
446
468
|
|
|
447
469
|
def excluded(op: Operation) -> bool:
|
|
448
|
-
return is_excluded(
|
|
470
|
+
return is_excluded(
|
|
471
|
+
op, prefixes=config.exclude_prefixes, tags=config.exclude_tags, path_globs=config.exclude_paths
|
|
472
|
+
)
|
|
449
473
|
|
|
450
474
|
names = read_referenced_route_names(repo_root / config.app_dir, tuple(config.url_for_functions))
|
|
451
475
|
by_key = {op.key: op for op in operations}
|
|
452
|
-
uncalled = [
|
|
476
|
+
uncalled = [
|
|
477
|
+
op
|
|
478
|
+
for op in operations
|
|
479
|
+
if not excluded(op) and call_evidence(op, frontends) is None and not is_named_by(op, names)
|
|
480
|
+
]
|
|
453
481
|
where = Path(config.name)
|
|
454
482
|
|
|
455
483
|
if not config.baseline:
|
|
@@ -488,13 +516,17 @@ def _finding(where: Path, op: Operation) -> Finding:
|
|
|
488
516
|
|
|
489
517
|
def run(table: dict, *, repo_root: Path, update_baseline: bool = False) -> list[Finding]:
|
|
490
518
|
configs = parse_config(table)
|
|
491
|
-
if
|
|
519
|
+
if (
|
|
520
|
+
update_baseline
|
|
521
|
+
): # validate everything first so a late failure can't leave some baselines rewritten and others not
|
|
492
522
|
paths = [c.baseline for c in configs]
|
|
493
523
|
if not all(paths):
|
|
494
524
|
missing = ", ".join(c.name for c in configs if not c.baseline)
|
|
495
525
|
raise ApiUsageError(f"--update-baseline needs a `baseline` for every app; missing for: {missing}")
|
|
496
526
|
if len(set(paths)) != len(paths):
|
|
497
|
-
raise ApiUsageError(
|
|
527
|
+
raise ApiUsageError(
|
|
528
|
+
"--update-baseline: two apps share the same `baseline` file, each would overwrite the other"
|
|
529
|
+
)
|
|
498
530
|
findings: list[Finding] = []
|
|
499
531
|
for config in configs:
|
|
500
532
|
findings.extend(check_app(config, repo_root=repo_root, update_baseline=update_baseline))
|
|
@@ -17,7 +17,7 @@ from urllib.parse import quote, urlparse
|
|
|
17
17
|
|
|
18
18
|
import requests
|
|
19
19
|
|
|
20
|
-
from . import azure_arm
|
|
20
|
+
from bmsdna.devtools import azure_arm
|
|
21
21
|
|
|
22
22
|
# Matches common error/warning markers across granian, uvicorn, and python tracebacks.
|
|
23
23
|
ERROR_RE = re.compile(r"\b(ERROR|CRITICAL|WARNING|Traceback|Exception|\b[45]\d\d\b|FAILED|FATAL)\b")
|
|
@@ -32,8 +32,7 @@ def download_logs(webapp: str, resource_group: str, slot: str | None, archive: p
|
|
|
32
32
|
try:
|
|
33
33
|
sub = azure_arm.default_subscription_id()
|
|
34
34
|
site = (
|
|
35
|
-
f"/subscriptions/{sub}/resourceGroups/{quote(resource_group)}"
|
|
36
|
-
f"/providers/Microsoft.Web/sites/{quote(webapp)}"
|
|
35
|
+
f"/subscriptions/{sub}/resourceGroups/{quote(resource_group)}/providers/Microsoft.Web/sites/{quote(webapp)}"
|
|
37
36
|
)
|
|
38
37
|
if slot:
|
|
39
38
|
site += f"/slots/{quote(slot)}"
|