如何使用API​​(curl)编辑github问题? (尤其是:关闭) [英] How to edit a github issue using the API (curl)? (especially: close)

查看:105
本文介绍了如何使用API​​(curl)编辑github问题? (尤其是:关闭)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正计划将在另一个(本垒打)系统中跟踪的数百个错误迁移到GitHub的问题系统中.这些错误大多数都是在过去关闭的.我可以使用github的API来创建问题,例如

I'm planning to migrate a couple hundred bugs tracked in another (home-rolled) system into GitHub's issue system. Most of these bugs were closed in the past. I can use github's API to create an issue, e.g.

curl -u $GITHUB_TOKEN:x-oauth-basic https://api.github.com/repos/my_organization/my_repo/issues -d '{
    "title": "test",
    "body": "the body"
}'

...但是,这将给我带来许多未解决的问题.如何关闭那些?我尝试在创建时关闭,例如:

... however, this will leave me with a bunch of open issues. How to close those? I've tried just closing at the time of creation, e.g.:

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"
}'

...但是结果是造成一个未解决的问题(即状态"被忽略).

... but the result is to create an open issue (i.e. the "state" is ignored).

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

It looks to me like I should be able to "edit" an issue to close it (https://developer.github.com/v3/issues/#edit-an-issue) ... but I'm unable to figure out what the corresponding curl command is supposed to look like. Any guidance?

额外的功劳:我真的想分配一个关闭"日期,以便与我们当前系统中捕获的实际关闭日期一致.尚不清楚这是否可能.

Extra credit: I'd really like to be able to assign a "closed" date, to agree with the actual closed date captured in our current system. It's not clear that this is possible.

谢谢!

推荐答案

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

migrating a bunch of issues to github with the command line? are you crazy?

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

anyway, using php and hhb_curl from https://github.com/divinity76/hhb_.inc.php/blob/master/hhb_.inc.php , this worked for me, unfortunately couldn't set the "closed_at" date (it was ignored by the api), but i could emulate it using labels, then it looked like

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

, the code should give you something to work on when porting it to command line:

<?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());

(我在将其发布到c的stackoverflow之前修改了授权:令牌"行)

(i modified the "Authorization: token" line before posting it on stackoverflow ofc)

这篇关于如何使用API​​(curl)编辑github问题? (尤其是:关闭)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