diff --git a/index.js b/index.js index 1084ed8..f7d6e11 100644 --- a/index.js +++ b/index.js @@ -1,18 +1,49 @@ +const token = getToken() + function getIssues() { -} + const fork = `shoppersaysso/javascript-fetch-lab` + fetch(`https://api.github.com/repos/${fork}/issues`, { + method: 'get', + headers: { + Authorization: `token ${token}` + } + }).then(resp => resp.json()).then(data => showIssues(data)) + } function showIssues(json) { -} + var div = document.getElementById("issues") + for (var i = 0, l = json.length; i < l; i++) { + $("#issues").append(`
  • ${json[i].title}
  • `) + } + + } function createIssue() { + var title = document.getElementById("title").value + var body = document.getElementById("body").value + var issue = {title: title, body: body} + fetch(`https://api.github.com/repos/shoppersaysso/javascript-fetch-lab/issues`, { + method: 'post', + headers: { + 'Authorization': `token ${token}` + }, + body: JSON.stringify(issue) + }).then(resp => getIssues()); + } function showResults(json) { + $('#results').append(`

    Fork:

    ${json.html_url} - ${json.name}`) } function forkRepo() { - const repo = 'learn-co-curriculum/javascript-fetch-lab' - //use fetch to fork it! + fetch(`https://api.github.com/repos/learn-co-curriculum/javascript-fetch-lab/forks`, { + method: 'post', + headers: { + Authorization: `token ${token}` + } + }).then(res => res.json()).then(json => showResults(json)); + } function getToken() {