2017-08-11 70 views
0

我明白,當我通過API創建一個GitHub的問題,像這樣我就可以提交初始體/評論評論:如何使在Github上發佈關於創建(API)

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); 
    }); 

是否有還可以在原創過程中對這個問題單獨發表評論?謝謝!

回答

1

創建發行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 
}); 
+0

我沒有意識到的是,createIssue調用返回的發行數量,出色的洞察力,謝謝!我會接受你的答案。用你的代碼,我確實碰巧得到了錯誤:「TypeError:createIssue(...)未定義」任何想法? – Acoustic77

+0

在控制檯中粘貼它工作得很好,所以我認爲在您的項目中粘貼或包含此代碼的方式必須存在問題。 – mdziekon