depdelta-cli 0.2.0__tar.gz → 0.3.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 (44) hide show
  1. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/PKG-INFO +145 -9
  2. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/README.md +142 -6
  3. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/pyproject.toml +13 -3
  4. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/src/depdelta_cli/__init__.py +3 -2
  5. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/src/depdelta_cli/api.py +4 -1
  6. depdelta_cli-0.3.0/src/depdelta_cli/azure.py +108 -0
  7. depdelta_cli-0.3.0/src/depdelta_cli/bitbucket.py +96 -0
  8. depdelta_cli-0.3.0/src/depdelta_cli/env.py +307 -0
  9. depdelta_cli-0.3.0/src/depdelta_cli/forgejo.py +89 -0
  10. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/src/depdelta_cli/main.py +102 -8
  11. depdelta_cli-0.3.0/tests/test_azure.py +122 -0
  12. depdelta_cli-0.3.0/tests/test_bitbucket.py +117 -0
  13. depdelta_cli-0.3.0/tests/test_env.py +363 -0
  14. depdelta_cli-0.3.0/tests/test_forgejo.py +139 -0
  15. depdelta_cli-0.3.0/tests/test_main.py +608 -0
  16. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/uv.lock +1 -1
  17. depdelta_cli-0.2.0/src/depdelta_cli/env.py +0 -116
  18. depdelta_cli-0.2.0/tests/test_env.py +0 -102
  19. depdelta_cli-0.2.0/tests/test_main.py +0 -304
  20. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/.dockerignore +0 -0
  21. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/.github/workflows/ci.yml +0 -0
  22. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/.github/workflows/release.yml +0 -0
  23. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/.gitignore +0 -0
  24. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/Dockerfile +0 -0
  25. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/LICENSE +0 -0
  26. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/Makefile +0 -0
  27. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/src/depdelta_cli/__main__.py +0 -0
  28. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/src/depdelta_cli/check.py +0 -0
  29. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/src/depdelta_cli/gerrit.py +0 -0
  30. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/src/depdelta_cli/git.py +0 -0
  31. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/src/depdelta_cli/gitlab.py +0 -0
  32. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/src/depdelta_cli/manifests.py +0 -0
  33. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/src/depdelta_cli/usage.py +0 -0
  34. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/src/depdelta_cli/web.py +0 -0
  35. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/tests/conftest.py +0 -0
  36. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/tests/helpers.py +0 -0
  37. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/tests/test_api.py +0 -0
  38. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/tests/test_check.py +0 -0
  39. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/tests/test_gerrit.py +0 -0
  40. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/tests/test_git.py +0 -0
  41. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/tests/test_gitlab.py +0 -0
  42. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/tests/test_manifests.py +0 -0
  43. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/tests/test_usage.py +0 -0
  44. {depdelta_cli-0.2.0 → depdelta_cli-0.3.0}/tests/test_web.py +0 -0
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: depdelta-cli
3
- Version: 0.2.0
4
- Summary: DepDelta for CI: review a change's dependency updates on Gerrit or GitLab.
3
+ Version: 0.3.0
4
+ Summary: DepDelta for CI: review a change's dependency updates on Gerrit, GitLab, Forgejo or Gitea.
5
5
  Project-URL: Homepage, https://depdelta.com
6
6
  Project-URL: Documentation, https://depdelta.com/ci
7
7
  Project-URL: Source, https://github.com/mbobiosio/depdelta-cli
@@ -9,7 +9,7 @@ Project-URL: Issues, https://github.com/mbobiosio/depdelta-cli/issues
9
9
  Author: Mbuodile Obiosio
10
10
  License-Expression: MIT
11
11
  License-File: LICENSE
12
- Keywords: breaking-changes,ci,dependencies,gerrit,gitlab,renovate
12
+ Keywords: breaking-changes,ci,codeberg,dependencies,forgejo,gerrit,gitea,gitlab,renovate
13
13
  Classifier: Development Status :: 4 - Beta
14
14
  Classifier: Environment :: Console
15
15
  Classifier: Intended Audience :: Developers
