test(gitea): add unit tests for parse_payload#2787
Conversation
|
|
There was a problem hiding this comment.
Code Review
This pull request refactors the Gitea payload parsing tests in pkg/provider/gitea/parse_payload_test.go by introducing helper functions like parseGiteaPayload and prPayload. It also adds comprehensive new unit tests covering pull requests, push events, error handling, and event population from Gitea pull requests. As there are no review comments, no further feedback is provided.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
theakshaypant
left a comment
There was a problem hiding this comment.
Thanks @kshitizj03 for picking this up and nice work on the test coverage! The structure is clean and the core logic paths are well-covered.
Two additional test cases in TestParsePayloadIssueCommentPullRequestData would strengthen this further
"empty issue URL falls back to PullRequest Index": Sets Issue.URL to "" with a non-nil PullRequest carrying Index: 2787, and asserts PullRequestNumber is 2787, covering the else if gitEvent.PullRequest != nil fallback branch."nil comment skips event type override": Omits the comment field from the payload and asserts that TriggerTarget stays as triggertype.PullRequest without being overridden by opscomments.SetEventTypeAndTargetPR.
|
Thanks @theakshaypant , added both cases |
|
Thanks @zakisk! Addressed both in |
|
Thanks @kshitizj03 for being patient with the requested changes. One convention that we follow in the repository is to use a single commit per PR. Instead of adding new commits for each round of reviews, could you please amend your initial commit and force push. |
Add table-driven unit tests for pkg/provider/gitea/parse_payload.go: - TestParsePayloadPullRequest covers the opened, synchronized, label_updated and closed actions (event type, trigger target and label extraction). - TestParsePayloadPush covers the head_commit path and the before-SHA fallback. - TestParsePayloadErrors covers a missing event-type header, an unknown webhook type, a parsed-but-unsupported type and invalid JSON. - TestPopulateEventFromGiteaPullRequest covers the nil PR, full PR, missing head/base repositories and missing SHA cases. - TestParsePayloadIssueCommentPullRequestData additionally asserts the resolved EventType (so the nil-comment case verifies the override is skipped) and the PullRequest.Index fallback when the issue URL is empty. A shared parseGiteaPayload helper builds the request and calls ParsePayload, and prPayload builds pull_request webhook bodies. Co-authored-by: Claude <noreply@anthropic.com> Signed-off-by: Kshitiz Jain <kshitizj@gmail.com>
ba6432c to
30651a6
Compare
|
Done. Squashed everything into a single commit. Thanks for the guidance on the repo convention, I'll keep PRs to one commit going forward. |
|
/ok-to-test |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2787 +/- ##
==========================================
+ Coverage 59.73% 60.06% +0.32%
==========================================
Files 210 210
Lines 21117 21117
==========================================
+ Hits 12615 12683 +68
+ Misses 7707 7641 -66
+ Partials 795 793 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
📝 Description of the Change
The Gitea provider's
parse_payload.goonly had direct test coverage for theissue_comment/pull_request_commentpath (TestParsePayloadIssueCommentPullRequestData).This adds table-driven unit tests for the remaining event handling, following
the structure suggested on the issue:
TestParsePayloadPullRequest— opened,label_updated, and closed pullrequest payloads, asserting the populated event fields, the
pull_request_labeledevent type, thepull_request_closedtrigger target,and label extraction.
TestParsePayloadPush— push payloads with and without a head commit,covering the head-commit SHA/URL/title path and the fallback to the
beforeSHA.TestParsePayloadErrors— missing event-type header, an event type thewebhook parser rejects, a parsed event type unsupported by
ParsePayload,and an invalid JSON body.
TestPopulateEventFromGiteaPullRequest— direct coverage of the helper(nil pull request, fully populated, missing head/base repositories, and the
missing-SHA case that skips the SHA URL).
A small
parseGiteaPayload()test helper builds the request and callsParsePayload; the existing test is updated to use it too. No production codeis changed — this is test-only.
🔗 Linked GitHub Issue
Fixes #2146
🧪 Testing Strategy
🤖 AI Assistance