diff --git a/index.html b/index.html index 2dbf584..35fc4e0 100644 --- a/index.html +++ b/index.html @@ -41,10 +41,19 @@

Issues

diff --git a/index.js b/index.js index 1084ed8..d533c7b 100644 --- a/index.js +++ b/index.js @@ -1,22 +1,50 @@ +const userName = '' +const baseApi = 'https://api.github.com/' +const fork = `${userName}/javascript-fetch-lab` + function getIssues() { + + fetch(`${baseApi}repos/${fork}/issues`). + then(resp => resp.json()). + then(json => showIssues(json)) } function showIssues(json) { + const template = Handlebars.compile(document.getElementById('issues-template').innerHTML) + document.getElementById('issues').innerHTML = template(json) } function createIssue() { + const issueTitle = document.getElementById('title').value + const issueBody = document.getElementById('body').value + const postData = { title: issueTitle, body: issueBody } + + fetch(`${baseApi}repos/${fork}/issues`, { + method: 'post', + headers: { + Authorization: `token ${getToken()}` + }, + body: JSON.stringify(postData) + }).then(resp => getIssues()) } function showResults(json) { + const template = Handlebars.compile(document.getElementById('repo-template').innerHTML) + document.getElementById('results').innerHTML = template(json) } function forkRepo() { const repo = 'learn-co-curriculum/javascript-fetch-lab' - //use fetch to fork it! + + fetch(`${baseApi}repos/${repo}/forks`, { + method: 'post', + headers: { + Authorization: `token ${getToken()}` + } + }).then(resp => resp.json()). + then(json => showResults(json)) } function getToken() { - //change to your token to run in browser, but set - //back to '' before committing so all tests pass return '' }