@@ -26,7 +26,8 @@ Description-Content-Type: text/markdown
26
26
  [![CI](https://github.com/mbobiosio/depdelta-cli/actions/workflows/ci.yml/badge.svg)](https://github.com/mbobiosio/depdelta-cli/actions/workflows/ci.yml)
27
27
  [![License: MIT](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
28
28
 
29
- Know what a dependency update breaks before you merge, on Gerrit and GitLab.
29
+ Know what a dependency update breaks before you merge, on Gerrit, GitLab,
30
+ Forgejo and Gitea (Codeberg included), Bitbucket Cloud and Azure DevOps.
30
31
 
31
32
  [DepDelta](https://depdelta.com) reads every release's notes, security
32
33
  advisories and published API between two versions of a package, and says
@@ -52,8 +53,9 @@ On every change that touches a manifest or lockfile, `depdelta`:
52
53
  3. looks for those declarations in the checkout, and sends only the hits
53
54
  (path, line, symbol);
54
55
  4. posts the review: a Gerrit change message (no vote), or one GitLab merge
55
- request note that later pipelines edit in place. Each update links to its
56
- full comparison on depdelta.com.
56
+ request note, Forgejo/Gitea or Bitbucket pull request comment, or Azure
57
+ DevOps pull request thread that later runs edit in place. Each update
58
+ links to its full comparison on depdelta.com.
57
59
 
58
60
  Beyond each update, the review says what the change does to your lockfiles:
59
61
  packages before and after, new and removed direct dependencies (dev or
@@ -151,11 +153,145 @@ depdelta:
151
153
 
152
154
  Uses link to the files at the merge request's head commit.
153
155
 
156
+ ## Forgejo and Gitea
157
+
158
+ Codeberg, self-hosted Forgejo and Gitea share one API, so one setup covers
159
+ them: Forgejo Actions, Gitea Actions, or Woodpecker CI. The review is one
160
+ pull request comment that later runs edit in place. The token comes from
161
+ `FORGEJO_TOKEN`, else `GITEA_TOKEN`, else `GITHUB_TOKEN`.
162
+
163
+ ### Forgejo Actions and Gitea Actions
164
+
165
+ The workflow's own token can comment on pull requests from branches of the
166
+ same repository. On a pull request from a fork it is read-only (and secrets
167
+ are not passed), so the review can't be posted there.
168
+
169
+ ```yaml
170
+ # .forgejo/workflows/depdelta.yml (Gitea: .gitea/workflows/depdelta.yml)
171
+ on: pull_request
172
+
173
+ jobs:
174
+ depdelta:
175
+ runs-on: docker
176
+ steps:
177
+ - uses: actions/checkout@v4
178
+ with:
179
+ fetch-depth: 0
180
+ - name: DepDelta
181
+ # A DepDelta outage shouldn't fail the pull request.
182
+ continue-on-error: true
183
+ env:
184
+ DEPDELTA_API_KEY: ${{ secrets.DEPDELTA_API_KEY }}
185
+ FORGEJO_TOKEN: ${{ github.token }}
186
+ run: |
187
+ curl -LsSf https://astral.sh/uv/install.sh | sh
188
+ ~/.local/bin/uvx --from depdelta-cli depdelta
189
+ ```
190
+
191
+ The job needs Python 3.11+ and git; the lines above fetch Python with
192
+ [uv](https://docs.astral.sh/uv/). With Python on the runner,
193
+ `pip install depdelta-cli && depdelta` does the same. A pull request that
194
+ touches no manifests or lockfiles ends at once with nothing to review.
195
+
196
+ ### Woodpecker CI
197
+
198
+ For a Forgejo or Gitea forge (`CI_FORGE_TYPE` is `forgejo` or `gitea`).
199
+ Woodpecker has no token for the forge: make an access token with the
200
+ `write:issue` and `read:repository` scopes (a bot account works best) and
201
+ store it as a secret. Woodpecker hides secrets from pull requests until
202
+ you allow the `pull_request` event on each one.
203
+
204
+ ```yaml
205
+ # .woodpecker/depdelta.yaml
206
+ when:
207
+ - event: pull_request
208
+
209
+ steps:
210
+ - name: depdelta
211
+ image: ghcr.io/mbobiosio/depdelta-cli:latest
212
+ commands:
213
+ - depdelta
214
+ environment:
215
+ DEPDELTA_API_KEY:
216
+ from_secret: depdelta_api_key
217
+ FORGEJO_TOKEN:
218
+ from_secret: forgejo_token
219
+ failure: ignore
220
+ ```
221
+
222
+ Woodpecker names only the target branch, so `depdelta` asks the forge for
223
+ the pull request's merge base, and fetches it when the clone is shallow.
224
+ Uses link to the files at the pull request's head commit.
225
+
226
+ ## Bitbucket Pipelines
227
+
228
+ Bitbucket Cloud, in a pull request pipeline. Pipelines has no token that can
229
+ comment: make a repository access token with the `pullrequest:write` scope
230
+ (Repository settings → Access tokens) and store it as a secured repository
231
+ variable `BITBUCKET_ACCESS_TOKEN`, next to `DEPDELTA_API_KEY`. An Atlassian
232
+ API token works too: set `BITBUCKET_EMAIL` and `BITBUCKET_API_TOKEN`.
233
+
234
+ ```yaml
235
+ # bitbucket-pipelines.yml
236
+ pipelines:
237
+ pull-requests:
238
+ "**":
239
+ - step:
240
+ name: DepDelta
241
+ image: ghcr.io/mbobiosio/depdelta-cli:latest
242
+ clone:
243
+ depth: full
244
+ script:
245
+ # A DepDelta outage shouldn't fail the pull request.
246
+ - depdelta || true
247
+ ```
248
+
249
+ Bitbucket shows HTML as text, so the review comes as plain Markdown, one
250
+ section per update. Bitbucket names only the destination's tip, so
251
+ `depdelta` asks Bitbucket for the pull request's merge base. Uses link to
252
+ the lines at the pull request's head commit. To fail the build with
253
+ `--fail-on`, drop the `|| true`.
254
+
255
+ ## Azure Pipelines
256
+
257
+ Azure Repos pull requests, run as build validation: add the pipeline to the
258
+ target branch's policies (Branch policies → Build validation). Give the
259
+ build service permission to comment: Project settings → Repositories → your
260
+ repository → Security → "*Project* Build Service" → Contribute to pull
261
+ requests: Allow. The job's token reaches `depdelta` only when mapped into
262
+ the step's environment:
263
+
264
+ ```yaml
265
+ # azure-pipelines.yml
266
+ trigger: none
267
+
268
+ pool:
269
+ vmImage: ubuntu-latest
270
+
271
+ steps:
272
+ - checkout: self
273
+ fetchDepth: 0
274
+ - script: pipx run --spec depdelta-cli depdelta
275
+ displayName: DepDelta
276
+ # A DepDelta outage shouldn't fail the pull request.
277
+ continueOnError: true
278
+ env:
279
+ DEPDELTA_API_KEY: $(DEPDELTA_API_KEY)
280
+ SYSTEM_ACCESSTOKEN: $(System.AccessToken)
281
+ ```
282
+
283
+ A personal access token with Code: Read & write works too, as
284
+ `AZURE_DEVOPS_TOKEN`. The review is one pull request thread that later
285
+ builds edit in place; it starts active, so it can be resolved like any
286
+ comment. The build checks out a merge commit, so `depdelta` asks Azure
287
+ DevOps where the pull request starts. Repositories on GitHub built in Azure
288
+ Pipelines aren't covered: use the GitHub app.
289
+
154
290
  ## Options
155
291
 
156
292
  ```
157
293
  depdelta [--repo .] [--base REV --head REV] [--print]
158
- [--format markdown|text] [--wait 300]
294
+ [--format markdown|commonmark|text] [--wait 300]
159
295
  [--fail-on never|breaking|review|unknown|safe]
160
296
  [--api-url URL]
161
297
  ```
@@ -196,8 +332,8 @@ falls back to the defaults, and the review says why.
196
332
 
197
333
  Only the changed manifests and lockfiles leave CI, plus, for updates with
198
334
  removed or changed APIs, the path, line and symbol of each use found. The
199
- source code stays in CI. Gerrit and GitLab credentials are sent only to your
200
- Gerrit or GitLab. The [privacy policy](https://depdelta.com/privacy) has the
335
+ source code stays in CI. Forge credentials (Gerrit, GitLab, Forgejo, Gitea,
336
+ Bitbucket, Azure DevOps) are sent only to that forge. The [privacy policy](https://depdelta.com/privacy) has the
201
337
  details.
202
338
 
203
339
  ## Links
@@ -4,7 +4,8 @@
4
4
  [![CI](https://github.com/mbobiosio/depdelta-cli/actions/workflows/ci.yml/badge.svg)](https://github.com/mbobiosio/depdelta-cli/actions/workflows/ci.yml)
5
5
  [![License: MIT](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
6
6
 
7
- Know what a dependency update breaks before you merge, on Gerrit and GitLab.
7
+ Know what a dependency update breaks before you merge, on Gerrit, GitLab,
8
+ Forgejo and Gitea (Codeberg included), Bitbucket Cloud and Azure DevOps.
8
9
 
9
10
  [DepDelta](https://depdelta.com) reads every release's notes, security
10
11
  advisories and published API between two versions of a package, and says
@@ -30,8 +31,9 @@ On every change that touches a manifest or lockfile, `depdelta`:
30
31
  3. looks for those declarations in the checkout, and sends only the hits
31
32
  (path, line, symbol);
32
33
  4. posts the review: a Gerrit change message (no vote), or one GitLab merge
33
- request note that later pipelines edit in place. Each update links to its
34
- full comparison on depdelta.com.
34
+ request note, Forgejo/Gitea or Bitbucket pull request comment, or Azure
35
+ DevOps pull request thread that later runs edit in place. Each update
36
+ links to its full comparison on depdelta.com.
35
37
 
36
38
  Beyond each update, the review says what the change does to your lockfiles:
37
39
  packages before and after, new and removed direct dependencies (dev or
@@ -129,11 +131,145 @@ depdelta:
129
131
 
130
132
  Uses link to the files at the merge request's head commit.
131
133
 
134
+ ## Forgejo and Gitea
135
+
136
+ Codeberg, self-hosted Forgejo and Gitea share one API, so one setup covers
137
+ them: Forgejo Actions, Gitea Actions, or Woodpecker CI. The review is one
138
+ pull request comment that later runs edit in place. The token comes from
139
+ `FORGEJO_TOKEN`, else `GITEA_TOKEN`, else `GITHUB_TOKEN`.
140
+
141
+ ### Forgejo Actions and Gitea Actions
142
+
143
+ The workflow's own token can comment on pull requests from branches of the
144
+ same repository. On a pull request from a fork it is read-only (and secrets
145
+ are not passed), so the review can't be posted there.
146
+
147
+ ```yaml
148
+ # .forgejo/workflows/depdelta.yml (Gitea: .gitea/workflows/depdelta.yml)
149
+ on: pull_request
150
+
151
+ jobs:
152
+ depdelta:
153
+ runs-on: docker
154
+ steps:
155
+ - uses: actions/checkout@v4
156
+ with:
157
+ fetch-depth: 0
158
+ - name: DepDelta
159
+ # A DepDelta outage shouldn't fail the pull request.
160
+ continue-on-error: true
161
+ env:
162
+ DEPDELTA_API_KEY: ${{ secrets.DEPDELTA_API_KEY }}
163
+ FORGEJO_TOKEN: ${{ github.token }}
164
+ run: |
165
+ curl -LsSf https://astral.sh/uv/install.sh | sh
166
+ ~/.local/bin/uvx --from depdelta-cli depdelta
167
+ ```
168
+
169
+ The job needs Python 3.11+ and git; the lines above fetch Python with
170
+ [uv](https://docs.astral.sh/uv/). With Python on the runner,
171
+ `pip install depdelta-cli && depdelta` does the same. A pull request that
172
+ touches no manifests or lockfiles ends at once with nothing to review.
173
+
174
+ ### Woodpecker CI
175
+
176
+ For a Forgejo or Gitea forge (`CI_FORGE_TYPE` is `forgejo` or `gitea`).
177
+ Woodpecker has no token for the forge: make an access token with the
178
+ `write:issue` and `read:repository` scopes (a bot account works best) and
179
+ store it as a secret. Woodpecker hides secrets from pull requests until
180
+ you allow the `pull_request` event on each one.
181
+
182
+ ```yaml
183
+ # .woodpecker/depdelta.yaml
184
+ when:
185
+ - event: pull_request
186
+
187
+ steps:
188
+ - name: depdelta
189
+ image: ghcr.io/mbobiosio/depdelta-cli:latest
190
+ commands:
191
+ - depdelta
192
+ environment:
193
+ DEPDELTA_API_KEY:
194
+ from_secret: depdelta_api_key
195
+ FORGEJO_TOKEN:
196
+ from_secret: forgejo_token
197
+ failure: ignore
198
+ ```
199
+
200
+ Woodpecker names only the target branch, so `depdelta` asks the forge for
201
+ the pull request's merge base, and fetches it when the clone is shallow.
202
+ Uses link to the files at the pull request's head commit.
203
+
204
+ ## Bitbucket Pipelines
205
+
206
+ Bitbucket Cloud, in a pull request pipeline. Pipelines has no token that can
207
+ comment: make a repository access token with the `pullrequest:write` scope
208
+ (Repository settings → Access tokens) and store it as a secured repository
209
+ variable `BITBUCKET_ACCESS_TOKEN`, next to `DEPDELTA_API_KEY`. An Atlassian
210
+ API token works too: set `BITBUCKET_EMAIL` and `BITBUCKET_API_TOKEN`.
211
+
212
+ ```yaml
213
+ # bitbucket-pipelines.yml
214
+ pipelines:
215
+ pull-requests:
216
+ "**":
217
+ - step:
218
+ name: DepDelta
219
+ image: ghcr.io/mbobiosio/depdelta-cli:latest
220
+ clone:
221
+ depth: full
222
+ script:
223
+ # A DepDelta outage shouldn't fail the pull request.
224
+ - depdelta || true
225
+ ```
226
+
227
+ Bitbucket shows HTML as text, so the review comes as plain Markdown, one
228
+ section per update. Bitbucket names only the destination's tip, so
229
+ `depdelta` asks Bitbucket for the pull request's merge base. Uses link to
230
+ the lines at the pull request's head commit. To fail the build with
231
+ `--fail-on`, drop the `|| true`.
232
+
233
+ ## Azure Pipelines
234
+
235
+ Azure Repos pull requests, run as build validation: add the pipeline to the
236
+ target branch's policies (Branch policies → Build validation). Give the
237
+ build service permission to comment: Project settings → Repositories → your
238
+ repository → Security → "*Project* Build Service" → Contribute to pull
239
+ requests: Allow. The job's token reaches `depdelta` only when mapped into
240
+ the step's environment:
241
+
242
+ ```yaml
243
+ # azure-pipelines.yml
244
+ trigger: none
245
+
246
+ pool:
247
+ vmImage: ubuntu-latest
248
+
249
+ steps:
250
+ - checkout: self
251
+ fetchDepth: 0
252
+ - script: pipx run --spec depdelta-cli depdelta
253
+ displayName: DepDelta
254
+ # A DepDelta outage shouldn't fail the pull request.
255
+ continueOnError: true
256
+ env:
257
+ DEPDELTA_API_KEY: $(DEPDELTA_API_KEY)
258
+ SYSTEM_ACCESSTOKEN: $(System.AccessToken)
259
+ ```
260
+
261
+ A personal access token with Code: Read & write works too, as
262
+ `AZURE_DEVOPS_TOKEN`. The review is one pull request thread that later
263
+ builds edit in place; it starts active, so it can be resolved like any
264
+ comment. The build checks out a merge commit, so `depdelta` asks Azure
265
+ DevOps where the pull request starts. Repositories on GitHub built in Azure
266
+ Pipelines aren't covered: use the GitHub app.
267
+
132
268
  ## Options
133
269
 
134
270
  ```
135
271
  depdelta [--repo .] [--base REV --head REV] [--print]
136
- [--format markdown|text] [--wait 300]
272
+ [--format markdown|commonmark|text] [--wait 300]
137
273
  [--fail-on never|breaking|review|unknown|safe]
138
274
  [--api-url URL]
139
275
  ```
@@ -174,8 +310,8 @@ falls back to the defaults, and the review says why.
174
310
 
175
311
  Only the changed manifests and lockfiles leave CI, plus, for updates with
176
312
  removed or changed APIs, the path, line and symbol of each use found. The
177
- source code stays in CI. Gerrit and GitLab credentials are sent only to your
178
- Gerrit or GitLab. The [privacy policy](https://depdelta.com/privacy) has the
313
+ source code stays in CI. Forge credentials (Gerrit, GitLab, Forgejo, Gitea,
314
+ Bitbucket, Azure DevOps) are sent only to that forge. The [privacy policy](https://depdelta.com/privacy) has the
179
315
  details.
180
316
 
181
317
  ## Links
@@ -1,14 +1,24 @@
1
1
  [project]
2
2
  name = "depdelta-cli"
3
- version = "0.2.0"
4
- description = "DepDelta for CI: review a change's dependency updates on Gerrit or GitLab."
3
+ version = "0.3.0"
4
+ description = "DepDelta for CI: review a change's dependency updates on Gerrit, GitLab, Forgejo or Gitea."
5
5
  readme = "README.md"
6
6
  license = "MIT"
7
7
  license-files = ["LICENSE"]
8
8
  authors = [{ name = "Mbuodile Obiosio" }]
9
9
  requires-python = ">=3.11"
10
10
  dependencies = []
11
- keywords = ["dependencies", "gerrit", "gitlab", "ci", "renovate", "breaking-changes"]
11
+ keywords = [
12
+ "dependencies",
13
+ "gerrit",
14
+ "gitlab",
15
+ "forgejo",
16
+ "gitea",
17
+ "codeberg",
18
+ "ci",
19
+ "renovate",
20
+ "breaking-changes",
21
+ ]
12
22
  classifiers = [
13
23
  "Development Status :: 4 - Beta",
14
24
  "Environment :: Console",
@@ -1,3 +1,4 @@
1
- """DepDelta for CI: review a change's dependency updates on Gerrit or GitLab."""
1
+ """DepDelta for CI: review a change's dependency updates on Gerrit, GitLab,
2
+ Forgejo or Gitea."""
2
3
 
3
- __version__ = "0.2.0"
4
+ __version__ = "0.3.0"
@@ -99,7 +99,10 @@ class DepDelta:
99
99
  "format": fmt,
100
100
  }
101
101
  if source_url:
102
- payload["source_url"] = source_url
102
+ # A link with {path} and {line} (Bitbucket, Azure DevOps), or the
103
+ # files' page that `/<path>#L<line>` is added to.
104
+ key = "source_link" if "{path}" in source_url else "source_url"
105
+ payload[key] = source_url
103
106
  if config is not None:
104
107
  payload["config"] = config
105
108
  for attempt in range(1, ATTEMPTS + 1):
@@ -0,0 +1,108 @@
1
+ # src/depdelta_cli/azure.py
2
+ #
3
+ # The review as one Azure DevOps pull request thread, found by its marker
4
+ # and its first comment edited in place on later builds. A new thread is
5
+ # active (it can be resolved like any review comment). The review comes in
6
+ # plain CommonMark with a link-reference marker.
7
+
8
+ from urllib.parse import quote
9
+
10
+ from depdelta_cli import web
11
+ from depdelta_cli.env import AzurePullRequest
12
+
13
+ #: In both the HTML marker and the CommonMark one (depdelta-api render.py).
14
+ MARKER_TEXT = "depdelta:review"
15
+ API_VERSION = "api-version=7.1"
16
+ #: The merge-bases call is still a preview in 7.1.
17
+ MERGE_BASES_VERSION = "api-version=7.1-preview.1"
18
+
19
+
20
+ class AzureError(Exception):
21
+ """Azure DevOps refused to show the pull request or its merge base, or
22
+ to list, add or edit the thread."""
23
+
24
+
25
+ def _pr_url(pr: AzurePullRequest) -> str:
26
+ return f"{pr.repo_url}/pullRequests/{quote(pr.id, safe='')}"
27
+
28
+
29
+ def _check(reply: web.Response, doing: str) -> None:
30
+ if reply.status not in (200, 201):
31
+ raise AzureError(
32
+ f"Azure DevOps answered {reply.status} {doing}: {_detail(reply.body)}"
33
+ )
34
+
35
+
36
+ def _detail(body: object) -> str:
37
+ if isinstance(body, dict):
38
+ return str(body.get("message") or body)[:300]
39
+ return str(body or "")[:300]
40
+
41
+
42
+ def merge_base(pr: AzurePullRequest, head: str, auth: str) -> str:
43
+ """Where the pull request starts: the target's last merged commit and
44
+ the head's common ancestor."""
45
+ headers = {"Authorization": auth}
46
+ reply = web.request("GET", f"{_pr_url(pr)}?{API_VERSION}", headers=headers)
47
+ _check(reply, "showing the pull request")
48
+ pull = reply.body if isinstance(reply.body, dict) else {}
49
+ target = (pull.get("lastMergeTargetCommit") or {}).get("commitId")
50
+ if not target:
51
+ raise AzureError("Azure DevOps gave no target commit for the pull request.")
52
+ reply = web.request(
53
+ "GET",
54
+ f"{pr.repo_url}/commits/{quote(head, safe='')}/mergebases"
55
+ f"?otherCommitId={quote(str(target), safe='')}&{MERGE_BASES_VERSION}",
56
+ headers=headers,
57
+ )
58
+ _check(reply, "finding the merge base")
59
+ bases = reply.body.get("value") if isinstance(reply.body, dict) else None
60
+ if not bases or not bases[0].get("commitId"):
61
+ raise AzureError("Azure DevOps gave no merge base for the pull request.")
62
+ return str(bases[0]["commitId"])
63
+
64
+
65
+ def find_comment(pr: AzurePullRequest, auth: str) -> tuple[int, int] | None:
66
+ """The (thread, comment) ids of the newest comment carrying the marker,
67
+ if one was posted."""
68
+ reply = web.request(
69
+ "GET", f"{_pr_url(pr)}/threads?{API_VERSION}", headers={"Authorization": auth}
70
+ )
71
+ _check(reply, "listing threads")
72
+ threads = reply.body.get("value") if isinstance(reply.body, dict) else None
73
+ found = None
74
+ for thread in threads or []:
75
+ if thread.get("isDeleted"):
76
+ continue
77
+ for comment in thread.get("comments") or []:
78
+ text = str(comment.get("content") or "")
79
+ if MARKER_TEXT in text and not comment.get("isDeleted"):
80
+ found = (int(thread["id"]), int(comment["id"]))
81
+ return found
82
+
83
+
84
+ def post(pr: AzurePullRequest, body: str, auth: str) -> str:
85
+ """Edit the earlier comment, or start a thread. Says which."""
86
+ headers = {"Authorization": auth}
87
+ existing = find_comment(pr, auth)
88
+ if existing is None:
89
+ reply = web.request(
90
+ "POST",
91
+ f"{_pr_url(pr)}/threads?{API_VERSION}",
92
+ body={
93
+ "comments": [{"parentCommentId": 0, "content": body, "commentType": 1}],
94
+ "status": "active",
95
+ },
96
+ headers=headers,
97
+ )
98
+ _check(reply, "starting the thread")
99
+ return "added"
100
+ thread, comment = existing
101
+ reply = web.request(
102
+ "PATCH",
103
+ f"{_pr_url(pr)}/threads/{thread}/comments/{comment}?{API_VERSION}",
104
+ body={"content": body},
105
+ headers=headers,
106
+ )
107
+ _check(reply, "editing the comment")
108
+ return "updated"
@@ -0,0 +1,96 @@
1
+ # src/depdelta_cli/bitbucket.py
2
+ #
3
+ # The review as one Bitbucket Cloud pull request comment, found by its marker
4
+ # and edited in place on later pipelines. Bitbucket shows HTML as text, so
5
+ # the review comes in plain CommonMark with a link-reference marker.
6
+
7
+ from urllib.parse import quote
8
+
9
+ from depdelta_cli import web
10
+ from depdelta_cli.env import BitbucketPullRequest
11
+
12
+ #: In both the HTML marker and the CommonMark one (depdelta-api render.py).
13
+ MARKER_TEXT = "depdelta:review"
14
+ PAGE_LENGTH = 100
15
+ #: Comment pages searched for the marker.
16
+ MAX_PAGES = 10
17
+
18
+
19
+ class BitbucketError(Exception):
20
+ """Bitbucket refused to show the merge base, or to list, add or edit
21
+ the comment."""
22
+
23
+
24
+ def _repo_url(pr: BitbucketPullRequest) -> str:
25
+ return f"{pr.api_url}/repositories/{quote(pr.repo, safe='/')}"
26
+
27
+
28
+ def _comments_url(pr: BitbucketPullRequest) -> str:
29
+ return f"{_repo_url(pr)}/pullrequests/{quote(pr.id, safe='')}/comments"
30
+
31
+
32
+ def _check(reply: web.Response, doing: str) -> None:
33
+ if reply.status not in (200, 201):
34
+ raise BitbucketError(
35
+ f"Bitbucket answered {reply.status} {doing}: {_detail(reply.body)}"
36
+ )
37
+
38
+
39
+ def _detail(body: object) -> str:
40
+ if isinstance(body, dict):
41
+ error = body.get("error")
42
+ if isinstance(error, dict):
43
+ return str(error.get("message") or error)[:300]
44
+ return str(body)[:300]
45
+ return str(body or "")[:300]
46
+
47
+
48
+ def merge_base(pr: BitbucketPullRequest, head: str, auth: str) -> str:
49
+ """Where the pull request starts: the destination's and head's common
50
+ ancestor."""
51
+ revspec = f"{quote(pr.destination, safe='')}..{quote(head, safe='')}"
52
+ reply = web.request(
53
+ "GET",
54
+ f"{_repo_url(pr)}/merge-base/{revspec}",
55
+ headers={"Authorization": auth},
56
+ )
57
+ _check(reply, "finding the merge base")
58
+ found = reply.body.get("hash") if isinstance(reply.body, dict) else None
59
+ if not found:
60
+ raise BitbucketError("Bitbucket gave no merge base for the pull request.")
61
+ return str(found)
62
+
63
+
64
+ def find_comment(pr: BitbucketPullRequest, auth: str) -> int | None:
65
+ """The id of the newest comment carrying the marker, if one was posted.
66
+ Pages come oldest first; deleted comments don't count."""
67
+ url: str | None = f"{_comments_url(pr)}?pagelen={PAGE_LENGTH}"
68
+ found = None
69
+ for _ in range(MAX_PAGES):
70
+ if url is None:
71
+ break
72
+ reply = web.request("GET", url, headers={"Authorization": auth})
73
+ _check(reply, "listing comments")
74
+ page = reply.body if isinstance(reply.body, dict) else {}
75
+ for comment in page.get("values") or []:
76
+ raw = str((comment.get("content") or {}).get("raw") or "")
77
+ if MARKER_TEXT in raw and not comment.get("deleted"):
78
+ found = int(comment["id"])
79
+ url = page.get("next")
80
+ return found
81
+
82
+
83
+ def post(pr: BitbucketPullRequest, body: str, auth: str) -> str:
84
+ """Edit the earlier comment, or add one. Says which."""
85
+ existing = find_comment(pr, auth)
86
+ content = {"content": {"raw": body}}
87
+ headers = {"Authorization": auth}
88
+ if existing is None:
89
+ reply = web.request("POST", _comments_url(pr), body=content, headers=headers)
90
+ _check(reply, "adding the comment")
91
+ return "added"
92
+ reply = web.request(
93
+ "PUT", f"{_comments_url(pr)}/{existing}", body=content, headers=headers
94
+ )
95
+ _check(reply, "editing the comment")
96
+ return "updated"