Skip to content

test(gitea): add unit tests for parse_payload#2787

Open
kshitizj03 wants to merge 1 commit into
tektoncd:mainfrom
kshitizj03:test/2146-gitea-parse-payload-tests
Open

test(gitea): add unit tests for parse_payload#2787
kshitizj03 wants to merge 1 commit into
tektoncd:mainfrom
kshitizj03:test/2146-gitea-parse-payload-tests

Conversation

@kshitizj03

Copy link
Copy Markdown

📝 Description of the Change

The Gitea provider's parse_payload.go only had direct test coverage for the
issue_comment / pull_request_comment path (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 pull
    request payloads, asserting the populated event fields, the
    pull_request_labeled event type, the pull_request_closed trigger 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 before SHA.
  • TestParsePayloadErrors — missing event-type header, an event type the
    webhook 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 calls
ParsePayload; the existing test is updated to use it too. No production code
is changed — this is test-only.

🔗 Linked GitHub Issue

Fixes #2146

🧪 Testing Strategy

  • Unit tests
  • Integration tests
  • End-to-end tests
  • Manual testing
  • Not Applicable

🤖 AI Assistance

  • I have not used any AI assistance for this PR.
  • I have used AI assistance for this PR.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 18, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: kshitizj03 / name: Kshitiz Jain (4ee9c17)

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 theakshaypant left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kshitizj03

Copy link
Copy Markdown
Author

Thanks @theakshaypant , added both cases

Comment thread pkg/provider/gitea/parse_payload_test.go
Comment thread pkg/provider/gitea/parse_payload_test.go
@kshitizj03

Copy link
Copy Markdown
Author

Thanks @zakisk! Addressed both in ba6432c2: the issue-comment test now asserts EventType (empty for the nil-comment case, retest-all-comment otherwise), and added a synchronized action case to TestParsePayloadPullRequest.

@theakshaypant

Copy link
Copy Markdown
Member

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.
This keeps the git history clean and makes it easier for maintainers to review and track changes.

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>
@kshitizj03 kshitizj03 force-pushed the test/2146-gitea-parse-payload-tests branch from ba6432c to 30651a6 Compare June 22, 2026 17:40
@kshitizj03

Copy link
Copy Markdown
Author

Done. Squashed everything into a single commit. Thanks for the guidance on the repo convention, I'll keep PRs to one commit going forward.

@theakshaypant

Copy link
Copy Markdown
Member

/ok-to-test

@codecov

codecov Bot commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.06%. Comparing base (1c0fabc) to head (30651a6).
⚠️ Report is 8 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add unit tests for pkg/provider/gitea/parse_payload.go

3 participants