无法使用Github API将注释发布到Pull请求



我正在使用GitHub API为Pull Request创建注释。

以下内容:

我不想对具体的代码行发表评论,而是对PR本身发表一般性评论。例如说"谢谢你的公关@作者">

// 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));

这将返回以下错误:

{
"message": "Invalid request.nnFor 'links/0/schema', nil is not an object.",
"documentation_url": "https://developer.github.com/v3/issues/comments/#create-a-comment"
}

我在文档中读到,links没有被提到作为这个请求的参数,所以这让我更加困惑。

PS:所有其他操作,如获取评论列表、获取评论列表,删除评论、向PR添加标签、从PR删除标签等,都运行良好。

我在某个地方发现,他们说评论需要一些额外的身份验证。我不知道这到底意味着什么,也不知道我是如何做到的。

我只有个人访问令牌来验证我的请求。

请告诉我遗漏了什么。

我能够使用issuesapi而不是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;
}

HttpRequest类是内部库的一部分,在这里并不重要。您应该能够使用任何Http传输方法。

唯一重要的是请求url和请求数据。

确保为使用中的ACCESS_TOKEN分配了正确的权限。我现在不记得了,等我有机会看的时候会添加到这里。

最新更新