Reputation: 935
I am using GitHub API to create comments to Pull Requests.
Following this:
I do not want to comment to specific line of code, rather a general comment to the PR itself. Say for example "Thanks for your PR @author"
// Using Joomla Http library that uses cURL internally
$http = new HttpRequest;
// The url variables below are set to the respective correct values
$url = "https://api.github.com/repos/{$owner}/{$repo}/issues/{$number}/comments";
// Method: post($url, $data, $headers);
$resp = $http->post($url, array('body' => 'Thanks for your PR @author'), array('Authorization' => 'token ' . PERSONAL_ACCESS_TOKEN));
This returns the following error:
{
"message": "Invalid request.\n\nFor 'links/0/schema', nil is not an object.",
"documentation_url": "https://developer.github.com/v3/issues/comments/#create-a-comment"
}
What I read in the docs, links
is nowhere mentioned as a parameter for this request, so this is confusing me more.
PS: All other operations such as get reviews list, get comments list, delete a comment, add a label to PR, remove a label from PR etc. are working fine.
I found somewhere they say some additional authentication is required for commenting. I am not sure what that exactly mean and how I achieve that.
I have only Personal Access Token to validate my requests.
Please advise what I am missing.
Upvotes: 1
Views: 1846
Reputation: 935
I was able to post the comment using issues
api instead of pull-request
public function comment($message)
{
$http = new HttpRequest;
$url = "https://api.github.com/repos/{$this->owner}/{$this->repo}/issues/{$this->num}/comments";
$headers = array(
'Content-Type' => 'application/json;charset=utf-8',
'Authorization' => 'token ' . GITHUB_ACCESS_TOKEN,
);
$resp = $http->post($url, json_encode(array('body' => $message)), $headers);
return $resp->code == 201 ? $resp : null;
}
The HttpRequest
class in part of an internal library which is not much important here. You should be able to use any Http transport method.
Only important things are the request url, headers and request data.
Make sure the ACCESS_TOKEN in use is assigned the correct permissions. I can't remember it for now, will add here when I get a chance to look at it.
Upvotes: 1