我计划将另一个(自制)系统中跟踪的几百个错误迁移到GitHub的问题系统中。大多数这些错误在过去都被关闭了。我可以使用github的API来创建一个问题,例如
curl -u $GITHUB_TOKEN:x-oauth-basic https://api.github.com/repos/my_organization/my_repo/issues -d '{
"title": "test",
"body": "the body"
}'
...然而,这将给我留下一堆悬而未决的问题。如何关闭?我在创作时试图关闭,例如:
curl -u $GITHUB_TOKEN:x-oauth-basic https://api.github.com/repos/my_organization/my_repo/issues -d '{
"title": "test",
"body": "the body",
"state": "closed"
}'
...但结果是创建一个开放的问题(即"状态"被忽略)。
在我看来,我应该能够"编辑"关闭它的问题(https://developer.github.com/v3/issues/#edit-an-issue)...但是我无法弄清楚相应的curl命令应该是什么样子。有什么指导吗?
额外信用:我真的喜欢能够分配一个"已关闭"日期,同意我们当前系统中捕获的实际关闭日期。目前尚不清楚这是可能的。
谢谢!
答案 0 :(得分:1)
使用命令行将一堆问题迁移到github?你疯了吗?
无论如何,使用来自https://github.com/divinity76/hhb_.inc.php/blob/master/hhb_.inc.php的php和hhb_curl, 这对我有用,遗憾的是无法设置“closed_at”日期(它被api忽略),但我可以使用标签来模拟它,然后看起来像
,在将代码移植到命令行时,代码应该为您提供一些工作:
<?php
declare(strict_types = 1);
require_once ('hhb_.inc.php');
$hc=new hhb_curl();
define('BASE_URL','https://api.github.com');
$hc->_setComfortableOptions();
$data=array(
'state'=>'closed',
'closed_at'=> '2011-04-22T13:33:48Z',// << unfortunately, ignored
'labels'=>array(
'closed at 2011-04-22T13:33:48Z' // << we can fake it using labels...
)
);
$data=json_encode($data);
$hc->setopt_array(array(
CURLOPT_CUSTOMREQUEST=>'PATCH',
// /repos/:owner/:repo/issues/:number
// https://github.com/divinity76/GitHubCrashTest/issues/1
CURLOPT_URL=>BASE_URL.'/repos/divinity76/GitHubCrashTest/issues/1',
CURLOPT_USERAGENT=>'test',
CURLOPT_HTTPHEADER=>array(
'Accept: application/vnd.github.v3+json',
'Content-Type: application/json',
'Authorization: token <removed>'
),
CURLOPT_POSTFIELDS=>$data,
));
$hc->exec();
hhb_var_dump($hc->getStdErr(),$hc->getResponseBody());
(我在将它发布到stackoverflow ofc之前修改了“Authorization:token”行)
答案 1 :(得分:1)
正如hanshenrik所建议的,正确改变的curl命令是:
curl -u $GITHUB_TOKEN:x-oauth-basic https://api.github.com/repos/my_organization/my_repo/issues/5 -d '{
"state": "closed"
}'
我未能理解他回答中引用的文档: /回购/:业主/:回购/问题/:数 翻译成 https://api.github.com/repos/my_organization/my_repo/issues/5 (我现在明白以&#34;:&#34;开头的字段是变量)
为了记录,我计划将调用脚本编写为curl。 :)