bmsdna-devtools 0.54.0__tar.gz → 0.55.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.54.0 → bmsdna_devtools-0.55.0}/PKG-INFO +20 -2
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/README.md +19 -1
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/cli.py +6 -1
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/gh_pr.py +1 -1
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/pr_build.py +35 -1
- bmsdna_devtools-0.55.0/bmsdna/devtools/pr_drift.py +153 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/pr_info.py +43 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/pyproject.toml +1 -1
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/skills/bmsdna-devtools/SKILL.md +8 -1
- bmsdna_devtools-0.55.0/tests/test_pr_drift.py +353 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_pr_info.py +4 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/uv.lock +2 -2
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/.github/workflows/auto-release.yml +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/.github/workflows/python-publish.yml +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/.github/workflows/python-test.yml +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/.gitignore +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/.python-version +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/__init__.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/_api_dump.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/ado_auth.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/ado_issue.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/agent_mentions.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/api_usage.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/app_service_logs.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/azure_arm.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/azure_auth.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/bdt_config.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/business_user.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/ci_plan.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/ci_plan_env.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/cli_tools.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/commit.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/dead_code.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/deps/__init__.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/deps/advisories.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/deps/cli.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/deps/lockfiles.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/deps/osv.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/deps/versions.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/env_config.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/env_files.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/find_injection.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/find_repo.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/gh_args.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/gh_issue.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/github_api.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/gitrepo.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/injection_frontend.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/injection_python.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/issue_do.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/issue_show.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/issue_watch.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/lint.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/lint_findings.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/lint_models.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/lint_sql.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/lint_sql_files.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/lint_tooling.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/lint_typescript.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/logs.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/pr_cancel.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/pr_choice.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/pr_create_args.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/pr_issue_link.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/pr_labels.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/pr_markdown.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/pr_merge_defaults.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/pr_ref.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/pull.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/testdb.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/translate.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/usage/__init__.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/usage/cli.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/usage/pipeline.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/usage/pricing.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/usage/report.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/usage/sql/00_schema.sql +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/usage/sql/01_ingest_claude.sql +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/usage/sql/01_ingest_codex.sql +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/usage/sql/02_messages.sql +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/usage/sql/03_markers.sql +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/usage/sql/04_facts.sql +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/usage/sql/05_views.sql +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/bmsdna/devtools/worktree.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/justfile +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/conftest.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/fake_github.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_ado_auth.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_ado_issue.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_ado_issue_flow.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_agent_mentions.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_api_usage.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_app_service_logs.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_azure_arm.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_bdt_config.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_business_user.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_ci_plan.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_ci_plan_env.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_cli_cleanup.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_cli_commit.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_cli_deps.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_cli_issue.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_cli_pr_create.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_cli_pr_id.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_cli_pull.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_cli_tools.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_cli_version.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_commit.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_deps_advisories.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_deps_lockfiles.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_deps_osv.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_deps_versions.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_env_config.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_env_files.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_find_injection.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_find_repo.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_gh_issue.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_gh_pr.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_github_api.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_gitrepo.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_issue_do.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_issue_for_me.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_issue_show.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_issue_watch.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_lint.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_lint_models.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_lint_sql.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_lint_sql_files.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_lint_tooling.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_lint_typescript.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_logs.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_pr_build.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_pr_build_create_options.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_pr_build_flow.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_pr_cancel_build.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_pr_choice.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_pr_create_args.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_pr_description_not_truncated.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_pr_issue_link.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_pr_labels.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_pr_markdown.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_pr_merge_defaults.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_pull.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_testdb.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_translate.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_usage.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.0}/tests/test_wait_timeout.py +0 -0
- {bmsdna_devtools-0.54.0 → bmsdna_devtools-0.55.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.
|
|
3
|
+
Version: 0.55.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
|
|
@@ -82,6 +82,18 @@ for builds/checks that will never run — e.g. on Azure DevOps:
|
|
|
82
82
|
on GitHub: `PR #42 ('feat: widgets') has merge conflicts with 'main' (mergeable=CONFLICTING)`.
|
|
83
83
|
Exit code 1 either way.
|
|
84
84
|
|
|
85
|
+
On Azure DevOps that status is only as current as the PR's last push: it is never recomputed when the **target
|
|
86
|
+
branch** moves on, so a PR can say `succeeded` while the target has since changed the same lines (and its builds ran
|
|
87
|
+
on the old merge). `pr status` therefore also compares the target's tip with the commit the merge status was
|
|
88
|
+
computed against; if they differ it fetches both by commit id and merges them locally with `git merge-tree` (no
|
|
89
|
+
working-tree change, no branch or tag created; the answer is cached in `.git/bdt-merge-check.json` per commit). A
|
|
90
|
+
conflict is reported like the server's, exit 1: `PR #42 ('feat: widgets') has merge conflicts with 'dev' (mergeStatus=succeeded
|
|
91
|
+
is stale: 'dev' has moved on by 3 commits since it was computed). Conflicting: a.txt. Merge or rebase 'dev' into the branch and push.`
|
|
92
|
+
A target that moved without conflicts is a one-line `Note:`. This runs at the start and on every poll of `--wait` (one
|
|
93
|
+
cheap request each, the merge itself only when the target moved again), so a conflict that appears while CI runs
|
|
94
|
+
stops the wait. It needs a checkout of the repo (without one the note says the target moved but not whether it
|
|
95
|
+
conflicts) and is skipped quietly if Azure DevOps or git can't answer. GitHub recomputes `mergeable` itself.
|
|
96
|
+
|
|
85
97
|
With `--wait`, a build/check that's paused on a manual approval (an Azure
|
|
86
98
|
Pipelines stage's Checkpoint.Approval, or a GitHub Actions deployment
|
|
87
99
|
protection rule) ends the wait instead of polling forever — it prints which
|
|
@@ -137,7 +149,7 @@ from the latest build of each pipeline (any failed result fails it; unfinished b
|
|
|
137
149
|
`--all` lists every open PR from the current branch (e.g. one into `dev` and one into `main`, which plain
|
|
138
150
|
`bdt pr info` refuses to pick between): with `--json` an array of the same objects, `[]` (exit 0) when there is
|
|
139
151
|
none; `--target-branch` narrows it, `--pr-id` can't be combined with it. Only open PRs are listed, and a PR with
|
|
140
|
-
merge conflicts is listed like any other (plain `pr info` on Azure DevOps errors on
|
|
152
|
+
merge conflicts is listed like any other, with `merge: conflicts` (plain `pr info` on Azure DevOps errors on one the server already reports).
|
|
141
153
|
|
|
142
154
|
`--pr-id` takes several PRs, also of other repos: repeat it and/or comma-separate (`--pr-id 12,34 --pr-id owner/repo#5`).
|
|
143
155
|
Each entry is a bare number (a PR of the current repo), `owner/repo#N` (GitHub), `project/repo#N` or
|
|
@@ -152,6 +164,12 @@ every org, and a PR with merge conflicts is an error entry there.
|
|
|
152
164
|
|
|
153
165
|
Every JSON object has a `repo` (`owner/repo` on GitHub, `org/project/repo` on Azure DevOps).
|
|
154
166
|
|
|
167
|
+
It also says whether the PR still merges into its `target` branch: `merge` is `clean`, `conflicts` (with the
|
|
168
|
+
`conflicts` paths when known), `behind` (the target moved on, but it still merges; `target_behind` = by how many
|
|
169
|
+
commits), `unknown` (it moved on and couldn't be checked, see `bdt pr status`) or `none` (not an open PR). On
|
|
170
|
+
Azure DevOps this is the drift check of `bdt pr status`, which is why `merge` can say `conflicts` while the server
|
|
171
|
+
still reports `succeeded`; on GitHub it is `mergeable`.
|
|
172
|
+
|
|
155
173
|
Azure DevOps limits: the PR is found by the current branch (into `--target-branch` if given, else any target),
|
|
156
174
|
a PR with merge conflicts is reported as an error (exit 1) like `pr status` does, and the closed
|
|
157
175
|
work items are only those whose URL is in the PR description -- not ones linked via
|
|
@@ -63,6 +63,18 @@ for builds/checks that will never run — e.g. on Azure DevOps:
|
|
|
63
63
|
on GitHub: `PR #42 ('feat: widgets') has merge conflicts with 'main' (mergeable=CONFLICTING)`.
|
|
64
64
|
Exit code 1 either way.
|
|
65
65
|
|
|
66
|
+
On Azure DevOps that status is only as current as the PR's last push: it is never recomputed when the **target
|
|
67
|
+
branch** moves on, so a PR can say `succeeded` while the target has since changed the same lines (and its builds ran
|
|
68
|
+
on the old merge). `pr status` therefore also compares the target's tip with the commit the merge status was
|
|
69
|
+
computed against; if they differ it fetches both by commit id and merges them locally with `git merge-tree` (no
|
|
70
|
+
working-tree change, no branch or tag created; the answer is cached in `.git/bdt-merge-check.json` per commit). A
|
|
71
|
+
conflict is reported like the server's, exit 1: `PR #42 ('feat: widgets') has merge conflicts with 'dev' (mergeStatus=succeeded
|
|
72
|
+
is stale: 'dev' has moved on by 3 commits since it was computed). Conflicting: a.txt. Merge or rebase 'dev' into the branch and push.`
|
|
73
|
+
A target that moved without conflicts is a one-line `Note:`. This runs at the start and on every poll of `--wait` (one
|
|
74
|
+
cheap request each, the merge itself only when the target moved again), so a conflict that appears while CI runs
|
|
75
|
+
stops the wait. It needs a checkout of the repo (without one the note says the target moved but not whether it
|
|
76
|
+
conflicts) and is skipped quietly if Azure DevOps or git can't answer. GitHub recomputes `mergeable` itself.
|
|
77
|
+
|
|
66
78
|
With `--wait`, a build/check that's paused on a manual approval (an Azure
|
|
67
79
|
Pipelines stage's Checkpoint.Approval, or a GitHub Actions deployment
|
|
68
80
|
protection rule) ends the wait instead of polling forever — it prints which
|
|
@@ -118,7 +130,7 @@ from the latest build of each pipeline (any failed result fails it; unfinished b
|
|
|
118
130
|
`--all` lists every open PR from the current branch (e.g. one into `dev` and one into `main`, which plain
|
|
119
131
|
`bdt pr info` refuses to pick between): with `--json` an array of the same objects, `[]` (exit 0) when there is
|
|
120
132
|
none; `--target-branch` narrows it, `--pr-id` can't be combined with it. Only open PRs are listed, and a PR with
|
|
121
|
-
merge conflicts is listed like any other (plain `pr info` on Azure DevOps errors on
|
|
133
|
+
merge conflicts is listed like any other, with `merge: conflicts` (plain `pr info` on Azure DevOps errors on one the server already reports).
|
|
122
134
|
|
|
123
135
|
`--pr-id` takes several PRs, also of other repos: repeat it and/or comma-separate (`--pr-id 12,34 --pr-id owner/repo#5`).
|
|
124
136
|
Each entry is a bare number (a PR of the current repo), `owner/repo#N` (GitHub), `project/repo#N` or
|
|
@@ -133,6 +145,12 @@ every org, and a PR with merge conflicts is an error entry there.
|
|
|
133
145
|
|
|
134
146
|
Every JSON object has a `repo` (`owner/repo` on GitHub, `org/project/repo` on Azure DevOps).
|
|
135
147
|
|
|
148
|
+
It also says whether the PR still merges into its `target` branch: `merge` is `clean`, `conflicts` (with the
|
|
149
|
+
`conflicts` paths when known), `behind` (the target moved on, but it still merges; `target_behind` = by how many
|
|
150
|
+
commits), `unknown` (it moved on and couldn't be checked, see `bdt pr status`) or `none` (not an open PR). On
|
|
151
|
+
Azure DevOps this is the drift check of `bdt pr status`, which is why `merge` can say `conflicts` while the server
|
|
152
|
+
still reports `succeeded`; on GitHub it is `mergeable`.
|
|
153
|
+
|
|
136
154
|
Azure DevOps limits: the PR is found by the current branch (into `--target-branch` if given, else any target),
|
|
137
155
|
a PR with merge conflicts is reported as an error (exit 1) like `pr status` does, and the closed
|
|
138
156
|
work items are only those whose URL is in the PR description -- not ones linked via
|
|
@@ -595,9 +595,14 @@ def pr_status(
|
|
|
595
595
|
|
|
596
596
|
|
|
597
597
|
def _info_text(info: pr_info_mod.PrInfo, with_repo: bool = False) -> str:
|
|
598
|
-
|
|
598
|
+
merge = [f"merge: {info.merge}"] if info.merge not in (pr_info_mod.MERGE_CLEAN, pr_info_mod.MERGE_NONE) else []
|
|
599
|
+
flags = ", ".join([info.state, *(["draft"] if info.draft else []), f"build: {info.build}", *merge])
|
|
599
600
|
name = f"PR {info.repo}#{info.number}" if with_repo and info.repo else f"PR #{info.number}"
|
|
600
601
|
lines = [f"{name}: {info.title} ({flags})", info.url]
|
|
602
|
+
if info.merge == pr_info_mod.MERGE_CONFLICTS:
|
|
603
|
+
lines.append(f"Conflicts with '{info.target}'" + (f": {', '.join(info.conflicts)}" if info.conflicts else ""))
|
|
604
|
+
elif info.merge in (pr_info_mod.MERGE_BEHIND, pr_info_mod.MERGE_UNKNOWN) and info.target_behind:
|
|
605
|
+
lines.append(f"'{info.target}' moved on by {info.target_behind} commit{'s' * (info.target_behind != 1)} since the PR's last merge check")
|
|
601
606
|
if info.abandon_reason:
|
|
602
607
|
lines.append(pr_cancel.abandoned_notice(pr_cancel.Reason(info.abandon_reason, info.abandon_session)))
|
|
603
608
|
if info.build == pr_info_mod.BUILD_CANCELLED:
|
|
@@ -48,7 +48,7 @@ from .pr_markdown import build_attachments_section, build_comment_content, build
|
|
|
48
48
|
# (needed for the draft mutations), `body` the PR description.
|
|
49
49
|
PR_VIEW_FIELDS = "number,title,baseRefName,headRefName,mergeable,statusCheckRollup,isDraft,state"
|
|
50
50
|
# What `bdt pr info` needs on top of the check rollup: where to link to, and the issues GitHub says it closes.
|
|
51
|
-
PR_INFO_FIELDS = "number,title,url,state,isDraft,closingIssuesReferences,statusCheckRollup"
|
|
51
|
+
PR_INFO_FIELDS = "number,title,url,state,isDraft,mergeable,baseRefName,closingIssuesReferences,statusCheckRollup"
|
|
52
52
|
|
|
53
53
|
# GitHub has no API for uploading images to a PR description (only the web
|
|
54
54
|
# UI's drag-and-drop, which needs a browser session). The standard
|
|
@@ -15,7 +15,7 @@ from .ado_auth import AdoAuthError, ado_session
|
|
|
15
15
|
from .cli_tools import EXIT_NEEDS_APPROVAL, HTTP_TIMEOUT_SECS, PollHeartbeat, WaitDeadline, detect_agent_session, ensure_agent_session_note, exit_wait_timeout, is_claude_code, status_rerun_cmd
|
|
16
16
|
from .gitrepo import AdoRemote, current_branch, head_commit_subject
|
|
17
17
|
from .pr_create_args import PrCreateOptions
|
|
18
|
-
from . import pr_cancel
|
|
18
|
+
from . import pr_cancel, pr_drift
|
|
19
19
|
from .pr_choice import PrCandidate, choose_pr
|
|
20
20
|
from .pr_markdown import build_attachments_section, build_comment_content, build_screenshots_section
|
|
21
21
|
|
|
@@ -152,6 +152,32 @@ def merge_conflict_message(pr: dict) -> str | None:
|
|
|
152
152
|
return f"PR #{pr_id} ({title!r}) {detail} (mergeStatus={merge_status})"
|
|
153
153
|
|
|
154
154
|
|
|
155
|
+
def target_tip(session: requests.Session, remote: AdoRemote, target: str) -> str | None:
|
|
156
|
+
"""The commit branch `target` points at now; None if there is no such branch."""
|
|
157
|
+
r = session.get(
|
|
158
|
+
f"{_base_url(remote)}/_apis/git/repositories/{quote(remote.repo, safe='')}/refs",
|
|
159
|
+
params={"filter": f"heads/{target}", "api-version": "7.1"},
|
|
160
|
+
timeout=HTTP_TIMEOUT_SECS,
|
|
161
|
+
)
|
|
162
|
+
r.raise_for_status()
|
|
163
|
+
return next((ref["objectId"] for ref in r.json().get("value", []) if ref.get("name") == f"refs/heads/{target}"), None)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def target_drift(session: requests.Session, remote: AdoRemote, pr: dict) -> pr_drift.Drift | None:
|
|
167
|
+
"""`pr_drift.check` for `pr`: has its target branch moved since Azure DevOps computed `mergeStatus`, and does it still merge?
|
|
168
|
+
Raises `requests.RequestException` when the target's tip can't be looked up: callers decide what "unknown" means for them."""
|
|
169
|
+
moved = pr_drift.moved_target(pr)
|
|
170
|
+
return pr_drift.check(remote, pr, target_tip(session, remote, moved[0])) if moved else None
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def target_drift_or_none(session: requests.Session, remote: AdoRemote, pr: dict) -> pr_drift.Drift | None:
|
|
174
|
+
"""`target_drift`, best effort like `has_build_policy`: an extra check mustn't fail a status, so None when it can't be made."""
|
|
175
|
+
try:
|
|
176
|
+
return target_drift(session, remote, pr)
|
|
177
|
+
except requests.RequestException:
|
|
178
|
+
return None
|
|
179
|
+
|
|
180
|
+
|
|
155
181
|
def draft_notice(pr: dict) -> str | None:
|
|
156
182
|
"""None if the PR isn't a draft; else a heads-up that it is.
|
|
157
183
|
|
|
@@ -1225,6 +1251,7 @@ def run(
|
|
|
1225
1251
|
baseline_completed_ids[def_id] = max(baseline_completed_ids.get(def_id, 0), b["id"])
|
|
1226
1252
|
|
|
1227
1253
|
draft_notice_shown = False
|
|
1254
|
+
drift_notice_shown: str | None = None
|
|
1228
1255
|
policy_checked = False
|
|
1229
1256
|
heartbeat = PollHeartbeat()
|
|
1230
1257
|
deadline = WaitDeadline(timeout)
|
|
@@ -1243,6 +1270,13 @@ def run(
|
|
|
1243
1270
|
pr_number = pr["pullRequestId"]
|
|
1244
1271
|
pr_title = pr.get("title", "?")
|
|
1245
1272
|
pr_status = pr.get("status", "?")
|
|
1273
|
+
# every poll, so a target that moves mid-wait is noticed too; one cheap request, the merge itself only when something changed
|
|
1274
|
+
drift = target_drift_or_none(session, remote, pr)
|
|
1275
|
+
if drift and drift.conflicting:
|
|
1276
|
+
sys.exit(pr_drift.conflict_message(pr, drift))
|
|
1277
|
+
if drift and (drift_msg := pr_drift.notice(drift)) != drift_notice_shown:
|
|
1278
|
+
print(("\n" if wait else "") + drift_msg)
|
|
1279
|
+
drift_notice_shown = drift_msg
|
|
1246
1280
|
if pr_status == "abandoned":
|
|
1247
1281
|
# nothing will ever build for it: say so (and why) instead of polling on with --wait
|
|
1248
1282
|
print(f"PR #{pr_number}: {pr_title} ({pr_status})")
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"""Target-branch drift of an Azure DevOps PR: does it still merge now that its target moved on?
|
|
2
|
+
|
|
3
|
+
Azure DevOps computes a PR's `mergeStatus` (and the merge commit its builds run on) once per push to the
|
|
4
|
+
*source* branch and never again when the *target* branch gains commits, so a PR can report `succeeded` for
|
|
5
|
+
weeks while the target has since changed the same lines. `check` notices that (the target's tip is not the
|
|
6
|
+
`lastMergeTargetCommit` the status was computed against) and merges the two locally with `git merge-tree`,
|
|
7
|
+
which touches neither the working tree nor any ref. GitHub recomputes `mergeable` itself, so needs none of this.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import json
|
|
13
|
+
import re
|
|
14
|
+
import subprocess
|
|
15
|
+
from dataclasses import dataclass
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
from .cli_tools import CLI_TIMEOUT_SECS
|
|
19
|
+
from .gitrepo import AdoRemote, UnknownRemoteError, current_remote
|
|
20
|
+
|
|
21
|
+
# Fetching objects over the network is slower than the metadata calls `CLI_TIMEOUT_SECS` is meant for.
|
|
22
|
+
FETCH_TIMEOUT_SECS = CLI_TIMEOUT_SECS * 4
|
|
23
|
+
|
|
24
|
+
# A check's answer only depends on the three commits, so it is kept between runs (a status line polls `pr info`).
|
|
25
|
+
_CACHE_FILE = "bdt-merge-check.json"
|
|
26
|
+
_CACHE_ENTRIES = 50
|
|
27
|
+
|
|
28
|
+
_OBJECT_ID = re.compile(r"[0-9a-f]{40}|[0-9a-f]{64}")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@dataclass(frozen=True)
|
|
32
|
+
class Drift:
|
|
33
|
+
"""The target moved since the PR's merge status was computed."""
|
|
34
|
+
|
|
35
|
+
target: str
|
|
36
|
+
behind: int | None # commits the target gained since then; None if they couldn't be counted
|
|
37
|
+
conflicts: tuple[str, ...] | None # paths that conflict with the target's tip; () = merges cleanly, None = couldn't tell
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def conflicting(self) -> bool:
|
|
41
|
+
return bool(self.conflicts)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _git(args: list[str], cwd: str | None, timeout: float = CLI_TIMEOUT_SECS) -> subprocess.CompletedProcess[str]:
|
|
45
|
+
try:
|
|
46
|
+
return subprocess.run(["git", *args], cwd=cwd, capture_output=True, encoding="utf-8", timeout=timeout)
|
|
47
|
+
except (OSError, subprocess.TimeoutExpired) as e: # no git, or a fetch that hangs: "couldn't tell", like any other failure
|
|
48
|
+
return subprocess.CompletedProcess(["git", *args], 255, "", str(e))
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _cache_path(cwd: str | None) -> Path | None:
|
|
52
|
+
r = _git(["rev-parse", "--git-path", _CACHE_FILE], cwd)
|
|
53
|
+
return Path(cwd or ".") / r.stdout.strip() if r.returncode == 0 else None
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _cache_read(path: Path | None) -> dict:
|
|
57
|
+
try:
|
|
58
|
+
return json.loads(path.read_text(encoding="utf-8")) if path else {}
|
|
59
|
+
except (OSError, ValueError):
|
|
60
|
+
return {}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _cache_write(path: Path | None, cache: dict) -> None:
|
|
64
|
+
if path is None:
|
|
65
|
+
return
|
|
66
|
+
try:
|
|
67
|
+
path.write_text(json.dumps(dict(list(cache.items())[-_CACHE_ENTRIES:])), encoding="utf-8")
|
|
68
|
+
except OSError:
|
|
69
|
+
pass # a cache that can't be written only costs the next run a fetch
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def merge_conflicts(source: str, target: str, cwd: str | None = None) -> tuple[str, ...] | None:
|
|
73
|
+
"""Paths that conflict when merging commit `source` into commit `target`; `()` if it merges cleanly,
|
|
74
|
+
`None` if that couldn't be found out (an object missing locally, git too old for `merge-tree --write-tree`)."""
|
|
75
|
+
r = _git(["merge-tree", "--write-tree", "--name-only", "--no-messages", target, source], cwd)
|
|
76
|
+
if r.returncode == 0:
|
|
77
|
+
return ()
|
|
78
|
+
lines = r.stdout.splitlines()
|
|
79
|
+
# a conflict is exit 1 with the merged tree's id first and one conflicted path per line after it; an unknown commit is exit 1 too
|
|
80
|
+
if r.returncode != 1 or not lines or not _OBJECT_ID.fullmatch(lines[0]):
|
|
81
|
+
return None
|
|
82
|
+
return tuple(dict.fromkeys(line for line in lines[1:] if line))
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _is_this_repo(remote: AdoRemote, cwd: str | None) -> bool:
|
|
86
|
+
try:
|
|
87
|
+
return current_remote(cwd) == remote
|
|
88
|
+
except (SystemExit, UnknownRemoteError):
|
|
89
|
+
return False
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def moved_target(pr: dict) -> tuple[str, str, str] | None:
|
|
93
|
+
"""(target branch, commit its merge status was computed against, source commit) of an active `pr`; None if it has none."""
|
|
94
|
+
target = (pr.get("targetRefName") or "").removeprefix("refs/heads/")
|
|
95
|
+
last_target = (pr.get("lastMergeTargetCommit") or {}).get("commitId")
|
|
96
|
+
source = (pr.get("lastMergeSourceCommit") or {}).get("commitId")
|
|
97
|
+
if pr.get("status") != "active" or not (target and last_target and source):
|
|
98
|
+
return None
|
|
99
|
+
return target, last_target, source
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def check(remote: AdoRemote, pr: dict, tip: str | None, cwd: str | None = None) -> Drift | None:
|
|
103
|
+
"""None unless the target branch of `pr` (see `moved_target`) has moved since its merge status was computed, i.e.
|
|
104
|
+
`tip`, the commit the branch points at now, isn't the one that status is about.
|
|
105
|
+
|
|
106
|
+
Needs a checkout of `remote` for the merge itself (`cwd`, default the current directory); for a PR of another
|
|
107
|
+
repo, or when the commits can't be fetched, the answer is a `Drift` whose `conflicts` is None: the target moved, but
|
|
108
|
+
whether that matters is unknown.
|
|
109
|
+
"""
|
|
110
|
+
moved = moved_target(pr)
|
|
111
|
+
if moved is None or tip is None or tip == moved[1]:
|
|
112
|
+
return None
|
|
113
|
+
target, last_target, source = moved
|
|
114
|
+
if not _is_this_repo(remote, cwd):
|
|
115
|
+
return Drift(target, None, None)
|
|
116
|
+
|
|
117
|
+
key = f"{last_target}:{tip}:{source}"
|
|
118
|
+
path = _cache_path(cwd)
|
|
119
|
+
cache = _cache_read(path)
|
|
120
|
+
if key in cache:
|
|
121
|
+
behind, conflicts = cache[key]
|
|
122
|
+
return Drift(target, behind, None if conflicts is None else tuple(conflicts))
|
|
123
|
+
|
|
124
|
+
# by commit id: the PR's source branch may be one this checkout never fetched
|
|
125
|
+
fetched = _git(["fetch", "--quiet", "--no-write-fetch-head", "origin", last_target, tip, source], cwd, FETCH_TIMEOUT_SECS)
|
|
126
|
+
if fetched.returncode != 0:
|
|
127
|
+
return Drift(target, None, None) # not cached: a later run may manage to fetch
|
|
128
|
+
count = _git(["rev-list", "--count", f"{last_target}..{tip}"], cwd)
|
|
129
|
+
behind = int(count.stdout) if count.returncode == 0 else None
|
|
130
|
+
conflicts = merge_conflicts(source, tip, cwd)
|
|
131
|
+
cache[key] = [behind, None if conflicts is None else list(conflicts)]
|
|
132
|
+
_cache_write(path, cache)
|
|
133
|
+
return Drift(target, behind, conflicts)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def _moved(drift: Drift) -> str:
|
|
137
|
+
return f"'{drift.target}' has moved on" + (f" by {drift.behind} commit{'s' * (drift.behind != 1)}" if drift.behind else "")
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def conflict_message(pr: dict, drift: Drift) -> str:
|
|
141
|
+
"""`pr` conflicts with the target's tip: what to say, in the shape of `pr_build.merge_conflict_message`."""
|
|
142
|
+
shown = ", ".join((drift.conflicts or ())[:10]) + (", ..." if len(drift.conflicts or ()) > 10 else "")
|
|
143
|
+
return (
|
|
144
|
+
f"PR #{pr.get('pullRequestId')} ({pr.get('title', '?')!r}) has merge conflicts with '{drift.target}' (mergeStatus="
|
|
145
|
+
f"{pr.get('mergeStatus', '?')} is stale: {_moved(drift)} since it was computed). Conflicting: {shown}. "
|
|
146
|
+
f"Merge or rebase '{drift.target}' into the branch and push."
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def notice(drift: Drift) -> str:
|
|
151
|
+
"""The target moved but `drift` isn't a conflict: informational, the PR still merges as far as is known."""
|
|
152
|
+
outcome = "the PR still merges cleanly" if drift.conflicts == () else "not checked for conflicts"
|
|
153
|
+
return f"Note: {_moved(drift)} since the PR's merge status and builds were computed; {outcome}."
|
|
@@ -28,6 +28,15 @@ BUILD_WAITING = "waiting" # paused on a manual approval; nothing resolves it wi
|
|
|
28
28
|
BUILD_NONE = "none"
|
|
29
29
|
BUILD_UNKNOWN = "unknown"
|
|
30
30
|
|
|
31
|
+
# `merge` values: can the PR be merged into its target as it is now. "behind" = the target moved on since the PR's
|
|
32
|
+
# merge status was computed (Azure DevOps never recomputes it) but it still merges; "unknown" = it moved and
|
|
33
|
+
# whether that conflicts couldn't be found out (no checkout of the repo, commits not fetchable); "none" = not an open PR.
|
|
34
|
+
MERGE_CLEAN = "clean"
|
|
35
|
+
MERGE_BEHIND = "behind"
|
|
36
|
+
MERGE_CONFLICTS = "conflicts"
|
|
37
|
+
MERGE_UNKNOWN = "unknown"
|
|
38
|
+
MERGE_NONE = "none"
|
|
39
|
+
|
|
31
40
|
|
|
32
41
|
@dataclass(frozen=True)
|
|
33
42
|
class IssueRef:
|
|
@@ -44,6 +53,10 @@ class PrInfo:
|
|
|
44
53
|
draft: bool
|
|
45
54
|
build: str
|
|
46
55
|
issues: list[IssueRef] = field(default_factory=list)
|
|
56
|
+
merge: str = MERGE_NONE # `MERGE_*`: does it merge into `target` as it is now
|
|
57
|
+
target: str = "" # the branch it merges into
|
|
58
|
+
conflicts: list[str] = field(default_factory=list) # the conflicting paths, when `merge` is "conflicts" and they are known
|
|
59
|
+
target_behind: int | None = None # commits `target` gained since the PR's merge status was computed (Azure DevOps), when known
|
|
47
60
|
cancel_reason: str | None = None # why the build was cancelled, when `build` is "cancelled" and a `CANCELLED BUILD:` comment says
|
|
48
61
|
cancel_session: Session | None = None # the agent session that cancelled it, when that comment says
|
|
49
62
|
abandon_reason: str | None = None # why the PR was abandoned, when `state` is "closed" and an `ABANDONED PR:` comment says
|
|
@@ -112,6 +125,9 @@ def github_info(pr: dict, remote: GitHubRemote, gh: GitHubClient | None = None)
|
|
|
112
125
|
draft=bool(pr.get("isDraft")),
|
|
113
126
|
build=build_state(checks, cancelled=cancelled is not None),
|
|
114
127
|
issues=issues,
|
|
128
|
+
# GitHub recomputes `mergeable` whenever the base moves, so it needs no drift check of its own
|
|
129
|
+
merge=MERGE_NONE if state != "open" else MERGE_CONFLICTS if pr.get("mergeable") == gh_pr.CONFLICTING else MERGE_CLEAN,
|
|
130
|
+
target=pr.get("baseRefName") or "",
|
|
115
131
|
cancel_reason=cancelled.reason if cancelled else None,
|
|
116
132
|
cancel_session=cancelled.session if cancelled else None,
|
|
117
133
|
abandon_reason=abandoned.reason if abandoned else None,
|
|
@@ -157,6 +173,28 @@ def _ado_build(session: requests.Session, remote: AdoRemote, pr: dict) -> tuple[
|
|
|
157
173
|
return state, cancelled
|
|
158
174
|
|
|
159
175
|
|
|
176
|
+
def _ado_merge(session: requests.Session, remote: AdoRemote, pr: dict) -> tuple[str, list[str], int | None]:
|
|
177
|
+
"""(`MERGE_*` state, conflicting paths, commits the target gained) of an Azure DevOps PR: its `mergeStatus`, but
|
|
178
|
+
that is only as current as the PR's last push, so also whether the target has moved on since (`pr_drift`)."""
|
|
179
|
+
if pr.get("status") != "active":
|
|
180
|
+
return MERGE_NONE, [], None
|
|
181
|
+
if pr.get("mergeStatus") == "conflicts":
|
|
182
|
+
return MERGE_CONFLICTS, [], None
|
|
183
|
+
if pr_build.merge_conflict_message(pr): # the merge failed or was rejected by policy: not a conflict, but not mergeable either
|
|
184
|
+
return MERGE_UNKNOWN, [], None
|
|
185
|
+
try:
|
|
186
|
+
drift = pr_build.target_drift(session, remote, pr)
|
|
187
|
+
except AdoAuthError:
|
|
188
|
+
raise
|
|
189
|
+
except requests.RequestException:
|
|
190
|
+
return MERGE_UNKNOWN, [], None
|
|
191
|
+
if drift is None:
|
|
192
|
+
return MERGE_CLEAN, [], None
|
|
193
|
+
if drift.conflicting:
|
|
194
|
+
return MERGE_CONFLICTS, list(drift.conflicts or ()), drift.behind
|
|
195
|
+
return (MERGE_BEHIND if drift.conflicts == () else MERGE_UNKNOWN), [], drift.behind
|
|
196
|
+
|
|
197
|
+
|
|
160
198
|
def ado_info(session: requests.Session, pr: dict, remote: AdoRemote) -> PrInfo:
|
|
161
199
|
"""`pr` is an Azure DevOps pull request REST object (see `pr_build.get_pr`)."""
|
|
162
200
|
issues = [
|
|
@@ -165,6 +203,7 @@ def ado_info(session: requests.Session, pr: dict, remote: AdoRemote) -> PrInfo:
|
|
|
165
203
|
]
|
|
166
204
|
pr_id = pr["pullRequestId"]
|
|
167
205
|
build, cancelled = _ado_build(session, remote, pr)
|
|
206
|
+
merge, conflicts, behind = _ado_merge(session, remote, pr)
|
|
168
207
|
abandoned = pr_build.abandonment(session, remote, pr_id) if pr.get("status") == "abandoned" else None
|
|
169
208
|
return PrInfo(
|
|
170
209
|
number=pr_id,
|
|
@@ -174,6 +213,10 @@ def ado_info(session: requests.Session, pr: dict, remote: AdoRemote) -> PrInfo:
|
|
|
174
213
|
draft=bool(pr.get("isDraft")),
|
|
175
214
|
build=build,
|
|
176
215
|
issues=issues,
|
|
216
|
+
merge=merge,
|
|
217
|
+
target=(pr.get("targetRefName") or "").removeprefix("refs/heads/"),
|
|
218
|
+
conflicts=conflicts,
|
|
219
|
+
target_behind=behind,
|
|
177
220
|
cancel_reason=cancelled.reason if cancelled else None,
|
|
178
221
|
cancel_session=cancelled.session if cancelled else None,
|
|
179
222
|
abandon_reason=abandoned.reason if abandoned else None,
|
|
@@ -10,7 +10,7 @@ packages = ["bmsdna"]
|
|
|
10
10
|
|
|
11
11
|
[project]
|
|
12
12
|
name = "bmsdna-devtools"
|
|
13
|
-
version = "0.
|
|
13
|
+
version = "0.55.0"
|
|
14
14
|
description = "Shared Azure DevOps / GitHub / git / Azure Monitor developer tooling for BMS projects"
|
|
15
15
|
readme = "README.md"
|
|
16
16
|
requires-python = ">=3.14" # pgdevkit>=0.7.1 requires 3.14; was >=3.11 before adding it as a dependency
|
|
@@ -46,6 +46,12 @@ error message for `mergeStatus=conflicts` (ADO) or `mergeable=CONFLICTING`
|
|
|
46
46
|
(GitHub) and tell the user to resolve conflicts rather than assuming CI is
|
|
47
47
|
just slow.
|
|
48
48
|
|
|
49
|
+
On Azure DevOps the server's `mergeStatus` goes stale when the **target** branch moves on (it is only recomputed by
|
|
50
|
+
a push to your branch), so `pr status` (also at the start of and during `--wait`) fetches the target's tip and merges it
|
|
51
|
+
locally: a conflict stops with `has merge conflicts with '<target>' (mergeStatus=... is stale ...)` and the conflicting
|
|
52
|
+
paths -- merge or rebase the target into your branch and push, then run it again. `Note: '<target>' has moved on ...` is
|
|
53
|
+
only informational.
|
|
54
|
+
|
|
49
55
|
Where your shell tool has a time limit shorter than CI (it kills the command and drops its output), run
|
|
50
56
|
`bdt pr status --wait --timeout 540` (seconds, below the limit): after that long it prints the current state and
|
|
51
57
|
exits 4 — just run the same command again to keep waiting. Exit 3 = a stage needs a human's approval.
|
|
@@ -174,7 +180,8 @@ PR link, state, aggregate build state and the issue(s) it closes, in one call --
|
|
|
174
180
|
with several PRs, e.g. into `dev` and `main`, where plain `pr info` has to ask which one.
|
|
175
181
|
`--pr-id` (repeatable, comma-separated) names PRs directly, also of other repos: a number, `owner/repo#N` (GitHub),
|
|
176
182
|
`project/repo#N` (Azure DevOps) or the PR's URL; two or more give a list, and a failing entry is an `error:` line on
|
|
177
|
-
stderr with exit 1 while the others are still printed. Every JSON object carries its `repo
|
|
183
|
+
stderr with exit 1 while the others are still printed. Every JSON object carries its `repo`, and `merge`
|
|
184
|
+
(`clean`/`behind`/`conflicts`/`unknown`/`none`) with `target`, `conflicts` and `target_behind`: whether it still merges into its target.
|
|
178
185
|
(`bdt pr status --wait` is still what to use to wait for CI.)
|
|
179
186
|
|
|
180
187
|
## Creating a worktree
|