diff --git a/index.js b/index.js index 1bb35ab..71a9a96 100644 --- a/index.js +++ b/index.js @@ -63,8 +63,32 @@ ipcMain.on('login', async () => { }, false); }); +ipcMain.on('changeProject', () => { + repo = undefined; -ipcMain.on('chooseDir', async function(event, data) { + let altWin = new BrowserWindow({ + width: 1280, + height: 800, + webPreferences: { + nodeIntegration: true + } + }); + + // load the index.html file + altWin.loadFile('src/intro.html'); + + if(user.name == undefined || user.email == undefined) { + win.webContents.on('did-finish-load', function() { + win.webContents.send('get-user-name', true); + }); + } + + win.destroy(); + win = altWin; + altWin = undefined; +}); + +ipcMain.on('chooseDir', function() { // set dir dir = modules.chooseDir(win); @@ -72,15 +96,43 @@ ipcMain.on('chooseDir', async function(event, data) { win.loadFile('src/index.html'); // load the user info - repo = await modules.getRepoInfo(dir); + repo = modules.getRepoInfo(dir); // when done loading the window, send the details. win.webContents.on('did-finish-load', () => { win.webContents.send('send_username', user.name); win.webContents.send('send_useremail', user.email); - win.webContents.send('send_remote', repo.remote); - win.webContents.send('send_status', repo.status); - win.webContents.send('send_log', repo.log); - win.webContents.send('send_branch', repo.branch); + try { + win.webContents.send('send_remote', repo.remote); + win.webContents.send('send_status', repo.status); + win.webContents.send('send_log', repo.log); + win.webContents.send('send_branch', repo.branch); + } catch(e) { + console.log('repo send 2.'); + } }); +}); + +ipcMain.on('gotoCommit', function() { + win.loadFile('src/commit.html'); + win.webContents.on('did-finish-load', () => { + win.webContents.send('send_username', user.name); + win.webContents.send('send_useremail', user.email); + try { + win.webContents.send('send_remote', repo.remote); + win.webContents.send('send_status', repo.status); + win.webContents.send('send_log', repo.log); + win.webContents.send('send_branch', repo.branch); + } catch(e) { + console.log('repo send 2.'); + } + }); +}); + +ipcMain.on('gotoOverview', function() { + win.loadFile('src/index.html'); +}); + +ipcMain.on('getCollaborators', (event, token) => { + api.getCollaborators(token, win, repo.remote); }); \ No newline at end of file diff --git a/modules/api.js b/modules/api.js index 6512eaf..a239db4 100644 --- a/modules/api.js +++ b/modules/api.js @@ -49,11 +49,40 @@ function requestGitHubToken(code, mainWin) { }) .then((response) => { let token = response.data.split('&')[0].split('=')[1]; + mainWin.reload(); mainWin.webContents.send("token", token); }); } +function getCollaborators(token, mainWin, repo) { + axios.get('https://api.github.com/user', { + headers: { + 'Authorization': `token ${token}` + } + }) + .then(response => { + let user = response.data.login; + + axios.get(`https://api.github.com/repos/${user}/${repo}`, { + headers: { + 'Authorization': `token ${token}` + } + }) + .then(response => { + mainWin.webContents.send('gh_user', user); + mainWin.webContents.send('desc', response.data.description); + }) + .catch(error => { + console.log(error); + }); + }) + .catch(error => { + console.log('error!'); + }); +} + module.exports = { handleGitHub, - handleGitHubCallback + handleGitHubCallback, + getCollaborators }; \ No newline at end of file diff --git a/modules/git.js b/modules/git.js index ecba732..13214dd 100644 --- a/modules/git.js +++ b/modules/git.js @@ -12,10 +12,24 @@ function getRepoInfo(dir) { // get branch, split by nextline, take the first one(assumed to be active), split by space and take the name of the branch let branch = execSync("git branch").toString().split("\n")[0].split(' ')[1]; + // process the log + let logSplit = log.split('\n'); + let arrLog = []; + for(let i = 0; i < logSplit.length; i += 6) { + arrLog.push([ + logSplit[i], + logSplit[i+1], + logSplit[i+2], + logSplit[i+3], + logSplit[i+4], + logSplit[i+5] + ]); + } + return { 'remote': remote, 'status': status, - 'log': log, + 'log': arrLog, 'branch': branch }; } diff --git a/src/commit.html b/src/commit.html new file mode 100644 index 0000000..5153ae2 --- /dev/null +++ b/src/commit.html @@ -0,0 +1,40 @@ + +
+