gpt4 book ai didi

javascript - 如何在 Github Issue on create (API) 上发表评论

转载 作者:行者123 更新时间:2023-12-03 03:40:41 24 4
gpt4 key购买 nike

据我了解,当我通过 API 创建 GitHub 问题时,可以提交初始正文/评论,如下所示:

var issue = {
"title": title,
"body": bodytext,
"assignees":[]
};
$.ajax({
type: "POST",
url: uploadURL,
contentType: "application/json",
dataType: "json",
data: JSON.stringify(issue)
})
.done(function( data ) {
console.log(data);
});

是否有办法在原创过程中对该问题单独发表评论?谢谢!

最佳答案

创建问题 API 调用在其响应中返回问题编号 ( https://developer.github.com/v3/issues/#create-an-issue )。

您只需在第一个针对该问题创建评论的请求 ( https://developer.github.com/v3/issues/comments/#create-a-comment ) 之后启动另一个请求即可。

示例可能如下所示:

var issue = {
"title": title,
"body": bodytext,
"assignees":[]
};

function createIssue(data) {
return $.ajax({
type: "POST",
url: "/repos/:owner/:repo/issues",
contentType: "application/json",
dataType: "json",
data: JSON.stringify(data)
}).then(function (response) {
// Return issue number from the response to the promise chain

return response.number;
});
}

function createComment(issueNumber, data) {
return $.ajax({
type: "POST",
url: "/repos/:owner/:repo/issues/" + issueNumber + "/comments",
contentType: "application/json",
dataType: "json",
data: JSON.stringify(data)
});
}

createIssue(issue).then(function (issueNumber) {
return createComment(
issueNumber,
{
// comment details
}
);
}).done(function () {
// callback on successful issue & comment creation
});

关于javascript - 如何在 Github Issue on create (API) 上发表评论,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45641782/

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