davsclaus opened a new pull request, #3293:
URL: https://github.com/apache/camel-kamelets/pull/3293

   Fixes #3291.
   
   ## The problem (verified)
   
   `github-pullrequest-source`, `github-pullrequest-comment-source` and 
`github-tag-source` wrote the `GHPullRequest`, `GHIssueComment` and `GHTag` 
objects of the `github2` component with `marshal: json`. Jackson calls every 
getter, and many getters of the GitHub library read more from the GitHub API. 
Verified with the GitHub API stand-in of the Citrus tests (`GitHubApiStub`, 
which now lists every request), one new item per Kamelet, on `main`:
   
   - `github-tag-source`: `GET repos/<o>/<r>/commits/<sha>` 
(`GHTag["commit"]->GHCommit["author"]`); with that answered, then 
`users/<login>`, then `users/<login>/followers`, ...
   - `github-pullrequest-source`: `GET repos/<o>/<r>/pulls/<n>`; with that 
answered, then `repos/<o>/<r>/commits/<sha>`, ...
   - `github-pullrequest-comment-source`: `GET repos/<o>/<r>/pulls/<n>` 
(`GHIssueComment["parent"]->GHPullRequest["additions"]`), ...
   
   When one of these requests failed (here a 404; against github.com also a 
rate limit or missing permission), the message failed at `marshal1` with a 
`DatabindException`. The consumer had already moved past the item, so the 
message was lost: none of the three tests got a message on `main`.
   
   ## The fix
   
   - The object is written from its **fields** with 
`GitHub.getMappingObjectWriter()`, the writer the GitHub library offers for its 
objects. It reads no getter, so it makes no request. It is a local bean of the 
template, made with `factoryMethod`.
   - `jq` then keeps the fields the description lists. The fields-only JSON 
also holds internal state of the library (the owning repository again and 
again, caches such as `milestones: {}`, `compare_use_paginated_commits`). It 
also holds counts that the list endpoint does not return, so they read `0` or 
`null` (`additions`, `commits`, `mergeable`).
   - `Content-Type: application/json` is set as before. `camel:jackson3` is 
replaced by `camel:jq`, which brings in Jackson 3 for its own use.
   
   ## Behaviour change (output shape)
   
   Before, the body was every getter of the library object, with camelCase 
names (`htmlUrl`, ...), after the extra requests had been made. The body is now 
JSON text (a `String`, before an `InputStreamCache`) with these field names, as 
the GitHub API uses them:
   
   - **pull request**: `number`, `title`, `body`, `state`, `draft`, `html_url`, 
`user.login`, `head` / `base` (`ref`, `sha`, `label`), `labels[].name`, 
`created_at`, `updated_at`
   - **comment**: `id`, `body`, `html_url`, `user.login`, `author_association`, 
`created_at`, `updated_at`
   - **tag**: `name`, `commit.sha`
   
   The headers are unchanged. Data that only the extra requests gave (the size 
of a pull request, whether it can be merged, details of the commit of a tag) is 
no longer in the body. The descriptions now list the fields and say this. This 
change needs an entry in the upgrade notes (#3190).
   
   ## Tests
   
   - `GitHubApiStub`: lists every request (`requests()`), and gives 
`<path>.first.json` as the answer to the first request of a path. That way a 
source that skips what exists at start can be shown something new.
   - New Citrus tests `github-pullrequest-source-route`, 
`github-pullrequest-comment-source-route` and `github-tag-source-route`, each 
on its own canned repository. They check the body (as JSON), its Java type, the 
Content-Type and the headers. `onlyPolls.groovy` checks that the source asked 
the GitHub API for nothing beyond its polls.
   - `./mvnw -o verify -pl tests/camel-kamelets-itest 
-Dit.test='CloudIT#github'`: Tests run: 5, Failures: 0, Errors: 0 (the 3 new 
tests plus the existing commit and event tests).
   - Before the fix, the same 3 tests got no message (`DatabindException` at 
`marshal1`, see above).
   - `./mvnw clean install` (twice): BUILD SUCCESS. The Kamelets were 
normalized with `camel validate normalize`; the index and the SBOM were 
regenerated.
   
   _Claude Code on behalf of Claus Ibsen_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   
   https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to