Skip to content

Fix getLabel() nullability for unlabeled events when label was deleted#2211

Open
Haarolean wants to merge 1 commit intohub4j:mainfrom
Haarolean:bugfix/webhook-label-null-handling
Open

Fix getLabel() nullability for unlabeled events when label was deleted#2211
Haarolean wants to merge 1 commit intohub4j:mainfrom
Haarolean:bugfix/webhook-label-null-handling

Conversation

@Haarolean
Copy link
Copy Markdown
Contributor

Description

When a label is deleted from a GitHub repository, GitHub sends unlabeled webhook events for every issue/PR that had it. Unlike normal unlabeled events, the payload omits the top-level label object entirely, causing getLabel() to return null.

This was undocumented — the javadoc implied the label is always present for labeled/unlabeled actions, likely leading consumers to NPE.

Changes

  • Added @CheckForNull annotation to getLabel() in GHEventPayload.Discussion, GHEventPayload.Issue, and GHEventPayload.PullRequest
  • Updated javadoc to document when null is returned
  • Added test case with a fixture that has no label field

GHEventPayload.Label.getLabel() is intentionally left unchanged — the label is the subject of that event type and should always be present.

Before submitting a PR:

  • Changes must not break binary backwards compatibility. If you are unclear on how to make the change you think is needed while maintaining backward compatibility, CONTRIBUTING.md for details.
  • Add JavaDocs and other comments explaining the behavior.
  • When adding or updating methods that fetch entities, add @link JavaDoc entries to the relevant documentation on https://docs.github.com/en/rest .
  • Add tests that cover any added or changed code. This generally requires capturing snapshot test data. See CONTRIBUTING.md for details.
  • Run mvn -D enable-ci clean install site "-Dsurefire.argLine=--add-opens java.base/java.net=ALL-UNNAMED" locally. If this command doesn't succeed, your change will not pass CI.
  • Push your changes to a branch other than main. You will create your PR from that branch.

When creating a PR:

  • Fill in the "Description" above with clear summary of the changes. This includes:
    • If this PR fixes one or more issues, include "Fixes #" lines for each issue.
    • Provide links to relevant documentation on https://docs.github.com/en/rest where possible. If not including links, explain why not.
  • All lines of new code should be covered by tests as reported by code coverage. Any lines that are not covered must have PR comments explaining why they cannot be covered. For example, "Reaching this particular exception is hard and is not a particular common scenario."
  • Enable "Allow edits from maintainers".

@Haarolean Haarolean force-pushed the bugfix/webhook-label-null-handling branch from a85ff6b to 0e9648f Compare March 30, 2026 14:07
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.14%. Comparing base (3ecd46e) to head (0e9648f).

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #2211   +/-   ##
=========================================
  Coverage     85.14%   85.14%           
  Complexity     2525     2525           
=========================================
  Files           239      239           
  Lines          7461     7461           
  Branches        393      393           
=========================================
  Hits           6353     6353           
  Misses          872      872           
  Partials        236      236           

☔ View full report in Codecov by Sentry.
📢 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.

1 participant