How to add label to Pull Request via Github API? According to GitHub API user can add label to an issue using this POST request.
I tried using this request but with PR number instead to automatically set label on PR. Here is the function I wrote:
def setLabel (String repository, List labels) {
    try {
        def response = httpRequest httpMode: 'POST',
                    url: &quot;https:[Repo_URL]/${repository}/issues/${CHANGE_ID}/labels&quot;,
                    authentication: 'ors_git_service_account',
                    requestBody: &quot;&quot;&quot;{
                        &quot;labels&quot;: labels
                    }&quot;&quot;&quot;
    } catch (e) {
        wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'XTerm']) {
            echo &quot;\u001B[31magdSlack.setLabels: '&quot; + e.toString() + &quot;'\u001B[0m&quot;
        }
        throw e
    }
}

And the response I get is HTTP/1.1 400 Bad Request
So I get that this request can't be used to labeling PRs.
My question: Is there other method which could be triggered from Jenkinsfile, to add or change PR label?
Closest thing to the question I asked was this question. Commenting API works on issues and PRs but that's not a case for labels.
I made it work by changing the way labels argument is passed into requestBody.
Turns out the list representation while interpolated into string is missing quotation marks around each list element.
def setLabels (String repository, List label) {
    try {
        String labelsAsString = &quot;[\&quot;${label.join('&quot;, &quot;')}\&quot;]&quot;
        def response = httpRequest httpMode: 'POST',
                        url: &quot;[REPO_URL]/${repository}/issues/${CHANGE_ID}/labels&quot;,
                        authentication: 'ors_git_service_account',
                        requestBody: &quot;&quot;&quot;{
                            &quot;labels&quot;: ${labelsAsString}
                        }&quot;&quot;&quot;
    } catch (e) {
        wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'XTerm']) {
            echo &quot;\u001B[31magdSlack.setLabels: '&quot; + e.toString() + &quot;'\u001B[0m&quot;
        }
        throw e
    }
}