git-bot-feedback 0.4.0__tar.gz → 0.5.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.
- git_bot_feedback-0.5.0/AGENTS.md +135 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/CHANGELOG.md +18 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/Cargo.lock +2 -2
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/Cargo.toml +1 -1
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/PKG-INFO +16 -2
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/README.md +13 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/README.rst +15 -1
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/bindings/python/CHANGELOG.md +19 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/bindings/python/Cargo.toml +2 -2
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/bindings/python/README.rst +15 -1
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/cspell.config.yml +1 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/src/client/common.rs +1 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/src/client/gitea/mod.rs +18 -23
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/src/client/gitea/serde_structs.rs +13 -6
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/src/client/gitea/specific_api.rs +98 -33
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/src/client/gitlab/mod.rs +12 -1
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/src/client/mod.rs +8 -1
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/.gitattributes +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/.gitignore +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/.pre-commit-config.yaml +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/CONTRIBUTING.md +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/LICENSE +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/bindings/python/git_bot_feedback.pyi +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/bindings/python/src/lib.rs +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/bindings/python/src/wrapper.rs +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/build.rs +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/codecov.yml +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/docs/API/client.rst +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/docs/API/file-annotations.rst +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/docs/API/file-changes.rst +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/docs/API/index.rst +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/docs/API/output-variables.rst +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/docs/API/pr-reviews.rst +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/docs/API/thread-comments.rst +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/docs/_static/favicon.ico +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/docs/_static/logo.png +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/docs/conf.py +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/docs/index.rst +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/docs/logo.xcf +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/docs/permissions/gitlab.md +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/git_bot_feedback.pyi +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/nurfile +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/pyproject.toml +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/src/client/github/graphql.rs +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/src/client/github/mod.rs +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/src/client/github/serde_structs.rs +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/src/client/github/specific_api.rs +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/src/client/gitlab/diff_positions.rs +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/src/client/gitlab/reviews.rs +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/src/client/gitlab/serde_structs.rs +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/src/client/gitlab/specific_api.rs +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/src/client/local.rs +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/src/comments/mod.rs +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/src/comments/review_comments.rs +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/src/comments/thread_comments.rs +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/src/error.rs +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/src/file_annotations.rs +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/src/file_utils/file_filter.rs +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/src/file_utils/mod.rs +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/src/git_diff.rs +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/src/lib.rs +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/src/output_variable.rs +0 -0
- {git_bot_feedback-0.4.0 → git_bot_feedback-0.5.0}/uv.lock +0 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# Agent Guidelines for git-bot-feedback
|
|
2
|
+
|
|
3
|
+
This document provides conventions, architectural context, and workflow commands for AI coding agents operating on this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
`git-bot-feedback` is a Rust library designed for CI workflows and automation tools to provide feedback on git hosting platforms:
|
|
8
|
+
- **Supported git servers**: GitHub, GitLab (>= v17.9), Gitea, Forgejo (BitBucket planned).
|
|
9
|
+
- **Core capabilities**: Thread comments (PR and commit), CI step summaries, output variables, log grouping, file annotations, Pull Request reviews, and changed file analysis.
|
|
10
|
+
- **Multi-language project**: Rust crate at workspace root (`git-bot-feedback`) and Python bindings in `bindings/python` (`git-bot-feedback-py` built with PyO3/Maturin).
|
|
11
|
+
- **License**: LGPL-3.0-or-later.
|
|
12
|
+
|
|
13
|
+
## Critical Invariants & Rules
|
|
14
|
+
|
|
15
|
+
### 1. Test Execution Rule: Never Run `cargo test` Directly
|
|
16
|
+
> [!IMPORTANT]
|
|
17
|
+
> Do **not** run raw `cargo test` for unit or integration tests!
|
|
18
|
+
> The test suite relies heavily on manipulating environment variables. `cargo test` executes tests concurrently within the same process space, causing severe cross-test pollution and intermittent failures.
|
|
19
|
+
> Always execute tests through `cargo-nextest` (or `nur test`), which provides process isolation for each individual test.
|
|
20
|
+
|
|
21
|
+
Note, this project is primarily hosted on GitHub; any mirrors on other platforms are considered unofficial. Therefore, the CI workflows and tests all are designed for GitHub Actions.
|
|
22
|
+
|
|
23
|
+
### 2. Line Endings & Whitespace
|
|
24
|
+
- **Line endings**: All files must strictly use LF (`\n`), never CRLF (`\r\n`).
|
|
25
|
+
- **Trailing whitespace**: No trailing whitespace permitted.
|
|
26
|
+
- **End of file**: Every file must terminate with a single trailing newline.
|
|
27
|
+
- **File size**: Do not commit large files (> 500 kB).
|
|
28
|
+
|
|
29
|
+
### 3. Commit Messages and Pull Request Titles
|
|
30
|
+
- Must strictly conform to [Conventional Commits](https://www.conventionalcommits.org) specifications.
|
|
31
|
+
- Allowed commit types (enforced in `.config/committed.toml`):
|
|
32
|
+
`fix`, `feat`, `build`, `chore`, `docs`, `style`, `refactor`, `remove`, `deprecate`, `security`, `add`, `perf`, `test`.
|
|
33
|
+
- **Subject casing**: Must start with a lowercase letter (`subject_capitalized = false`).
|
|
34
|
+
- Pull request titles are validated in CI against Conventional Commits via `committed` and spell-checked via CSpell.
|
|
35
|
+
- Feature branches are squashed into a single commit upon merge into `main` so `git-cliff` can generate release notes and `CHANGELOG.md`.
|
|
36
|
+
|
|
37
|
+
### 4. Spelling & Terminology
|
|
38
|
+
- CI enforces CSpell across all project files (`cspell.config.yml`).
|
|
39
|
+
- If you introduce new technical terms, acronyms, or crate names, verify they do not fail spell checking or add them to `cspell.config.yml`.
|
|
40
|
+
|
|
41
|
+
## Task Runner: `nur`
|
|
42
|
+
|
|
43
|
+
This project uses [nur](https://crates.io/crates/nur) (a task runner using Nushell syntax) defined in `nurfile`. Prefer `nur` tasks over composite manual commands.
|
|
44
|
+
|
|
45
|
+
| Task | Command | Description |
|
|
46
|
+
| :--- | :--- | :--- |
|
|
47
|
+
| **Run Tests** | `nur test` | Runs tests with `cargo-nextest` under the `default` profile (marks tests > 10s as "SLOW"). |
|
|
48
|
+
| **Run CI Tests** | `nur test -p ci` | Runs all tests including slow tests with verbose output. |
|
|
49
|
+
| **Run Doc Tests** | `nur test docs` | Runs doc tests (`cargo test --doc --features file-changes`). |
|
|
50
|
+
| **Generate Coverage** | `nur test lcov` / `nur test html` | Generates LCOV or HTML coverage via `cargo-llvm-cov`. |
|
|
51
|
+
| **Lint & Format Check** | `nur lint --check` | Runs `cargo clippy --workspace --features file-changes --all-targets -- -D warnings` and `cargo fmt -- --check`. |
|
|
52
|
+
| **Auto-Fix Lint & Fmt** | `nur lint` | Applies clippy auto-fixes and formats code with `cargo fmt`. |
|
|
53
|
+
| **Pre-Commit Checks** | `nur pre-commit` | Runs pre-commit hooks via `uvx` on all files. |
|
|
54
|
+
| **Build Examples** | `nur examples` | Builds all examples in `examples/`. |
|
|
55
|
+
| **Build Docs** | `nur docs` | Builds Rust documentation (`cargo doc --no-deps --lib --features file-changes`). |
|
|
56
|
+
| **Build Python Docs**| `nur docs py` | Builds Python documentation using Sphinx and `uv`. |
|
|
57
|
+
|
|
58
|
+
### Fallback Commands (if `nur` is unavailable)
|
|
59
|
+
- **Run tests**:
|
|
60
|
+
Without coverage measurements:
|
|
61
|
+
```shell
|
|
62
|
+
cargo nextest run --features "test-skip-wait-for-rate-limit,file-changes" --profile default
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
With coverage measurements:
|
|
66
|
+
```shell
|
|
67
|
+
cargo llvm-cov --no-report --features "test-skip-wait-for-rate-limit,file-changes" nextest --profile default
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
To generate a coverage report:
|
|
71
|
+
```shell
|
|
72
|
+
cargo llvm-cov report --lcov --output-path lcov.info
|
|
73
|
+
# or for json output
|
|
74
|
+
cargo llvm-cov report --json --output-path coverage.json
|
|
75
|
+
```
|
|
76
|
+
Git ignores both lcov.info and coverage.json files.
|
|
77
|
+
|
|
78
|
+
Use `cargo llvm-cov clean` to flush previous coverage measurements, if fresh coverage report is needed. This will invoke a fresh compile when running the test suite.
|
|
79
|
+
- **Lint check**:
|
|
80
|
+
```shell
|
|
81
|
+
cargo clippy --workspace --features file-changes --all-targets -- -D warnings
|
|
82
|
+
cargo fmt -- --check
|
|
83
|
+
```
|
|
84
|
+
- **Pre-commit**:
|
|
85
|
+
```shell
|
|
86
|
+
uvx pre-commit run --all-files
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## CI Pipeline Overview
|
|
90
|
+
|
|
91
|
+
Automated GitHub Actions workflows run on pushes and PRs to `main`:
|
|
92
|
+
1. **`pre-commit.yml`**:
|
|
93
|
+
- `all-files`: Runs pre-commit hooks (whitespace, LF line endings, YAML/TOML syntax, file size limits, CSpell, Ruff, Mypy).
|
|
94
|
+
- `lint-rust`: Runs `nur lint --check` (`cargo clippy` with `-D warnings` and `cargo fmt -- --check`).
|
|
95
|
+
- `check-pr-title`: Verifies PR title with `committed` and `cspell-cli`.
|
|
96
|
+
- `lint-ci`: Checks GitHub Actions workflows with `zizmor`.
|
|
97
|
+
2. **`rust.yml`**:
|
|
98
|
+
- Runs `nur test docs` (documentation examples).
|
|
99
|
+
- Runs `nur examples` (compiles all examples).
|
|
100
|
+
- Runs `nur test --profile ci` (runs nextest test suite under CI profile).
|
|
101
|
+
- Generates and uploads `lcov.info` coverage report to Codecov.
|
|
102
|
+
- Publishes to crates.io upon tagged release (`git-bot-feedback/v*`).
|
|
103
|
+
3. **`docs.yml`**:
|
|
104
|
+
- Builds Python Sphinx docs and deploys to GitHub Pages on `main`.
|
|
105
|
+
- Builds Rustdoc documentation and uploads artifacts.
|
|
106
|
+
4. **`python.yml`**:
|
|
107
|
+
- Compiles and packages Python wheels across platforms (Linux, macOS, Windows) and architectures using `maturin`.
|
|
108
|
+
- Validates distribution packages with `twine check`.
|
|
109
|
+
- Publishes to PyPI upon tagged release (`git-bot-feedback-py/v*`).
|
|
110
|
+
5. **`bump-n-release.yml`**:
|
|
111
|
+
- Automated version bumping and release orchestration script (`bump-n-release.nu`).
|
|
112
|
+
|
|
113
|
+
## Cargo Features & TLS Architecture
|
|
114
|
+
|
|
115
|
+
- **Default features**: `["github", "gitea", "gitlab"]`.
|
|
116
|
+
- **Optional features**:
|
|
117
|
+
- `file-changes`: Enables git diff inspection (`fast-glob`, `regex`).
|
|
118
|
+
- `pyo3`: Enables Python binding support.
|
|
119
|
+
- `custom-git-server-impl`: Silences compiler error when git server implementations are disabled.
|
|
120
|
+
- `test-skip-wait-for-rate-limit`: Dev-only feature to bypass rate-limit wait timeouts in unit tests.
|
|
121
|
+
- **TLS backend**: The library intentionally does not specify a TLS backend for `reqwest` so consumers can select their preferred backend. For dev/testing workflows, `reqwest` dev-dependencies enable `features = ["default-tls"]`.
|
|
122
|
+
|
|
123
|
+
## Repository Structure
|
|
124
|
+
|
|
125
|
+
- `src/`: Core library implementation.
|
|
126
|
+
- `client/`: Git server client implementations (`github/`, `gitlab/`, `gitea/`, and common traits).
|
|
127
|
+
- `types.rs`, `lib.rs`: Public APIs, data models, and error types.
|
|
128
|
+
- `tests/`: Integration tests using `cargo-nextest`, `mockito`, and `tempfile`.
|
|
129
|
+
- `examples/`: Example executables demonstrating library usage.
|
|
130
|
+
- `bindings/python/`: Python bindings using PyO3 and Maturin (`git-bot-feedback-py`).
|
|
131
|
+
- `docs/`: Sphinx documentation sources for Python and web guides.
|
|
132
|
+
- `.config/`: Configuration files for `nextest.toml`, `committed.toml`, and `cliff.toml`.
|
|
133
|
+
- `nurfile`: Nushell-based task runner definitions.
|
|
134
|
+
- `.pre-commit-config.yaml`: Pre-commit hook definitions.
|
|
135
|
+
- `cspell.config.yml`: Spelling dictionary configuration.
|
|
@@ -6,12 +6,30 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
<!-- markdownlint-disable MD024 -->
|
|
8
8
|
|
|
9
|
+
## [git-bot-feedback/v0.11.0] - 2026-10-27
|
|
10
|
+
|
|
11
|
+
### <!-- 1 --> 🚀 Added
|
|
12
|
+
|
|
13
|
+
- Support Forgejo Actions by @shenxianpeng in [#154](https://github.com/2bndy5/git-bot-feedback/pull/154)
|
|
14
|
+
|
|
15
|
+
### <!-- 4 --> 🛠️ Fixed
|
|
16
|
+
|
|
17
|
+
- Add impl for `GitlabApiClient::workspace_root()` by @2bndy5 in [#153](https://github.com/2bndy5/git-bot-feedback/pull/153)
|
|
18
|
+
|
|
19
|
+
[git-bot-feedback/v0.11.0]: https://github.com/2bndy5/git-bot-feedback/compare/git-bot-feedback/v0.10.0...git-bot-feedback/v0.11.0
|
|
20
|
+
|
|
21
|
+
Full commit diff: [`git-bot-feedback/v0.10.0...git-bot-feedback/v0.11.0`][git-bot-feedback/v0.11.0]
|
|
22
|
+
|
|
9
23
|
## [git-bot-feedback/v0.10.0] - 2026-10-27
|
|
10
24
|
|
|
11
25
|
### <!-- 1 --> 🚀 Added
|
|
12
26
|
|
|
13
27
|
- Add GitLab support by @shenxianpeng in [#146](https://github.com/2bndy5/git-bot-feedback/pull/146)
|
|
14
28
|
|
|
29
|
+
### <!-- 6 --> 📦 Dependency updates
|
|
30
|
+
|
|
31
|
+
- Bump version to git-bot-feedback/v0.10.0 by @2bndy5 in [`cb5351a`](https://github.com/2bndy5/git-bot-feedback/commit/cb5351aa30c18e2d3c94235d0c932a7e93b8f254)
|
|
32
|
+
|
|
15
33
|
[git-bot-feedback/v0.10.0]: https://github.com/2bndy5/git-bot-feedback/compare/git-bot-feedback/v0.9.0...git-bot-feedback/v0.10.0
|
|
16
34
|
|
|
17
35
|
Full commit diff: [`git-bot-feedback/v0.9.0...git-bot-feedback/v0.10.0`][git-bot-feedback/v0.10.0]
|
|
@@ -413,7 +413,7 @@ dependencies = [
|
|
|
413
413
|
|
|
414
414
|
[[package]]
|
|
415
415
|
name = "git-bot-feedback"
|
|
416
|
-
version = "0.
|
|
416
|
+
version = "0.11.0"
|
|
417
417
|
dependencies = [
|
|
418
418
|
"async-trait",
|
|
419
419
|
"chrono",
|
|
@@ -433,7 +433,7 @@ dependencies = [
|
|
|
433
433
|
|
|
434
434
|
[[package]]
|
|
435
435
|
name = "git-bot-feedback-py"
|
|
436
|
-
version = "0.
|
|
436
|
+
version = "0.5.0"
|
|
437
437
|
dependencies = [
|
|
438
438
|
"git-bot-feedback",
|
|
439
439
|
"pyo3",
|
|
@@ -21,7 +21,7 @@ features = ["http2", "charset", "system-proxy"]
|
|
|
21
21
|
[package]
|
|
22
22
|
name = "git-bot-feedback"
|
|
23
23
|
description = "A library designed for CI tools that posts comments on a Pull Request."
|
|
24
|
-
version = "0.
|
|
24
|
+
version = "0.11.0"
|
|
25
25
|
edition.workspace = true
|
|
26
26
|
license.workspace = true
|
|
27
27
|
repository.workspace = true
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: git-bot-feedback
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Classifier: Development Status :: 5 - Production/Stable
|
|
5
5
|
Classifier: Intended Audience :: Developers
|
|
6
6
|
Classifier: Intended Audience :: System Administrators
|
|
@@ -72,9 +72,23 @@ The following is just a list of git servers that are planned (in order or priori
|
|
|
72
72
|
- posting thread comments for commits (push events)
|
|
73
73
|
- programmatically deleting a PR reviews' individual comments, rather we can
|
|
74
74
|
only resolve them (currently). However, deleting an entire PR review is supported.
|
|
75
|
+
|
|
76
|
+
Only a repository admin can dismiss a PR review.
|
|
77
|
+
If the token's user is not an admin, outdated reviews can only be deleted
|
|
78
|
+
(see ``ReviewOptions.delete_review_comments``).
|
|
79
|
+
- Forgejo
|
|
80
|
+
|
|
81
|
+
Forgejo uses the Gitea implementation, so the same limitations apply.
|
|
82
|
+
Forgejo support requires `Forgejo Runner`_ v7.0.0 or newer,
|
|
83
|
+
which sets the ``FORGEJO_ACTIONS`` environment variable.
|
|
84
|
+
The token is read from the ``GITEA_TOKEN`` environment variable, or
|
|
85
|
+
the ``FORGEJO_TOKEN`` environment variable that the runner sets automatically.
|
|
86
|
+
Forgejo also does not support resolving a PR review's individual comments.
|
|
75
87
|
- BitBucket
|
|
76
88
|
|
|
77
|
-
Currently, only GitHub, GitLab, and
|
|
89
|
+
Currently, only GitHub, GitLab, Gitea, and Forgejo are supported.
|
|
90
|
+
|
|
91
|
+
.. _Forgejo Runner: https://forgejo.org/docs/latest/admin/actions/
|
|
78
92
|
|
|
79
93
|
.. _GitLab token permissions: https://github.com/2bndy5/git-bot-feedback/blob/main/docs/permissions/gitlab.md
|
|
80
94
|
|
|
@@ -54,6 +54,18 @@ The following is just a list of git servers that are planned (in order or priori
|
|
|
54
54
|
- programmatically deleting a PR reviews' individual comments,
|
|
55
55
|
rather we can only resolve them (currently).
|
|
56
56
|
However, deleting an entire PR review is supported.
|
|
57
|
+
|
|
58
|
+
Only a repository admin can dismiss a PR review.
|
|
59
|
+
If the token's user is not an admin, outdated reviews can only be deleted
|
|
60
|
+
(see `ReviewOptions::delete_review_comments`).
|
|
61
|
+
- [x] Forgejo
|
|
62
|
+
|
|
63
|
+
Forgejo uses the Gitea implementation, so the same limitations apply.
|
|
64
|
+
Forgejo support requires [Forgejo Runner][forgejo-runner] v7.0.0 or newer,
|
|
65
|
+
which sets the `FORGEJO_ACTIONS` environment variable.
|
|
66
|
+
The token is read from the `GITEA_TOKEN` environment variable, or
|
|
67
|
+
the `FORGEJO_TOKEN` environment variable that the runner sets automatically.
|
|
68
|
+
Forgejo also does not support resolving a PR review's individual comments.
|
|
57
69
|
- [ ] BitBucket
|
|
58
70
|
|
|
59
71
|
### Optional support
|
|
@@ -90,6 +102,7 @@ because the following conditions must be met:
|
|
|
90
102
|
[docs-rs-link]: https://docs.rs/git-bot-feedback
|
|
91
103
|
[dep-features]: https://doc.rust-lang.org/cargo/reference/features.html#dependency-features
|
|
92
104
|
[reqwest-docs]: https://docs.rs/reqwest/latest/reqwest/#optional-features
|
|
105
|
+
[forgejo-runner]: https://forgejo.org/docs/latest/admin/actions/
|
|
93
106
|
[gitlab-permissions]: https://github.com/2bndy5/git-bot-feedback/blob/main/docs/permissions/gitlab.md
|
|
94
107
|
[LGPL-3.0-or-later]: https://github.com/2bndy5/git-bot-feedback/blob/main/LICENSE
|
|
95
108
|
[license-badge]: https://img.shields.io/github/license/2bndy5/git-bot-feedback
|
|
@@ -47,9 +47,23 @@ The following is just a list of git servers that are planned (in order or priori
|
|
|
47
47
|
- posting thread comments for commits (push events)
|
|
48
48
|
- programmatically deleting a PR reviews' individual comments, rather we can
|
|
49
49
|
only resolve them (currently). However, deleting an entire PR review is supported.
|
|
50
|
+
|
|
51
|
+
Only a repository admin can dismiss a PR review.
|
|
52
|
+
If the token's user is not an admin, outdated reviews can only be deleted
|
|
53
|
+
(see ``ReviewOptions.delete_review_comments``).
|
|
54
|
+
- Forgejo
|
|
55
|
+
|
|
56
|
+
Forgejo uses the Gitea implementation, so the same limitations apply.
|
|
57
|
+
Forgejo support requires `Forgejo Runner`_ v7.0.0 or newer,
|
|
58
|
+
which sets the ``FORGEJO_ACTIONS`` environment variable.
|
|
59
|
+
The token is read from the ``GITEA_TOKEN`` environment variable, or
|
|
60
|
+
the ``FORGEJO_TOKEN`` environment variable that the runner sets automatically.
|
|
61
|
+
Forgejo also does not support resolving a PR review's individual comments.
|
|
50
62
|
- BitBucket
|
|
51
63
|
|
|
52
|
-
Currently, only GitHub, GitLab, and
|
|
64
|
+
Currently, only GitHub, GitLab, Gitea, and Forgejo are supported.
|
|
65
|
+
|
|
66
|
+
.. _Forgejo Runner: https://forgejo.org/docs/latest/admin/actions/
|
|
53
67
|
|
|
54
68
|
.. _GitLab token permissions: https://github.com/2bndy5/git-bot-feedback/blob/main/docs/permissions/gitlab.md
|
|
55
69
|
|
|
@@ -6,6 +6,24 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
<!-- markdownlint-disable MD024 -->
|
|
8
8
|
|
|
9
|
+
## [git-bot-feedback-py/v0.5.0] - 2026-10-27
|
|
10
|
+
|
|
11
|
+
### <!-- 1 --> 🚀 Added
|
|
12
|
+
|
|
13
|
+
- Support Forgejo Actions by @shenxianpeng in [#154](https://github.com/2bndy5/git-bot-feedback/pull/154)
|
|
14
|
+
|
|
15
|
+
### <!-- 4 --> 🛠️ Fixed
|
|
16
|
+
|
|
17
|
+
- Add impl for `GitlabApiClient::workspace_root()` by @2bndy5 in [#153](https://github.com/2bndy5/git-bot-feedback/pull/153)
|
|
18
|
+
|
|
19
|
+
### <!-- 6 --> 📦 Dependency updates
|
|
20
|
+
|
|
21
|
+
- Bump version to git-bot-feedback/v0.11.0 by @2bndy5 in [`b6d5b08`](https://github.com/2bndy5/git-bot-feedback/commit/b6d5b085a1a43268818b1c4ded00e62fc649b15a)
|
|
22
|
+
|
|
23
|
+
[git-bot-feedback-py/v0.5.0]: https://github.com/2bndy5/git-bot-feedback/compare/git-bot-feedback-py/v0.4.0...git-bot-feedback-py/v0.5.0
|
|
24
|
+
|
|
25
|
+
Full commit diff: [`git-bot-feedback-py/v0.4.0...git-bot-feedback-py/v0.5.0`][git-bot-feedback-py/v0.5.0]
|
|
26
|
+
|
|
9
27
|
## [git-bot-feedback-py/v0.4.0] - 2026-10-27
|
|
10
28
|
|
|
11
29
|
### <!-- 1 --> 🚀 Added
|
|
@@ -15,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
15
33
|
### <!-- 6 --> 📦 Dependency updates
|
|
16
34
|
|
|
17
35
|
- Bump version to git-bot-feedback/v0.10.0 by @2bndy5 in [`cb5351a`](https://github.com/2bndy5/git-bot-feedback/commit/cb5351aa30c18e2d3c94235d0c932a7e93b8f254)
|
|
36
|
+
- Bump version to git-bot-feedback-py/v0.4.0 by @2bndy5 in [`93206e7`](https://github.com/2bndy5/git-bot-feedback/commit/93206e7265cadfa30d2833ba8da11d8e7dfd7c09)
|
|
18
37
|
|
|
19
38
|
[git-bot-feedback-py/v0.4.0]: https://github.com/2bndy5/git-bot-feedback/compare/git-bot-feedback-py/v0.3.0...git-bot-feedback-py/v0.4.0
|
|
20
39
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "git-bot-feedback-py"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.5.0"
|
|
4
4
|
edition.workspace = true
|
|
5
5
|
license.workspace = true
|
|
6
6
|
repository.workspace = true
|
|
@@ -14,7 +14,7 @@ crate-type = ["cdylib"] # spell-checker: disable-line
|
|
|
14
14
|
path = "src/lib.rs"
|
|
15
15
|
|
|
16
16
|
[dependencies]
|
|
17
|
-
git-bot-feedback = { path = "../..", version = "0.
|
|
17
|
+
git-bot-feedback = { path = "../..", version = "0.11.0", features = ["file-changes", "pyo3"] }
|
|
18
18
|
pyo3 = { workspace = true }
|
|
19
19
|
pyo3-async-runtimes = { version = "0.29.0", features = ["tokio-runtime"] }
|
|
20
20
|
pyo3-log = "0.13.4"
|
|
@@ -47,9 +47,23 @@ The following is just a list of git servers that are planned (in order or priori
|
|
|
47
47
|
- posting thread comments for commits (push events)
|
|
48
48
|
- programmatically deleting a PR reviews' individual comments, rather we can
|
|
49
49
|
only resolve them (currently). However, deleting an entire PR review is supported.
|
|
50
|
+
|
|
51
|
+
Only a repository admin can dismiss a PR review.
|
|
52
|
+
If the token's user is not an admin, outdated reviews can only be deleted
|
|
53
|
+
(see ``ReviewOptions.delete_review_comments``).
|
|
54
|
+
- Forgejo
|
|
55
|
+
|
|
56
|
+
Forgejo uses the Gitea implementation, so the same limitations apply.
|
|
57
|
+
Forgejo support requires `Forgejo Runner`_ v7.0.0 or newer,
|
|
58
|
+
which sets the ``FORGEJO_ACTIONS`` environment variable.
|
|
59
|
+
The token is read from the ``GITEA_TOKEN`` environment variable, or
|
|
60
|
+
the ``FORGEJO_TOKEN`` environment variable that the runner sets automatically.
|
|
61
|
+
Forgejo also does not support resolving a PR review's individual comments.
|
|
50
62
|
- BitBucket
|
|
51
63
|
|
|
52
|
-
Currently, only GitHub, GitLab, and
|
|
64
|
+
Currently, only GitHub, GitLab, Gitea, and Forgejo are supported.
|
|
65
|
+
|
|
66
|
+
.. _Forgejo Runner: https://forgejo.org/docs/latest/admin/actions/
|
|
53
67
|
|
|
54
68
|
.. _GitLab token permissions: https://github.com/2bndy5/git-bot-feedback/blob/main/docs/permissions/gitlab.md
|
|
55
69
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
use std::{
|
|
1
|
+
use std::{fs::OpenOptions, io::Write, path::PathBuf};
|
|
2
2
|
|
|
3
3
|
use async_trait::async_trait;
|
|
4
4
|
use reqwest::{Client, Method};
|
|
@@ -12,6 +12,7 @@ use crate::{
|
|
|
12
12
|
mod serde_structs;
|
|
13
13
|
use serde_structs::{FullReview, ReviewDiffComment};
|
|
14
14
|
mod specific_api;
|
|
15
|
+
use specific_api::{ci_env_var, token};
|
|
15
16
|
|
|
16
17
|
#[cfg(feature = "file-changes")]
|
|
17
18
|
use crate::{FileDiffLines, FileFilter, LinesChangedOnly, parse_diff};
|
|
@@ -43,20 +44,17 @@ pub struct GiteaApiClient {
|
|
|
43
44
|
/// The value of the `ACTIONS_STEP_DEBUG` environment variable.
|
|
44
45
|
pub debug_enabled: bool,
|
|
45
46
|
|
|
47
|
+
/// Is the CI workflow run by Forgejo's runner (`FORGEJO_ACTIONS` is `true`)?
|
|
48
|
+
is_forgejo: bool,
|
|
49
|
+
|
|
46
50
|
/// The response header names that describe the rate limit status.
|
|
47
51
|
rate_limit_headers: RestApiRateLimitHeaders,
|
|
48
52
|
}
|
|
49
53
|
|
|
50
54
|
fn step_summary_url() -> Option<String> {
|
|
51
|
-
let server_url =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
let repo = env::var("GITEA_REPOSITORY")
|
|
55
|
-
.or_else(|_| env::var("GITHUB_REPOSITORY"))
|
|
56
|
-
.ok()?;
|
|
57
|
-
let run_id = env::var("GITEA_RUN_ID")
|
|
58
|
-
.or_else(|_| env::var("GITHUB_RUN_ID"))
|
|
59
|
-
.ok()?;
|
|
55
|
+
let server_url = ci_env_var("SERVER_URL").ok()?;
|
|
56
|
+
let repo = ci_env_var("REPOSITORY").ok()?;
|
|
57
|
+
let run_id = ci_env_var("RUN_ID").ok()?;
|
|
60
58
|
Some(format!(
|
|
61
59
|
"{}/{repo}/actions/runs/{run_id}",
|
|
62
60
|
server_url.trim_end_matches('/')
|
|
@@ -77,13 +75,9 @@ impl RestApiClient for GiteaApiClient {
|
|
|
77
75
|
self.pull_request.is_some()
|
|
78
76
|
}
|
|
79
77
|
|
|
80
|
-
/// Uses `GITEA_WORKSPACE`, or `GITHUB_WORKSPACE`
|
|
81
|
-
/// The error names `GITEA_WORKSPACE` when neither can be read.
|
|
78
|
+
/// Uses the first of `GITEA_WORKSPACE`, `FORGEJO_WORKSPACE`, or `GITHUB_WORKSPACE` that is set.
|
|
82
79
|
fn workspace_root(&self) -> Result<Option<PathBuf>, ClientError> {
|
|
83
|
-
|
|
84
|
-
.or_else(|e| env::var("GITHUB_WORKSPACE").map_err(|_| e))
|
|
85
|
-
.map(|v| Some(PathBuf::from(v)))
|
|
86
|
-
.map_err(|e| ClientError::env_var("GITEA_WORKSPACE or GITHUB_WORKSPACE", e))
|
|
80
|
+
ci_env_var("WORKSPACE").map(|v| Some(PathBuf::from(v)))
|
|
87
81
|
}
|
|
88
82
|
|
|
89
83
|
fn set_user_agent(&mut self, user_agent: &str) -> Result<(), ClientError> {
|
|
@@ -101,7 +95,7 @@ impl RestApiClient for GiteaApiClient {
|
|
|
101
95
|
if pr_info.locked {
|
|
102
96
|
return Ok(()); // cannot comment on locked PRs
|
|
103
97
|
}
|
|
104
|
-
|
|
98
|
+
token()?;
|
|
105
99
|
self.api_url.join(
|
|
106
100
|
format!("repos/{}/issues/{}/comments", self.repo, pr_info.number).as_str(),
|
|
107
101
|
)?
|
|
@@ -159,7 +153,7 @@ impl RestApiClient for GiteaApiClient {
|
|
|
159
153
|
log::info!(
|
|
160
154
|
"Using existing review comment: path='{}', line_end={}",
|
|
161
155
|
existing_comment.path,
|
|
162
|
-
existing_comment.
|
|
156
|
+
existing_comment.position
|
|
163
157
|
);
|
|
164
158
|
reused_comments.insert(proposed_comment.clone());
|
|
165
159
|
keep_comment = true;
|
|
@@ -205,7 +199,7 @@ impl RestApiClient for GiteaApiClient {
|
|
|
205
199
|
{
|
|
206
200
|
return Ok(());
|
|
207
201
|
}
|
|
208
|
-
|
|
202
|
+
token()?;
|
|
209
203
|
let url = self
|
|
210
204
|
.api_url
|
|
211
205
|
.join(format!("repos/{}/pulls/{}/reviews", self.repo, pr_info.number).as_str())?;
|
|
@@ -265,12 +259,12 @@ impl RestApiClient for GiteaApiClient {
|
|
|
265
259
|
// fetching the env var GITEA_OUTPUT value and opening the referenced file.
|
|
266
260
|
return Ok(());
|
|
267
261
|
}
|
|
268
|
-
if let Ok(gh_out) =
|
|
262
|
+
if let Ok(gh_out) = ci_env_var("OUTPUT") {
|
|
269
263
|
return match OpenOptions::new().append(true).open(gh_out) {
|
|
270
264
|
Ok(mut gh_out_file) => {
|
|
271
265
|
for out_var in vars {
|
|
272
266
|
out_var.validate()?;
|
|
273
|
-
writeln!(&mut gh_out_file, "{}
|
|
267
|
+
writeln!(&mut gh_out_file, "{out_var}")
|
|
274
268
|
.map_err(|e| ClientError::io("write to GITEA_OUTPUT file", e))?;
|
|
275
269
|
}
|
|
276
270
|
Ok(())
|
|
@@ -282,7 +276,7 @@ impl RestApiClient for GiteaApiClient {
|
|
|
282
276
|
}
|
|
283
277
|
|
|
284
278
|
fn append_step_summary(&self, comment: &str) -> Result<(), ClientError> {
|
|
285
|
-
if let Ok(gh_out) =
|
|
279
|
+
if let Ok(gh_out) = ci_env_var("STEP_SUMMARY") {
|
|
286
280
|
// step summary MD file can be overwritten/removed in CI runners
|
|
287
281
|
return match OpenOptions::new().append(true).open(gh_out) {
|
|
288
282
|
Ok(mut gh_out_file) => {
|
|
@@ -310,7 +304,8 @@ impl RestApiClient for GiteaApiClient {
|
|
|
310
304
|
) -> Result<HashMap<String, FileDiffLines>, ClientError> {
|
|
311
305
|
let url_path = match &self.pull_request {
|
|
312
306
|
Some(pr_info) => format!("repos/{}/pulls/{}.diff", self.repo, pr_info.number),
|
|
313
|
-
|
|
307
|
+
// The documented path (`repos/{repo}/commits/{sha}.diff` is not served by Forgejo).
|
|
308
|
+
None => format!("repos/{}/git/commits/{}.diff", self.repo, self.sha),
|
|
314
309
|
};
|
|
315
310
|
let url = self.api_url.join(&url_path)?;
|
|
316
311
|
let mut headers = HeaderMap::new();
|
|
@@ -22,7 +22,8 @@ pub struct ThreadComment {
|
|
|
22
22
|
#[derive(Debug, Deserialize, PartialEq, Clone)]
|
|
23
23
|
pub struct User {
|
|
24
24
|
pub login: String,
|
|
25
|
-
|
|
25
|
+
/// Negative for built-in users, such as `gitea-actions` (-2).
|
|
26
|
+
pub id: i64,
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
#[derive(Debug, Serialize, PartialEq, Clone)]
|
|
@@ -46,7 +47,9 @@ impl From<&crate::ReviewComment> for ReviewDiffComment {
|
|
|
46
47
|
Self {
|
|
47
48
|
body: comment.comment.clone(),
|
|
48
49
|
new_position: comment.line_end as i64,
|
|
49
|
-
|
|
50
|
+
// Gitea has no multi-line comments; a non-zero old_position puts
|
|
51
|
+
// the comment on the old side of the diff.
|
|
52
|
+
old_position: 0,
|
|
50
53
|
path: comment.path.clone(),
|
|
51
54
|
}
|
|
52
55
|
}
|
|
@@ -94,12 +97,16 @@ pub struct GiteaReviewComment {
|
|
|
94
97
|
pub id: i64,
|
|
95
98
|
/// The file path this comment is on.
|
|
96
99
|
pub path: String,
|
|
97
|
-
/// The
|
|
100
|
+
/// The line number in the old file (for comments on deleted lines).
|
|
101
|
+
///
|
|
102
|
+
/// This is `0` for comments on the new side of the diff.
|
|
98
103
|
#[serde(default)]
|
|
99
|
-
pub
|
|
100
|
-
/// The
|
|
104
|
+
pub original_position: i64,
|
|
105
|
+
/// The line number in the new file (for comments on added or unchanged lines).
|
|
106
|
+
///
|
|
107
|
+
/// When creating a comment, this is called `new_position` (see [`ReviewDiffComment`]).
|
|
101
108
|
#[serde(default)]
|
|
102
|
-
pub
|
|
109
|
+
pub position: i64,
|
|
103
110
|
/// The comment body text.
|
|
104
111
|
pub body: String,
|
|
105
112
|
}
|
|
@@ -15,16 +15,60 @@ use reqwest::{
|
|
|
15
15
|
};
|
|
16
16
|
use std::{collections::HashMap, env, fs};
|
|
17
17
|
|
|
18
|
+
/// The prefixes of the environment variables set by Gitea and Forgejo runners,
|
|
19
|
+
/// in order of precedence.
|
|
20
|
+
///
|
|
21
|
+
/// - Gitea's act_runner sets all `GITHUB_*` variables, but only some `GITEA_*` variables.
|
|
22
|
+
/// - Forgejo's runner (v7.0.0 or newer) sets `FORGEJO_*` and `GITHUB_*` variables,
|
|
23
|
+
/// but no `GITEA_*` variables.
|
|
24
|
+
///
|
|
25
|
+
/// `GITEA_*` variables come first because the `GITHUB_*` variables cannot be
|
|
26
|
+
/// overwritten in CI runners on GitHub (eg. for tests).
|
|
27
|
+
const ENV_PREFIXES: [&str; 3] = ["GITEA", "FORGEJO", "GITHUB"];
|
|
28
|
+
|
|
29
|
+
/// Get the value of the first environment variable that is set from the given `names`.
|
|
30
|
+
///
|
|
31
|
+
/// The returned error names all the given `names`.
|
|
32
|
+
fn first_env_var(names: &[String]) -> Result<String, ClientError> {
|
|
33
|
+
let mut error = env::VarError::NotPresent;
|
|
34
|
+
for name in names {
|
|
35
|
+
match env::var(name) {
|
|
36
|
+
Ok(value) => return Ok(value),
|
|
37
|
+
Err(e) => error = e,
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
Err(ClientError::env_var(&names.join(" or "), error))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/// Get the value of a CI environment variable that ends with the given `suffix`.
|
|
44
|
+
///
|
|
45
|
+
/// For example, `ci_env_var("SHA")` reads `GITEA_SHA`, `FORGEJO_SHA`, or `GITHUB_SHA`
|
|
46
|
+
/// (see [`ENV_PREFIXES`]).
|
|
47
|
+
pub(super) fn ci_env_var(suffix: &str) -> Result<String, ClientError> {
|
|
48
|
+
first_env_var(&ENV_PREFIXES.map(|prefix| format!("{prefix}_{suffix}")))
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/// Get the token used to authenticate REST API requests.
|
|
52
|
+
///
|
|
53
|
+
/// This is the `GITEA_TOKEN` environment variable, or `FORGEJO_TOKEN`
|
|
54
|
+
/// (set automatically by Forgejo's runner) if `GITEA_TOKEN` is not set.
|
|
55
|
+
pub(super) fn token() -> Result<String, ClientError> {
|
|
56
|
+
first_env_var(&["GITEA_TOKEN".to_string(), "FORGEJO_TOKEN".to_string()])
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/// Is the CI workflow run by Forgejo's runner?
|
|
60
|
+
pub(super) fn is_forgejo() -> bool {
|
|
61
|
+
env::var("FORGEJO_ACTIONS").is_ok_and(|v| v.to_lowercase() == "true")
|
|
62
|
+
}
|
|
63
|
+
|
|
18
64
|
impl GiteaApiClient {
|
|
19
65
|
/// Instantiate a [`GiteaApiClient`] object.
|
|
20
66
|
pub fn new() -> Result<Self, ClientError> {
|
|
21
|
-
let event_name =
|
|
67
|
+
let event_name = ci_env_var("EVENT_NAME").unwrap_or(String::from("unknown"));
|
|
22
68
|
let pull_request = {
|
|
23
69
|
match event_name.as_str() {
|
|
24
70
|
"pull_request" => {
|
|
25
|
-
|
|
26
|
-
let event_payload_path = env::var("GITEA_EVENT_PATH")
|
|
27
|
-
.map_err(|e| ClientError::env_var("GITEA_EVENT_PATH", e))?;
|
|
71
|
+
let event_payload_path = ci_env_var("EVENT_PATH")?;
|
|
28
72
|
// event payload JSON file can be overwritten/removed in CI runners
|
|
29
73
|
let file_buf = fs::read_to_string(event_payload_path.clone())
|
|
30
74
|
.map_err(|e| ClientError::io("read event payload", e))?;
|
|
@@ -36,11 +80,16 @@ impl GiteaApiClient {
|
|
|
36
80
|
_ => None,
|
|
37
81
|
}
|
|
38
82
|
};
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
83
|
+
// `GITEA_API_URL` is the server's URL, but the runners set `FORGEJO_API_URL` and
|
|
84
|
+
// `GITHUB_API_URL` to the full API root (eg. `<server>/api/v1`).
|
|
85
|
+
let gh_api_url = match env::var("GITEA_API_URL") {
|
|
86
|
+
Ok(server) => format!("{}/api/v1/", server.trim_end_matches('/')),
|
|
87
|
+
Err(_) => format!(
|
|
88
|
+
"{}/",
|
|
89
|
+
first_env_var(&["FORGEJO_API_URL".to_string(), "GITHUB_API_URL".to_string()])?
|
|
90
|
+
.trim_end_matches('/')
|
|
91
|
+
),
|
|
92
|
+
};
|
|
44
93
|
let api_url = Url::parse(gh_api_url.as_str())?;
|
|
45
94
|
|
|
46
95
|
Ok(Self {
|
|
@@ -51,9 +100,9 @@ impl GiteaApiClient {
|
|
|
51
100
|
pull_request,
|
|
52
101
|
event_name,
|
|
53
102
|
api_url,
|
|
54
|
-
repo:
|
|
55
|
-
|
|
56
|
-
|
|
103
|
+
repo: ci_env_var("REPOSITORY")?,
|
|
104
|
+
sha: ci_env_var("SHA")?,
|
|
105
|
+
is_forgejo: is_forgejo(),
|
|
57
106
|
debug_enabled: env::var("ACTIONS_STEP_DEBUG").is_ok_and(|val| &val == "true"),
|
|
58
107
|
rate_limit_headers: RestApiRateLimitHeaders {
|
|
59
108
|
reset: "x-ratelimit-reset".to_string(),
|
|
@@ -66,14 +115,15 @@ impl GiteaApiClient {
|
|
|
66
115
|
pub(super) fn make_headers() -> Result<HeaderMap<HeaderValue>, ClientError> {
|
|
67
116
|
let mut headers = HeaderMap::new();
|
|
68
117
|
headers.insert("Accept", HeaderValue::from_str("application/json")?);
|
|
69
|
-
|
|
70
|
-
|
|
118
|
+
headers.insert("Content-Type", HeaderValue::from_str("application/json")?);
|
|
119
|
+
if let Ok(token) = token() {
|
|
120
|
+
log::debug!("Using auth token from GITEA_TOKEN or FORGEJO_TOKEN environment variable");
|
|
71
121
|
let mut val = HeaderValue::from_str(format!("token {token}").as_str())?;
|
|
72
122
|
val.set_sensitive(true);
|
|
73
123
|
headers.insert(AUTHORIZATION, val);
|
|
74
124
|
} else {
|
|
75
125
|
log::warn!(
|
|
76
|
-
"No GITEA_TOKEN environment variable found! Permission to post comments may be unsatisfied."
|
|
126
|
+
"No GITEA_TOKEN or FORGEJO_TOKEN environment variable found! Permission to post comments may be unsatisfied."
|
|
77
127
|
);
|
|
78
128
|
}
|
|
79
129
|
Ok(headers)
|
|
@@ -357,9 +407,8 @@ impl GiteaApiClient {
|
|
|
357
407
|
|
|
358
408
|
// Path must match
|
|
359
409
|
existing.path == proposed.path
|
|
360
|
-
// Check line position: proposed line_end maps to
|
|
361
|
-
|
|
362
|
-
&& existing.new_position == proposed.line_end as i64
|
|
410
|
+
// Check line position: proposed line_end maps to the new side's line
|
|
411
|
+
&& existing.position == proposed.line_end as i64
|
|
363
412
|
// existing comment body must start with the marker
|
|
364
413
|
&& existing.body.starts_with(marker)
|
|
365
414
|
// compare comment bodies
|
|
@@ -376,21 +425,37 @@ impl GiteaApiClient {
|
|
|
376
425
|
) -> Result<(), ClientError> {
|
|
377
426
|
let base_url = format!("{}repos/{}/pulls/{pr_number}", self.api_url, self.repo);
|
|
378
427
|
// resolve individual comments first
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
428
|
+
if self.is_forgejo {
|
|
429
|
+
// Forgejo has no endpoint to resolve a review comment.
|
|
430
|
+
if !comment_ids.is_empty() {
|
|
431
|
+
log::info!(
|
|
432
|
+
"Forgejo does not support resolving review comments; {} outdated comment(s) left unresolved",
|
|
433
|
+
comment_ids.len()
|
|
434
|
+
);
|
|
435
|
+
}
|
|
436
|
+
} else {
|
|
437
|
+
for comment_id in comment_ids {
|
|
438
|
+
// This endpoint is not scoped to a PR number.
|
|
439
|
+
let comment_url = Url::parse(
|
|
440
|
+
format!(
|
|
441
|
+
"{}repos/{}/pulls/comments/{comment_id}/resolve",
|
|
442
|
+
self.api_url, self.repo
|
|
443
|
+
)
|
|
444
|
+
.as_str(),
|
|
445
|
+
)?;
|
|
446
|
+
let request =
|
|
447
|
+
self.make_api_request(&self.client, comment_url, Method::POST, None, None)?;
|
|
448
|
+
match self
|
|
449
|
+
.send_api_request(&self.client, request, &self.rate_limit_headers)
|
|
450
|
+
.await
|
|
451
|
+
{
|
|
452
|
+
Ok(result) => {
|
|
453
|
+
self.log_response(result, "Failed to resolve outdated review comment")
|
|
454
|
+
.await;
|
|
455
|
+
}
|
|
456
|
+
Err(e) => {
|
|
457
|
+
return Err(e.add_request_context("resolve outdated review comment"));
|
|
458
|
+
}
|
|
394
459
|
}
|
|
395
460
|
}
|
|
396
461
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//! In the root module, we just implement the RestApiClient trait.
|
|
4
4
|
//! In other (private) submodules we implement behavior specific to GitLab's REST API.
|
|
5
5
|
|
|
6
|
-
use std::env;
|
|
6
|
+
use std::{env, path::PathBuf};
|
|
7
7
|
|
|
8
8
|
use async_trait::async_trait;
|
|
9
9
|
use chrono::Utc;
|
|
@@ -111,6 +111,17 @@ impl RestApiClient for GitlabApiClient {
|
|
|
111
111
|
Some(self.event_name.clone())
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
+
/// Return the value of `CI_PROJECT_DIR` environment variable.
|
|
115
|
+
///
|
|
116
|
+
/// The value returned here is subject to the runner's git checkout or
|
|
117
|
+
/// the configured `build_dir` (which may not be the same as the git
|
|
118
|
+
/// checkout path).
|
|
119
|
+
fn workspace_root(&self) -> Result<Option<PathBuf>, ClientError> {
|
|
120
|
+
env::var("CI_PROJECT_DIR")
|
|
121
|
+
.map(|v| Some(PathBuf::from(v)))
|
|
122
|
+
.map_err(|e| ClientError::env_var("CI_PROJECT_DIR", e))
|
|
123
|
+
}
|
|
124
|
+
|
|
114
125
|
fn set_user_agent(&mut self, user_agent: &str) -> Result<(), ClientError> {
|
|
115
126
|
self.client = Client::builder()
|
|
116
127
|
.default_headers(Self::make_headers()?)
|
|
@@ -407,10 +407,17 @@ pub trait RestApiClient {
|
|
|
407
407
|
///
|
|
408
408
|
/// - the `GITHUB_ACTIONS` environment variable is not set
|
|
409
409
|
/// - the `GITEA_ACTIONS` environment variable is not set
|
|
410
|
+
/// - the `FORGEJO_ACTIONS` environment variable is not set
|
|
410
411
|
/// - the `GITLAB_CI` environment variable is not set
|
|
412
|
+
///
|
|
413
|
+
/// Forgejo uses the [`GiteaApiClient`].
|
|
414
|
+
/// Forgejo's runner also sets `GITHUB_ACTIONS`, so `FORGEJO_ACTIONS` is checked first.
|
|
411
415
|
pub fn init_client() -> Result<Box<dyn RestApiClient + Send + Sync>, ClientError> {
|
|
412
416
|
#[cfg(feature = "gitea")]
|
|
413
|
-
if
|
|
417
|
+
if ["GITEA_ACTIONS", "FORGEJO_ACTIONS"]
|
|
418
|
+
.iter()
|
|
419
|
+
.any(|name| env::var(name).is_ok_and(|v| v.to_lowercase() == "true"))
|
|
420
|
+
{
|
|
414
421
|
return Ok(Box::new(GiteaApiClient::new()?));
|
|
415
422
|
}
|
|
416
423
|
#[cfg(feature = "gitlab")]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|