sumedhe
sumedhe

Reputation: 1018

How to get the linked issue of a project item using GitHub Webhook?

I’ve set up a webhook for projects_v2_item, and whenever I update an entry in the project, it triggers a request with the relevant details. However, while the request contains information about the project item itself, it does not include the linked issue.

How can I retrieve the linked issue from the webhook payload?

{
    "action": "edited",
    "projects_v2_item": {
        "id": 10000001,
        "node_id": "###",
        "project_node_id": "###",
        "content_node_id": "###",
        "content_type": "Issue",
        "creator": {
            "login": "sumedhe",
            "id": 2020370,
            "node_id": "###",
            ...
        },
        "created_at": "2024-10-01T08:29:55Z",
        "updated_at": "2024-10-01T08:31:44Z",
        "archived_at": null
    },
    "changes": {
        "field_value": {
            "field_node_id": "###",
            "field_type": "single_select",
            "field_name": "Status",
            "project_number": 1,
            "from": null,
            "to": {
                "id": "###",
                "name": "Todo",
                "color": "GREEN",
                "description": "This+item+hasn't+been+started"
            }
        }
    },
    "organization": {
        "login": "selforgmap",
        "id": 47916970,
        ...
    },
    "sender": {
        "login": "sumedhe",
        "id": 2020370,
        ...
    }
}

Upvotes: 1

Views: 33

Answers (1)

Ronan Boiteau
Ronan Boiteau

Reputation: 10138

You can use the field content_node_id under projects_v2_item in the JSON received from the GitHub webhook.

If the content_node_id starts with I_ it means your project item is an issue, so you can use GitHub's GraphQL API to get details about the issue from its node ID.

Example with the GitHub CLI:

gh api graphql -f query='query($nodeID: ID!) { 
    node(id: $nodeID) {
        ... on Issue {
            number
        }
    }
}' -f nodeID=CONTENT_NODE_ID_GOES_HERE

Result:

{"data":{"node":{"number":4242}}}

To make this GraphQL query I use a classic token with access to the scope repo.

Upvotes: 1

Related Questions