gpt4 book ai didi

api - 如何使用 API (curl) 编辑 github 问题? (尤其是 : close)

转载 作者:行者123 更新时间:2023-12-04 15:50:39 26 4
gpt4 key购买 nike

我计划将在另一个(自制)系统中跟踪的数百个错误迁移到 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"
}'

...但结果是创建一个 Unresolved 问题(即忽略“状态”)。

在我看来,我应该能够“编辑”一个问题以将其关闭 ( https://developer.github.com/v3/issues/#edit-an-issue ) ... 但我无法弄清楚相应的 curl 命令应该是什么样子。有什么指导吗?

额外功劳:我真的希望能够指定一个“关闭”日期,以与我们当前系统中捕获的实际关闭日期一致。目前尚不清楚这是否可能。

谢谢!

最佳答案

使用命令行将一堆问题迁移到 github?你疯了吗?

无论如何,使用 https://github.com/divinity76/hhb_.inc.php/blob/master/hhb_.inc.php 中的 php 和 hhb_curl ,这对我有用,不幸的是无法设置“closed_at”日期(它被 api 忽略),但我可以使用标签模拟它,然后它看起来像

enter image description here

,当将代码移植到命令行时,代码应该为您提供一些工作:

<?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 之前修改了“授权: token ”行)

关于api - 如何使用 API (curl) 编辑 github 问题? (尤其是 : close),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41235024/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com