Skip to content

GHPullRequest.getLabels fails for parsed events #943

@seregamorph

Description

@seregamorph

Describe the bug
Consider a payload for X-GitHub-Event: pull_request webhook (exact payload in first comment). It has path /pull_request/labels:

...
    "labels": [
      {
        "id": 1545228115,
        "node_id": "MDU6TGFiZWwxNTQ1MjI4MTE1",
        "url": "https://api.github.com/repos/trilogy-group/devfactory-codeserver-framework/labels/rest%20api",
        "name": "rest api",
        "color": "0f288c",
        "default": false,
        "description": ""
      }
    ],
...

To parse this object I call:

GHEventPayload.PullRequest pullRequest = GitHub.offline()
                .parseEventPayload(payloadReader, GHEventPayload.PullRequest.class);

Then if I call pullRequest.getPullRequest().getLabels() it fails:

org.kohsuke.github.GHIOException: Offline
	at org.kohsuke.github.GitHubHttpUrlConnectionClient.getResponseInfo(GitHubHttpUrlConnectionClient.java:64)
	at org.kohsuke.github.GitHubClient.sendRequest(GitHubClient.java:400)
	at org.kohsuke.github.GitHubClient.sendRequest(GitHubClient.java:363)
	at org.kohsuke.github.Requester.fetchInto(Requester.java:89)
	at org.kohsuke.github.GHPullRequest.fetchIssue(GHPullRequest.java:631)
	at org.kohsuke.github.GHPullRequest.getLabels(GHPullRequest.java:182)
	at com.trilogy.restapilistener.controllers.GitHubHookControllerKt.hasRestApiLabel(GitHubHookController.kt:437)
	...
Caused by: java.io.IOException: Offline
	at org.kohsuke.github.HttpConnector.lambda$static$1(HttpConnector.java:39)
	at org.kohsuke.github.GitHubHttpUrlConnectionClient$HttpURLConnectionResponseInfo.setupConnection(GitHubHttpUrlConnectionClient.java:113)
	at org.kohsuke.github.GitHubHttpUrlConnectionClient.getResponseInfo(GitHubHttpUrlConnectionClient.java:61)
	... 66 common frames omitted

But the data is correct before the call. Enforced GHPullRequest.fetchIssue() breaks things.

To Reproduce
Steps to reproduce the behavior:

  1. Set up webhook on gitHub repository with type pull request
    Screen Shot 2020-09-24 at 21 27 19
  2. Fire pull request event, e.g. open a pull request with non-empty labels, or edit existing PR
  3. handle the payload via GitHub.offline().parseEventPayload and try to get labels

Expected behavior
pullRequest.getPullRequest().getLabels() call gives a list of parsed labels (name)

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions