我正在使用GitHub API创建注释来提取请求。
此后:
我不想评论具体的代码行,而是对PR本身的一般性评论。比如说“谢谢你的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.\n\nFor 'links/0/schema', nil is not an object.",
"documentation_url": "https://developer.github.com/v3/issues/comments/#create-a-comment"
}
我在文档中看到的是,links
没有被提到作为这个请求的一个参数,所以这让我更加困惑。
PS:所有其他操作,如get评论列表、获取评论列表、删除评论、向PR添加标签、从PR中删除标签等操作都很正常。
我找到了一些地方,他们说,需要一些额外的身份验证来进行评论。我不知道这到底意味着什么,也不知道我是如何做到这一点的。
我只有个人存取令牌来验证我的请求。
请告诉我错过了什么。
发布于 2019-02-21 12:19:55
我能够使用issues
api而不是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、headers和request data。
确保使用中的ACCESS_TOKEN分配了正确的权限。我现在不记得了,我有机会看的时候会在这里加一句。
https://stackoverflow.com/questions/53047565
复制相似问题