git-bot-feedback 0.6.1__tar.gz → 0.6.2__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 (66) hide show
  1. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/CHANGELOG.md +15 -0
  2. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/Cargo.lock +4 -4
  3. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/Cargo.toml +1 -1
  4. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/PKG-INFO +1 -1
  5. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/bindings/python/CHANGELOG.md +16 -0
  6. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/bindings/python/Cargo.toml +2 -2
  7. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/cspell.config.yml +1 -0
  8. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/src/client/gitea/specific_api.rs +32 -1
  9. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/src/client/github/mod.rs +121 -34
  10. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/src/client/github/serde_structs.rs +10 -0
  11. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/src/client/github/specific_api.rs +59 -1
  12. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/uv.lock +24 -24
  13. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/.gitattributes +0 -0
  14. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/.gitignore +0 -0
  15. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/.pre-commit-config.yaml +0 -0
  16. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/AGENTS.md +0 -0
  17. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/CONTRIBUTING.md +0 -0
  18. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/LICENSE +0 -0
  19. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/README.md +0 -0
  20. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/README.rst +0 -0
  21. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/bindings/python/README.rst +0 -0
  22. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/bindings/python/git_bot_feedback.pyi +0 -0
  23. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/bindings/python/src/lib.rs +0 -0
  24. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/bindings/python/src/py_types.rs +0 -0
  25. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/bindings/python/src/wrapper.rs +0 -0
  26. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/build.rs +0 -0
  27. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/codecov.yml +0 -0
  28. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/docs/API/client.rst +0 -0
  29. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/docs/API/errors.rst +0 -0
  30. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/docs/API/file-annotations.rst +0 -0
  31. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/docs/API/file-changes.rst +0 -0
  32. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/docs/API/http.rst +0 -0
  33. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/docs/API/index.rst +0 -0
  34. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/docs/API/output-variables.rst +0 -0
  35. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/docs/API/pr-reviews.rst +0 -0
  36. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/docs/API/thread-comments.rst +0 -0
  37. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/docs/_static/favicon.ico +0 -0
  38. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/docs/_static/logo.png +0 -0
  39. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/docs/conf.py +0 -0
  40. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/docs/index.rst +0 -0
  41. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/docs/logo.xcf +0 -0
  42. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/docs/permissions/gitlab.md +0 -0
  43. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/git_bot_feedback.pyi +0 -0
  44. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/nurfile +0 -0
  45. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/pyproject.toml +0 -0
  46. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/src/client/common.rs +0 -0
  47. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/src/client/gitea/mod.rs +0 -0
  48. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/src/client/gitea/serde_structs.rs +0 -0
  49. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/src/client/github/graphql.rs +0 -0
  50. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/src/client/gitlab/diff_positions.rs +0 -0
  51. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/src/client/gitlab/mod.rs +0 -0
  52. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/src/client/gitlab/reviews.rs +0 -0
  53. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/src/client/gitlab/serde_structs.rs +0 -0
  54. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/src/client/gitlab/specific_api.rs +0 -0
  55. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/src/client/local.rs +0 -0
  56. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/src/client/mod.rs +0 -0
  57. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/src/comments/mod.rs +0 -0
  58. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/src/comments/review_comments.rs +0 -0
  59. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/src/comments/thread_comments.rs +0 -0
  60. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/src/error.rs +0 -0
  61. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/src/file_annotations.rs +0 -0
  62. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/src/file_utils/file_filter.rs +0 -0
  63. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/src/file_utils/mod.rs +0 -0
  64. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/src/git_diff.rs +0 -0
  65. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/src/lib.rs +0 -0
  66. {git_bot_feedback-0.6.1 → git_bot_feedback-0.6.2}/src/output_variable.rs +0 -0
