【问题标题】:How to use Github API v3 to create Pull Request reviews?如何使用 Github API v3 创建 Pull Request 评论?
【发布时间】:2017-10-31 10:21:59
【问题描述】:
在 Github API v3 文档上,how to create a pull request review using the API 上有一篇文章。
有这一行:
POST /repos/:owner/:repo/pulls/:number/requested_reviewers
有人可以用一个例子来解释我该怎么做吗? curl 命令会更可取。我可以猜到它是 POST 消息的某种格式,但是如何触发 POST 调用?
对任何示例的任何帮助将不胜感激。
编辑
我自己想出了一个方法,但如果可能的话,我也希望看到一些 Pythonic 的方法。
【问题讨论】:
标签:
python
curl
post
github-api
【解决方案1】:
好的。
所以在我自己尝试了一些之后,我弄清楚了这实际上意味着什么以及如何使用这些调用。分享给未来的访客。
以:开头的术语实际上是变量,需要替换为值。因此,以创建拉取请求评论为例,curl 命令如下所示:
curl "https://api.github.com/repos/<repo-owner-username>/<project-name>/pulls/<pull-number>/requested_reviewers?access_token=<personal-access-token-for-github>" -H "Content-Type: application/json" -X POST -d "{\"reviewers\":[\"reviewer1\"]}"
同样,您可以按照 Github API 文档中为其他情况指定的格式,并生成 curl 调用。
【解决方案2】:
对于pythonic方式,可以使用string.Template的子类。
以你为例:
from string import Template
class URLTemplate(Template):
delimiter = ':'
post_url = URLTemplate('/repos/:owner/:repo/pulls/:number/requested_reviewers')
post_param = {
'owner': 'myself',
'repo': 'secret_one'
}
print(post_url.substitute(number=42, **post_param))
将产生:
/repos/myself/secret_one/pulls/42/requested_reviewers