@@ -6,12 +6,27 @@ 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.12.2] - 2026-11-16
10
+
11
+ ### <!-- 4 --> 🛠️ Fixed
12
+
13
+ - Get the right changed files for `pull_request_target` and multi-commit pushes by @shenxianpeng in [#168](https://github.com/2bndy5/git-bot-feedback/pull/168)
14
+ - Skip files without line changes when lines-changed-only is on by @shenxianpeng in [#170](https://github.com/2bndy5/git-bot-feedback/pull/170)
15
+
16
+ [git-bot-feedback/v0.12.2]: https://github.com/2bndy5/git-bot-feedback/compare/git-bot-feedback/v0.12.1...git-bot-feedback/v0.12.2
17
+
18
+ Full commit diff: [`git-bot-feedback/v0.12.1...git-bot-feedback/v0.12.2`][git-bot-feedback/v0.12.2]
19
+
9
20
  ## [git-bot-feedback/v0.12.1] - 2026-11-06
10
21
 
11
22
  ### <!-- 4 --> 🛠️ Fixed
12
23
 
13
24
  - Use same-origin redirect policy by @2bndy5 in [#165](https://github.com/2bndy5/git-bot-feedback/pull/165)
14
25
 
26
+ ### <!-- 6 --> 📦 Dependency updates
27
+
28
+ - Bump version to git-bot-feedback/v0.12.1 by @2bndy5 in [`1eb37b3`](https://github.com/2bndy5/git-bot-feedback/commit/1eb37b3dc60bac0465f8f7e03ca3572671b4a48b)
29
+
15
30
  [git-bot-feedback/v0.12.1]: https://github.com/2bndy5/git-bot-feedback/compare/git-bot-feedback/v0.12.0...git-bot-feedback/v0.12.1
16
31
 
17
32
  Full commit diff: [`git-bot-feedback/v0.12.0...git-bot-feedback/v0.12.1`][git-bot-feedback/v0.12.1]
@@ -413,7 +413,7 @@ dependencies = [
413
413
 
414
414
  [[package]]
415
415
  name = "git-bot-feedback"
416
- version = "0.12.1"
416
+ version = "0.12.2"
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.6.1"
436
+ version = "0.6.2"
437
437
  dependencies = [
438
438
  "git-bot-feedback",
439
439
  "pyo3",
@@ -831,9 +831,9 @@ dependencies = [
831
831
 
832
832
  [[package]]
833
833
  name = "log"
834
- version = "0.4.34"
834
+ version = "0.4.35"
835
835
  source = "registry+https://github.com/rust-lang/crates.io-index"
836
- checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6"
836
+ checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c"
837
837
 
838
838
  [[package]]
839
839
  name = "lru-slab"
@@ -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.12.1"
24
+ version = "0.12.2"
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.6.1
3
+ Version: 0.6.2
4
4
  Classifier: Development Status :: 5 - Production/Stable
5
5
  Classifier: Intended Audience :: Developers
6
6
  Classifier: Intended Audience :: System Administrators
@@ -6,6 +6,21 @@ 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.6.2] - 2026-11-16
10
+
11
+ ### <!-- 4 --> 🛠️ Fixed
12
+
13
+ - Get the right changed files for `pull_request_target` and multi-commit pushes by @shenxianpeng in [#168](https://github.com/2bndy5/git-bot-feedback/pull/168)
14
+ - Skip files without line changes when lines-changed-only is on by @shenxianpeng in [#170](https://github.com/2bndy5/git-bot-feedback/pull/170)
15
+
16
+ ### <!-- 6 --> 📦 Dependency updates
17
+
18
+ - Bump version to git-bot-feedback/v0.12.2 by @2bndy5 in [`d314a30`](https://github.com/2bndy5/git-bot-feedback/commit/d314a3083421cff41b6ee62ac51a70dea4549a58)
19
+
20
+ [git-bot-feedback-py/v0.6.2]: https://github.com/2bndy5/git-bot-feedback/compare/git-bot-feedback-py/v0.6.1...git-bot-feedback-py/v0.6.2
21
+
22
+ Full commit diff: [`git-bot-feedback-py/v0.6.1...git-bot-feedback-py/v0.6.2`][git-bot-feedback-py/v0.6.2]
23
+
9
24
  ## [git-bot-feedback-py/v0.6.1] - 2026-11-06
10
25
 
11
26
  ### <!-- 4 --> 🛠️ Fixed
@@ -15,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
15
30
  ### <!-- 6 --> 📦 Dependency updates
16
31
 
17
32
  - Bump version to git-bot-feedback/v0.12.1 by @2bndy5 in [`1eb37b3`](https://github.com/2bndy5/git-bot-feedback/commit/1eb37b3dc60bac0465f8f7e03ca3572671b4a48b)
33
+ - Bump version to git-bot-feedback-py/v0.6.1 by @2bndy5 in [`cb36ab9`](https://github.com/2bndy5/git-bot-feedback/commit/cb36ab94704cf198a902a6a36a04078484364901)
18
34
 
19
35
  [git-bot-feedback-py/v0.6.1]: https://github.com/2bndy5/git-bot-feedback/compare/git-bot-feedback-py/v0.6.0...git-bot-feedback-py/v0.6.1
20
36
 
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "git-bot-feedback-py"
3
- version = "0.6.1"
3
+ version = "0.6.2"
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.12.1", features = ["file-changes", "pyo3"] }
17
+ git-bot-feedback = { path = "../..", version = "0.12.2", features = ["file-changes", "pyo3"] }
18
18
  pyo3 = { workspace = true }
19
19
  pyo3-async-runtimes = { version = "0.30.0", features = ["tokio-runtime"] }
20
20
  pyo3-log = "0.13.5"
@@ -21,6 +21,7 @@ words:
21
21
  - furo
22
22
  - Gitea
23
23
  - gitmodules
24
+ - hexdigit
24
25
  - hustcer
25
26
  - manylinux
26
27
  - maturin
@@ -80,7 +80,9 @@ impl GiteaApiClient {
80
80
  let event_name = ci_env_var("EVENT_NAME").ok();
81
81
  let pull_request = {
82
82
  match event_name.as_deref() {
83
- Some("pull_request") => {
83
+ // Both events have the same payload.
84
+ // They only differ in the context (and permissions) of the workflow run.
85
+ Some("pull_request" | "pull_request_target") => {
84
86
  let event_payload_path = ci_env_var("EVENT_PATH")?;
85
87
  // event payload JSON file can be overwritten/removed in CI runners
86
88
  let file_buf = fs::read_to_string(event_payload_path.clone())
@@ -615,6 +617,35 @@ mod tests {
615
617
  assert!(client.is_pr_same_remote());
616
618
  }
617
619
 
620
+ #[test]
621
+ fn pull_request_target_is_pr_event() {
622
+ let mut event_file = NamedTempFile::new().unwrap();
623
+ let payload = serde_json::json!({
624
+ "pull_request": {
625
+ "draft": false,
626
+ "state": "open",
627
+ "number": 42,
628
+ "is_locked": false,
629
+ "head": {"repo_id": 200},
630
+ "base": {"repo_id": 100}
631
+ }
632
+ });
633
+ event_file
634
+ .write_all(payload.to_string().as_bytes())
635
+ .unwrap();
636
+ unsafe {
637
+ env::set_var("GITEA_REPOSITORY", "2bndy5/git-bot-feedback");
638
+ env::set_var("GITEA_SHA", "abc123");
639
+ env::set_var("GITEA_API_URL", "https://gitea.example.com");
640
+ env::set_var("GITEA_EVENT_NAME", "pull_request_target");
641
+ env::set_var("GITEA_EVENT_PATH", event_file.path());
642
+ }
643
+ let client = GiteaApiClient::new().unwrap();
644
+ assert_eq!(client.event_name().as_deref(), Some("pull_request_target"));
645
+ assert!(client.is_pr_event());
646
+ assert!(!client.is_pr_same_remote());
647
+ }
648
+
618
649
  #[test]
619
650
  fn is_pr_same_remote_fork() {
620
651
  let mut fork_event_file = NamedTempFile::new().unwrap();
@@ -49,6 +49,13 @@ pub struct GithubApiClient {
49
49
  /// The value of the `GITHUB_SHA` environment variable.
50
50
  sha: String,
51
51
 
52
+ /// The commit that a pushed branch pointed to before a push event.
53
+ ///
54
+ /// This is [`None`] for any other event, or if a push event has no such commit
55
+ /// (eg. the branch was just created).
56
+ #[cfg(feature = "file-changes")]
57
+ push_base: Option<String>,
58
+
52
59
  /// The value of the `ACTIONS_STEP_DEBUG` environment variable.
53
60
  pub debug_enabled: bool,
54
61
 
@@ -227,8 +234,14 @@ impl RestApiClient for GithubApiClient {
227
234
  _base_diff: Option<String>,
228
235
  _ignore_index: bool,
229
236
  ) -> Result<HashMap<String, FileDiffLines>, ClientError> {
230
- use crate::client::github::serde_structs::GitHubChangedFileStatus;
231
-
237
+ // A push event can deliver several commits at once.
238
+ if let Some(base) = &self.push_base
239
+ && let Some(files) = self
240
+ .get_pushed_files(base, file_filter, lines_changed_only)
241
+ .await?
242
+ {
243
+ return Ok(files);
244
+ }
232
245
  let (url, is_pr) = match &self.pull_request {
233
246
  Some(pr_event) => (
234
247
  self.api_url.join(
@@ -268,38 +281,7 @@ impl RestApiClient for GithubApiClient {
268
281
  serde_json::from_str::<Vec<serde_structs::GithubChangedFile>>(&body)
269
282
  .map_err(|e| ClientError::json("deserialize list of changed files", e))?
270
283
  };
271
- for file in files_list {
272
- let ext = Path::new(&file.filename).extension().unwrap_or_default();
273
- if !file_filter
274
- .extensions
275
- .contains(&ext.to_string_lossy().to_string())
276
- // skip files that were removed, since there's no content to analyze.
277
- || matches!(file.status, GitHubChangedFileStatus::Removed)
278
- {
279
- continue;
280
- }
281
- if let Some(patch) = file.patch {
282
- let diff = format!(
283
- "diff --git a/{old} b/{new}\n--- a/{old}\n+++ b/{new}\n{patch}\n",
284
- old = file.previous_filename.unwrap_or(file.filename.clone()),
285
- new = file.filename,
286
- );
287
- for (name, info) in parse_diff(&diff, file_filter, lines_changed_only)? {
288
- files.entry(name).or_insert(info);
289
- }
290
- } else if file.changes == 0 || matches!(lines_changed_only, LinesChangedOnly::Off) {
291
- // file may have been only renamed.
292
- // include it in case files-changed-only is enabled.
293
- files.entry(file.filename).or_default();
294
- } else {
295
- log::warn!(
296
- "File {} has no patch info about {} changes, skipping",
297
- file.filename,
298
- file.changes
299
- );
300
- }
301
- // else changes are too big (per git server limits) or we don't care
302
- }
284
+ Self::collect_changed_files(files_list, file_filter, lines_changed_only, &mut files)?;
303
285
  }
304
286
 
305
287
  Ok(files)
@@ -388,3 +370,108 @@ impl RestApiClient for GithubApiClient {
388
370
  Ok(())
389
371
  }
390
372
  }
373
+
374
+ #[cfg(feature = "file-changes")]
375
+ impl GithubApiClient {
376
+ /// The most files that GitHub lists when comparing 2 commits.
377
+ const COMPARE_FILES_LIMIT: usize = 300;
378
+
379
+ /// Add the qualifying `files_list` (from a REST API response) to `files`.
380
+ fn collect_changed_files(
381
+ files_list: Vec<serde_structs::GithubChangedFile>,
382
+ file_filter: &FileFilter,
383
+ lines_changed_only: &LinesChangedOnly,
384
+ files: &mut HashMap<String, FileDiffLines>,
385
+ ) -> Result<(), ClientError> {
386
+ use serde_structs::GitHubChangedFileStatus;
387
+
388
+ for file in files_list {
389
+ let ext = Path::new(&file.filename).extension().unwrap_or_default();
390
+ if !file_filter
391
+ .extensions
392
+ .contains(&ext.to_string_lossy().to_string())
393
+ // skip files that were removed, since there's no content to analyze.
394
+ || matches!(file.status, GitHubChangedFileStatus::Removed)
395
+ {
396
+ continue;
397
+ }
398
+ if let Some(patch) = file.patch {
399
+ let diff = format!(
400
+ "diff --git a/{old} b/{new}\n--- a/{old}\n+++ b/{new}\n{patch}\n",
401
+ old = file.previous_filename.unwrap_or(file.filename.clone()),
402
+ new = file.filename,
403
+ );
404
+ for (name, info) in parse_diff(&diff, file_filter, lines_changed_only)? {
405
+ files.entry(name).or_insert(info);
406
+ }
407
+ } else if matches!(lines_changed_only, LinesChangedOnly::Off) {
408
+ // file may have been only renamed (or had its mode changed, or is binary).
409
+ // include it because lines are not filtered (eg. for files-changed-only).
410
+ files.entry(file.filename).or_default();
411
+ } else if file.changes == 0 {
412
+ log::debug!(
413
+ "File {} has no changed lines (eg. renamed, mode change, or binary), skipping",
414
+ file.filename
415
+ );
416
+ } else {
417
+ log::warn!(
418
+ "File {} has no patch info about {} changes, skipping",
419
+ file.filename,
420
+ file.changes
421
+ );
422
+ }
423
+ // else changes are too big (per git server limits) or we don't care
424
+ }
425
+ Ok(())
426
+ }
427
+
428
+ /// Get the files changed by all commits of a push event.
429
+ ///
430
+ /// A push event can deliver several commits at once, so this compares the pushed
431
+ /// commit (`GITHUB_SHA`) with the commit that the branch pointed to before (`base`).
432
+ ///
433
+ /// Returns [`None`] if the commits cannot be compared (eg. `base` no longer exists
434
+ /// after a force push). The caller should then only use the pushed commit's changes.
435
+ async fn get_pushed_files(
436
+ &self,
437
+ base: &str,
438
+ file_filter: &FileFilter,
439
+ lines_changed_only: &LinesChangedOnly,
440
+ ) -> Result<Option<HashMap<String, FileDiffLines>>, ClientError> {
441
+ const TASK: &str = "compare the pushed commits";
442
+ // The changed files are only listed in the first page.
443
+ // Each page also lists the compared commits, which are not needed here.
444
+ let url = Url::parse_with_params(
445
+ self.api_url
446
+ .join(format!("repos/{}/compare/{base}...{}", self.repo, self.sha).as_str())?
447
+ .as_str(),
448
+ &[("per_page", "1"), ("page", "1")],
449
+ )?;
450
+ let request = self.make_api_request(&self.client, url, Method::GET, None, None)?;
451
+ let response = self
452
+ .send_api_request(&self.client, request, &self.rate_limit_headers)
453
+ .await
454
+ .map_err(|e| e.add_request_context(TASK))?;
455
+ if let Err(e) = response.error_for_status_ref() {
456
+ log::warn!(
457
+ "Failed to {TASK}: {e:?}\nOnly using the changes of commit {}",
458
+ self.sha
459
+ );
460
+ return Ok(None);
461
+ }
462
+ let files_list =
463
+ serde_json::from_str::<serde_structs::PushEventFiles>(&response.text().await?)
464
+ .map_err(|e| ClientError::json("deserialize list of changed files", e))?
465
+ .files;
466
+ if files_list.len() >= Self::COMPARE_FILES_LIMIT {
467
+ log::warn!(
468
+ "GitHub lists at most {} changed files when comparing commits. \
469
+ Some files changed by this push may be missing.",
470
+ Self::COMPARE_FILES_LIMIT
471
+ );
472
+ }
473
+ let mut files = HashMap::new();
474
+ Self::collect_changed_files(files_list, file_filter, lines_changed_only, &mut files)?;
475
+ Ok(Some(files))
476
+ }
477
+ }
@@ -115,3 +115,13 @@ pub struct PushEventFiles {
115
115
  /// The list of changed files.
116
116
  pub files: Vec<GithubChangedFile>,
117
117
  }
118
+
119
+ /// A structure for deserializing a Push event's payload.
120
+ #[cfg(feature = "file-changes")]
121
+ #[derive(Debug, Deserialize, PartialEq, Clone)]
122
+ pub struct PushEventPayload {
123
+ /// The SHA of the most recent commit on the pushed ref before the push.
124
+ ///
125
+ /// This consists of only zeros when the push created the ref.
126
+ pub before: Option<String>,
127
+ }
@@ -17,7 +17,9 @@ impl GithubApiClient {
17
17
  let event_name = env::var("GITHUB_EVENT_NAME").ok();
18
18
  let pull_request = {
19
19
  match event_name.as_deref() {
20
- Some("pull_request") => {
20
+ // Both events have the same payload.
21
+ // They only differ in the context (and permissions) of the workflow run.
22
+ Some("pull_request" | "pull_request_target") => {
21
23
  // GITHUB_*** env vars cannot be overwritten in CI runners on GitHub.
22
24
  let event_payload_path = env::var("GITHUB_EVENT_PATH")
23
25
  .map_err(|e| ClientError::env_var("GITHUB_EVENT_PATH", e))?;
@@ -37,6 +39,11 @@ impl GithubApiClient {
37
39
  _ => None,
38
40
  }
39
41
  };
42
+ #[cfg(feature = "file-changes")]
43
+ let push_base = match event_name.as_deref() {
44
+ Some("push") => Self::get_push_base(),
45
+ _ => None,
46
+ };
40
47
  // GITHUB_*** env vars cannot be overwritten in CI runners on GitHub.
41
48
  let gh_api_url = env::var("GITHUB_API_URL").unwrap_or("https://api.github.com".to_string());
42
49
  let api_url = Url::parse(format!("{}/", gh_api_url.trim_end_matches('/')).as_str())?;
@@ -58,6 +65,8 @@ impl GithubApiClient {
58
65
  repo: env::var("GITHUB_REPOSITORY")
59
66
  .map_err(|e| ClientError::env_var("GITHUB_REPOSITORY", e))?,
60
67
  sha: env::var("GITHUB_SHA").map_err(|e| ClientError::env_var("GITHUB_SHA", e))?,
68
+ #[cfg(feature = "file-changes")]
69
+ push_base,
61
70
  debug_enabled: env::var("ACTIONS_STEP_DEBUG").is_ok_and(|val| &val == "true"),
62
71
  rate_limit_headers: RestApiRateLimitHeaders {
63
72
  reset: "x-ratelimit-reset".to_string(),
@@ -67,6 +76,25 @@ impl GithubApiClient {
67
76
  })
68
77
  }
69
78
 
79
+ /// Get the commit that the pushed branch pointed to before a push event.
80
+ ///
81
+ /// Returns [`None`] if the event payload cannot be read, or if it does not name
82
+ /// such a commit (eg. the branch was just created).
83
+ /// A push event is still usable without this information.
84
+ #[cfg(feature = "file-changes")]
85
+ fn get_push_base() -> Option<String> {
86
+ use super::serde_structs::PushEventPayload;
87
+
88
+ // event payload JSON file can be overwritten/removed in CI runners
89
+ let file_buf = fs::read_to_string(env::var("GITHUB_EVENT_PATH").ok()?).ok()?;
90
+ let before = serde_json::from_str::<PushEventPayload>(&file_buf)
91
+ .ok()?
92
+ .before?;
93
+ // A commit SHA of only zeros means there was no commit before the push.
94
+ (before.chars().all(|c| c.is_ascii_hexdigit()) && before.chars().any(|c| c != '0'))
95
+ .then_some(before)
96
+ }
97
+
70
98
  pub(super) fn make_headers(sensitive: bool) -> Result<HeaderMap<HeaderValue>, ClientError> {
71
99
  let mut headers = HeaderMap::new();
72
100
  headers.insert(
@@ -291,6 +319,36 @@ mod tests {
291
319
  assert!(client.is_pr_same_remote());
292
320
  }
293
321
 
322
+ #[test]
323
+ fn pull_request_target_is_pr_event() {
324
+ use crate::RestApiClient;
325
+ use tempfile::NamedTempFile;
326
+
327
+ let mut event_file = NamedTempFile::new().unwrap();
328
+ let payload = serde_json::json!({
329
+ "pull_request": {
330
+ "draft": false,
331
+ "state": "open",
332
+ "number": 42,
333
+ "locked": false,
334
+ "head": {"repo": {"id": 200, "full_name": "fork/repo"}},
335
+ "base": {"repo": {"id": 100, "full_name": "owner/repo"}}
336
+ }
337
+ });
338
+ std::io::Write::write_all(&mut event_file, payload.to_string().as_bytes()).unwrap();
339
+ unsafe {
340
+ env::set_var("GITHUB_REPOSITORY", "2bndy5/git-bot-feedback");
341
+ // For this event, `GITHUB_SHA` is the last commit on the PR's base branch.
342
+ env::set_var("GITHUB_SHA", "abc123");
343
+ env::set_var("GITHUB_EVENT_NAME", "pull_request_target");
344
+ env::set_var("GITHUB_EVENT_PATH", event_file.path());
345
+ }
346
+ let client = GithubApiClient::new().unwrap();
347
+ assert_eq!(client.event_name().as_deref(), Some("pull_request_target"));
348
+ assert!(client.is_pr_event());
349
+ assert!(!client.is_pr_same_remote());
350
+ }
351
+
294
352
  #[test]
295
353
  fn is_pr_same_remote_fork() {
296
354
  use crate::RestApiClient;
@@ -54,13 +54,30 @@ wheels = [
54
54
  { url = "https://files.pythonhosted.org/packages/a0/59/76ab57e3fe74484f48a53f8e337171b4a2349e506eabe136d7e01d059086/backports_asyncio_runner-1.2.0-py3-none-any.whl", hash = "sha256:0da0a936a8aeb554eccb426dc55af3ba63bcdc69fa1a600b5bb305413a4477b5", size = 12313, upload-time = "2025-07-02T02:27:14.263Z" },
55
55
  ]
56
56
 
57
+ [[package]]
58
+ name = "beautifulsoup4"
59
+ version = "4.6.3"
60
+ source = { registry = "https://pypi.org/simple" }
61
+ resolution-markers = [
62
+ "python_full_version >= '3.11' and python_full_version < '3.11.5'",
63
+ "python_full_version < '3.11'",
64
+ ]
65
+ sdist = { url = "https://files.pythonhosted.org/packages/88/df/86bffad6309f74f3ff85ea69344a078fc30003270c8df6894fca7a3c72ff/beautifulsoup4-4.6.3.tar.gz", hash = "sha256:90f8e61121d6ae58362ce3bed8cd997efb00c914eae0ff3d363c32f9a9822d10", size = 167469, upload-time = "2018-08-12T16:39:49.655Z" }
66
+ wheels = [
67
+ { url = "https://files.pythonhosted.org/packages/21/0a/47fdf541c97fd9b6a610cb5fd518175308a7cc60569962e776ac52420387/beautifulsoup4-4.6.3-py3-none-any.whl", hash = "sha256:194ec62a25438adcb3fdb06378b26559eda1ea8a747367d34c33cef9c7f48d57", size = 90375, upload-time = "2018-08-12T16:39:48.02Z" },
68
+ ]
69
+
57
70
  [[package]]
58
71
  name = "beautifulsoup4"
59
72
  version = "4.15.0"
60
73
  source = { registry = "https://pypi.org/simple" }
74
+ resolution-markers = [
75
+ "python_full_version >= '3.13'",
76
+ "python_full_version == '3.12.*'",
77
+ "python_full_version >= '3.11.5' and python_full_version < '3.12'",
78
+ ]
61
79
  dependencies = [
62
- { name = "soupsieve", version = "2.10", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11.5'" },
63
- { name = "soupsieve", version = "4.0.1", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11.5'" },
80
+ { name = "soupsieve" },
64
81
  { name = "typing-extensions" },
65
82
  ]
66
83
  sdist = { url = "https://files.pythonhosted.org/packages/43/65/318323f98dbee45d42dff61d8f047181bc6f2268a9068cfad035a46be5af/beautifulsoup4-4.15.0.tar.gz", hash = "sha256:288e3ca7d54b06f2ac191970bc275c1939cb46d450b255bf6718b04aa37ab4f7", size = 632571, upload-time = "2026-06-07T16:44:20.453Z" }
@@ -305,7 +322,8 @@ version = "2025.12.19"
305
322
  source = { registry = "https://pypi.org/simple" }
306
323
  dependencies = [
307
324
  { name = "accessible-pygments" },
308
- { name = "beautifulsoup4" },
325
+ { name = "beautifulsoup4", version = "4.6.3", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11.5'" },
326
+ { name = "beautifulsoup4", version = "4.15.0", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11.5'" },
309
327
  { name = "pygments" },
310
328
  { name = "sphinx", version = "8.1.3", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" },
311
329
  { name = "sphinx", version = "9.0.4", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version == '3.11.*'" },
@@ -632,29 +650,11 @@ wheels = [
632
650
 
633
651
  [[package]]
634
652
  name = "soupsieve"
635
- version = "2.10"
653
+ version = "4.0"
636
654
  source = { registry = "https://pypi.org/simple" }
637
- resolution-markers = [
638
- "python_full_version >= '3.11' and python_full_version < '3.11.5'",
639
- "python_full_version < '3.11'",
640
- ]
641
- sdist = { url = "https://files.pythonhosted.org/packages/71/c3/1b817965ac12dc002d7c9cd7dfffdd7d4fbf9b45763ef2ffe7b86ee94670/soupsieve-2.10.tar.gz", hash = "sha256:49e9380d7d2905463583bafe285e818c7366a9ed7b3aee221c1ac79c905d8bc0", size = 124337, upload-time = "2026-09-24T02:36:35.048Z" }
642
- wheels = [
643
- { url = "https://files.pythonhosted.org/packages/66/87/5ed59e1d0290564e2027ed066c52b059892c4637741337fc0967183c8d4d/soupsieve-2.10-py3-none-any.whl", hash = "sha256:8596eb8967d744174820280fa62b4542a2e955bfaccca73ed8a13c6eb8e9b502", size = 38019, upload-time = "2026-09-24T02:36:33.709Z" },
644
- ]
645
-
646
- [[package]]
647
- name = "soupsieve"
648
- version = "4.0.1"
649
- source = { registry = "https://pypi.org/simple" }
650
- resolution-markers = [
651
- "python_full_version >= '3.13'",
652
- "python_full_version == '3.12.*'",
653
- "python_full_version >= '3.11.5' and python_full_version < '3.12'",
654
- ]
655
- sdist = { url = "https://files.pythonhosted.org/packages/01/7c/a64eedae0b7776cb9602d2da9cb8f8caae8e1b4c1da5e8e87bf1e68121ec/soupsieve-4.0.1.tar.gz", hash = "sha256:7621e3c5f6b371ed2c5eabaac5de300ac3d66d05e6d7f34783e31b63c4f90c75", size = 153302, upload-time = "2026-11-04T16:36:27.749Z" }
655
+ sdist = { url = "https://files.pythonhosted.org/packages/7d/5e/19b7c5d20bc2f226c44f33a9d9aab9740efed7555b96e656231fd564e514/soupsieve-4.0.tar.gz", hash = "sha256:ccd6470b256394ac44b08b86fd94b30a17d335a5335c8a3d15565f7b03d3c8cf", size = 151929, upload-time = "2026-11-03T14:28:55.388Z" }
656
656
  wheels = [
657
- { url = "https://files.pythonhosted.org/packages/2c/5c/4f68370847b561a389dd9a2d7eb3d19fd8cbb8acbae543a0c6b8d0d9700b/soupsieve-4.0.1-py3-none-any.whl", hash = "sha256:2e68cf7dd5a0f29d81f9d485275ccf294e6475f615e211895d91cb81f8614f04", size = 50688, upload-time = "2026-11-04T16:36:26.158Z" },
657
+ { url = "https://files.pythonhosted.org/packages/4f/18/d24df2f733ee0655c58717d51add4118a70e64692d0e47d403b9aac4cf98/soupsieve-4.0-py3-none-any.whl", hash = "sha256:5e7494bfce90e06676cfb4c5c2cf22243e98e5cf24646bb1ecdda46d318550a0", size = 50158, upload-time = "2026-11-03T14:28:53.988Z" },
658
658
  ]
659
659
 
660
660
  [[package]]