Major Check in - Git and Recast Integrated, create repository and issue functional via UI

This commit is contained in:
2018-07-19 14:23:15 +05:30
parent a5996f1f2d
commit 76aca797d6
18 changed files with 2007 additions and 283 deletions

View File

@@ -1,41 +1,19 @@
import './../styles/scss/base.scss';
import './../styles/css/base.css';
import { parseWebDriverCommand } from '../../node_modules/blocking-proxy/built/lib/webdriver_commands';
const Microbot = require("./microbot-ops.js");
const app = new Microbot();
document.write('<h1>' + app.createRepository() + '</h1>');
require('./event-toggles.js');
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
// var getUrlParameter = function getUrlParameter(sParam) {
// var sPageURL = decodeURIComponent(window.location.search.substring(1)),
// sURLVariables = sPageURL.split('&'),
// sParameterName,
// i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
// for (i = 0; i < sURLVariables.length; i++) {
// sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : sParameterName[1];
}
}
};
// window.onload = function() {
// var code = getUrlParameter('code');
// console.log(code)
// if(code !== undefined) {
// var result = $.ajax({
// type: "POST",
// url: 'https://github.com/login/oauth/access_token',
// data: {
// client_id: app.clientId,
// client_secret: app.clientSecret,
// code: code
// }
// });
// // alert(JSON.stringify(result));
// if (sParameterName[0] === sParam) {
// return sParameterName[1] === undefined ? true : sParameterName[1];
// }
// }
// //access_token = JSON.parse(result)['access_token']
// return code;
// };

57
src/js/bot/bot.js Normal file
View File

@@ -0,0 +1,57 @@
/*
* bot.js
*
* In this file:
* - received message from a connected channel will be transformed with Recast.AI SDK
* - received message from test command will be processed by Recast.AI
* You can run this command for testing:
* curl -X "POST" "http://localhost:5000" -d '{"text": "YOUR_TEXT"}' -H "Content-Type: application/json; charset=utf-8"
*
*
* The Recast.AI SDK will handle the message and call your reply bot function (ie. replyMessage function)
*/
const recastai = require('recastai').default
const config = require('./config.js');
// Instantiate Recast.AI SDK
const client = new recastai(config.recasttoken);
/*
* Callback for BotConnector messages
* Parameters:
* - message: Message received from BotConnector
*/
const replyMessage = message => {
// Get text from message received
const text = message.content
console.log('I receive: ', text)
return client.request.analyseText(text)
.then(nlp => {
let reply = 'I\'m sorry but I don\'t understand what you are talking about.'
const intent = nlp.intent()
if (intent) {
reply = `I understand that you talk about ${intent.slug}.`
}
message.addReply({ type: 'text', content: reply })
return message.reply().then(p => p.body)
})
}
/*
* Main bot function
* Parameters are:
* - body: Request body
* - response: Response of your server (can be a blank object if not needed: {})
*/
const reply = (request, response) => {
return client.connect.handleMessage(request, response, replyMessage)
}
module.exports = {
reply,
}

3
src/js/bot/config.js Normal file
View File

@@ -0,0 +1,3 @@
module.exports = {
recasttoken: "26021d055040a9d9f1ad48476efab4a0"
}

88
src/js/bot/recast-ops.js Normal file
View File

@@ -0,0 +1,88 @@
const config = require('./config.js');
const Microbot = require("./../microbot-ops.js");
const app = new Microbot();
const DomManipulator = require('./../dom-ops.js');
const domManipulator = new DomManipulator();
module.exports = class Recast {
constructor() {
this.recastToken = config.recasttoken;
this.requestUrl = "https://api.recast.ai/v2/request";
}
getAndCallProcessIntent(command, text) {
self = this;
var url = this.requestUrl + "?text=" + command;
var bodyRelevant = '';
var intent = '';
fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json; charset=utf-8",
"Authorization": "Token " + this.recastToken
},
data: text
})
.then(function(response) {
response.json().then(function(body) {
bodyRelevant = body.results;
intent = bodyRelevant.intents[0]["slug"];
if(intent !== undefined) {
domManipulator.showWidget(intent);
domManipulator.populateRecastData(intent, bodyRelevant);
// self.processIntent(intent);
}
return intent;
});
})
.catch(function(error) {
console.error('Fetch Error =\n', error);
});
};
processIntent(intent) {
switch(intent) {
case "createrepo":
app.createRepository();
break;
case "updaterepo":
app.updateRepository();
break;
case "viewrepos":
app.viewRepositories();
break;
case "deleterepo":
app.deleteRepository();
break;
case "createissue":
app.createIssue();
break;
case "updateissue":
app.updateIssue();
break;
case "closeissue":
app.closeIssue();
break;
case "reopenissue":
app.reopenIssue();
break;
case "displayissue":
app.displayIssue();
break;
case "addissuecomment":
app.addIssueComment();
break;
case "displaylastcomment":
app.displayLastComment();
break;
case "addcollab":
app.addCollaborator();
break;
case "removecollab":
app.removeCollaborator();
break;
default:
console.log("default");
}
}
}

47
src/js/bot/server.js Normal file
View File

@@ -0,0 +1,47 @@
/*
* server.js
* This file is the core of your bot
*
* It creates a little server using express
* So, your bot can be triggered throught "/" route
*
* This file was made for locally testing your bot
* You can test it by running this command
* curl -X "POST" "http://localhost:5000" -d '{"text": "YOUR_TEXT"}' -H "Content-Type: application/json; charset=utf-8"
* You might modify the server port ^^^^ depending on your configuration in config.js file
*/
const express = require('express')
const bodyParser = require('body-parser')
// Load configuration
require('./config')
const bot = require('./bot')
// Start Express server
const app = express()
app.set('port', process.env.PORT || 5000)
app.use(bodyParser.json())
// Handle / route
app.use('/', (request, response) => {
bot.reply(request, response)
.then(success => {
console.log(success)
if (!response.headersSent) { response.status(200) }
}).catch(error => {
console.log('Error in your bot:', error)
if (!response.headersSent) { response.sendStatus(400) }
})
})
if (!process.env.REQUEST_TOKEN) {
console.log('ERROR: process.env.REQUEST_TOKEN variable in src/config.js file is empty ! You must fill this field with the request_token of your bot before launching your bot locally')
process.exit(0)
} else {
// Run Express server, on right port
app.listen(app.get('port'), () => {
console.log('Our bot is running on port', app.get('port'))
})
}

3
src/js/config.js Normal file
View File

@@ -0,0 +1,3 @@
module.exports = {
gitToken: "b5f624887b686467decb0b707521baa171308df4"
}

334
src/js/dom-ops.js Normal file
View File

@@ -0,0 +1,334 @@
module.exports = class DomManipulator {
constructor() {
this.createRepoWidgetCreated = false;
}
showWidget(widgetName) {
self = this;
switch(widgetName) {
case "createrepo":
self.showCreateRepoWidget();
break;
case "updaterepo":
app.updateRepository();
break;
case "viewrepos":
app.viewRepositories();
break;
case "deleterepo":
app.deleteRepository();
break;
case "createissue":
self.showCreateIssueWidget();
break;
case "updateissue":
app.updateIssue();
break;
case "closeissue":
app.closeIssue();
break;
case "reopenissue":
app.reopenIssue();
break;
case "displayissue":
app.displayIssue();
break;
case "addissuecomment":
app.addIssueComment();
break;
case "displaylastcomment":
app.displayLastComment();
break;
case "addcollab":
app.addCollaborator();
break;
case "removecollab":
app.removeCollaborator();
break;
default:
console.log("default");
}
}
showCreateRepoWidget() {
var createRepoWidget = self.createRepoWidget();
if(!this.isVisible(createRepoWidget)) {
createRepoWidget.classList.remove('hide');
}
}
showCreateIssueWidget() {
var createIssueWidget = document.getElementById('createissue');
if(!this.isVisible(createIssueWidget)) {
createIssueWidget.classList.remove('hide');
}
}
createRepoWidget() {
var existingWidget = document.getElementById('createrepo')
if(existingWidget) {
return existingWidget;
}
// Create Elements
var widgets = document.getElementById("widgets");
var createRepoWidget = document.createElement('div');
var cardBody = document.createElement('div');
var header = document.createElement('div');
var form = document.createElement('form');
var formRow1 = document.createElement('div');
var formGroup1_1 = document.createElement('div');
var repoNamelabel = document.createElement('label');
var repoNameTextField = document.createElement('input');
var formGroup1_2 = document.createElement('div');
var homePageURLLabel = document.createElement('label');
var homePageURLTextField = document.createElement('input');
var formRow2 = document.createElement('div');
var formGroup2_1 = document.createElement('div');
var formCheck1 = document.createElement('div');
var privateLabel = document.createElement('label');
var privateCB = document.createElement('input');
var formGroup2_2 = document.createElement('div');
var formCheck2 = document.createElement('div');
var addIssueLabel = document.createElement('label');
var addIssueCB = document.createElement('input');
var formGroup2_3 = document.createElement('div');
var formCheck3 = document.createElement('div');
var addWikiLabel = document.createElement('label');
var addWikiCB = document.createElement('input');
var formGroup3_1 = document.createElement('div');
var descriptionLabel = document.createElement('label');
var descriptionTextArea = document.createElement('textarea');
var submitRepoCreate = document.createElement('button')
var line = document.createElement('div');
// Add Attributes
widgets.classList.add('card-group');
createRepoWidget.setAttribute('id', 'createrepo');
createRepoWidget.classList.add('card', 'hide', 'widget', 'good');
cardBody.classList.add('card-body');
header.classList.add('card-title');
formRow1.classList.add('form-row');
formGroup1_1.classList.add('form-group', 'col-md-6', 'col-sm-6', 'col-lg-6', 'col-xs-6', 'mb-3');
repoNamelabel.setAttribute('for', 'repositoryName');
repoNameTextField.setAttribute('type', 'text');
repoNameTextField.setAttribute('id', 'repositoryName');
repoNameTextField.setAttribute('placeholder', 'Repository Name... ');
repoNameTextField.required = true;
repoNameTextField.classList.add('form-control');
formGroup1_2.classList.add('form-group', 'col-md-6', 'col-sm-6', 'col-lg-6', 'col-xs-6', 'mb-3');
homePageURLLabel.setAttribute('for', 'homePageURL');
homePageURLTextField.setAttribute('type', 'text');
homePageURLTextField.setAttribute('id', 'homePageURL');
homePageURLTextField.setAttribute('placeholder', 'Home Page URL... ');
homePageURLTextField.classList.add('form-control');
formRow2.classList.add('form-row');
formGroup2_1.classList.add('form-group', 'col-md-3', 'col-sm-3', 'col-lg-3', 'col-xs-3', 'mb-3');
formCheck1.classList.add('form-check', 'form-check-inline')
privateLabel.setAttribute('for', 'privateRepoChk');
privateLabel.classList.add('form-check-label');
privateCB.setAttribute('type', 'checkbox');
privateCB.setAttribute('id', 'privateRepoChk');
privateCB.setAttribute('value', 'Option 1');
privateCB.classList.add('form-check-input');
formGroup2_2.classList.add('form-group', 'col-md-4', 'col-sm-4', 'col-lg-4', 'col-xs-4', 'mb-3');
formCheck2.classList.add('form-check', 'form-check-inline')
addIssueLabel.setAttribute('for', 'issuesChk');
addIssueLabel.classList.add('form-check-label');
addIssueCB.setAttribute('type', 'checkbox');
addIssueCB.setAttribute('id', 'issuesChk');
addIssueCB.setAttribute('value', 'Option 2');
addIssueCB.classList.add('form-check-input');
formGroup2_3.classList.add('form-group', 'col-md-4', 'col-sm-4', 'col-lg-4', 'col-xs-4', 'mb-3');
formCheck3.classList.add('form-check', 'form-check-inline')
addWikiLabel.setAttribute('for', 'wikiChk');
addWikiLabel.classList.add('form-check-label');
addWikiCB.setAttribute('type', 'checkbox');
addWikiCB.setAttribute('id', 'wikiChk');
addWikiCB.setAttribute('value', 'Option 3');
addWikiCB.classList.add('form-check-input');
formGroup3_1.classList.add('form-group');
descriptionLabel.setAttribute('for', 'description');
descriptionTextArea.setAttribute('rows', '3');
descriptionTextArea.classList.add('form-control');
descriptionTextArea.setAttribute('id', 'description');
submitRepoCreate.setAttribute('type', 'button');
submitRepoCreate.setAttribute('data-toggle', 'modal');
submitRepoCreate.setAttribute('data-target', '#submitConfirm');
submitRepoCreate.setAttribute('id', 'submitForm');
submitRepoCreate.classList.add('btn', 'btn-primary');
line.classList.add('line');
line.setAttribute('id', 'underWidgetLine');
// Add inner HTML
header.innerHTML = "Create Repository";
repoNamelabel.innerHTML = "Repository Name";
homePageURLLabel.innerHTML = "Home Page URL";
privateLabel.innerHTML = "Private";
addIssueLabel.innerHTML = "Allow Adding Issues?";
addWikiLabel.innerHTML = "Add Wiki?";
descriptionLabel.innerHTML = "Add some Description for this repository:";
submitRepoCreate.innerHTML = "Submit";
// Associations
formCheck1.appendChild(privateCB);
formCheck1.appendChild(privateLabel);
formCheck2.appendChild(addIssueCB);
formCheck2.appendChild(addIssueLabel);
formCheck3.appendChild(addWikiCB);
formCheck3.appendChild(addWikiLabel);
formGroup1_1.appendChild(repoNamelabel);
formGroup1_1.appendChild(repoNameTextField);
formGroup1_2.appendChild(homePageURLLabel);
formGroup1_2.appendChild(homePageURLTextField);
formGroup2_1.appendChild(formCheck1);
formGroup2_2.appendChild(formCheck2);
formGroup2_3.appendChild(formCheck3);
formGroup3_1.appendChild(descriptionLabel);
formGroup3_1.appendChild(descriptionTextArea);
formRow1.appendChild(formGroup1_1);
formRow1.appendChild(formGroup1_2);
formRow2.appendChild(formGroup2_1);
formRow2.appendChild(formGroup2_2);
formRow2.appendChild(formGroup2_3);
form.appendChild(formRow1);
form.appendChild(formRow2);
form.appendChild(formGroup3_1);
form.appendChild(submitRepoCreate);
cardBody.appendChild(header);
cardBody.appendChild(form);
widgets.appendChild(createRepoWidget);
createRepoWidget.appendChild(cardBody);
widgets.appendChild(line);
this.createRepoWidgetCreated = true;
return createRepoWidget;
}
showEmptyCommandMessage() {
$('#emptyCommandMsgDisplayer').click();
}
populateWidgetWithRecastResponse() {
}
populateWidgetWithGithubResponse() {
}
populateRecastData(widgetName, recastResponse) {
switch(widgetName) {
case "createrepo":
self.populateCreateRepoData(recastResponse);
break;
case "updaterepo":
app.updateRepository();
break;
case "viewrepos":
app.viewRepositories();
break;
case "deleterepo":
app.deleteRepository();
break;
case "createissue":
app.createIssue();
break;
case "updateissue":
app.updateIssue();
break;
case "closeissue":
app.closeIssue();
break;
case "reopenissue":
app.reopenIssue();
break;
case "displayissue":
app.displayIssue();
break;
case "addissuecomment":
app.addIssueComment();
break;
case "displaylastcomment":
app.displayLastComment();
break;
case "addcollab":
app.addCollaborator();
break;
case "removecollab":
app.removeCollaborator();
break;
default:
console.log("default");
}
}
populateCreateRepoData(recastResponse) {
var repoNameTextField = document.getElementById('repositoryName');
if(repoNameTextField && recastResponse && recastResponse.entities['git-repository'] && recastResponse.entities['git-repository'].length > 0
&& recastResponse.entities['git-repository']['0']['value']) {
var repoName = recastResponse.entities['git-repository']['0']['value'];
repoNameTextField.value = repoName;
}
}
isVisible(element) {
return element ? !element.classList.contains('hide') : false;
}
getDataFromFormAsJSON() {
var request = {};
if(this.isVisible(document.getElementById("createrepo"))) {
request.name = document.getElementById("repositoryName").value;
request.description = document.getElementById("description").value;
request.homepage = document.getElementById("homePageURL").value;
request.private = document.getElementById("privateRepoChk").checked;
request.has_issues = document.getElementById("issuesChk").checked;
request.has_wiki = document.getElementById("wikiChk").checked;
}
return request;
}
addGitOperationHistory(response) {
}
toggleModals(response) {
var promise = response.json();
$('#submitConfirm').hide();
$('.modal-backdrop').removeClass('modal-backdrop');
$('#underWidgetLine').hide();
if(response && response.status && response.status === 201) {
$('#successAlert').show();
$('#createrepo').hide();
}
promise.then(function(body) {
addGitOperationHistory(body);
})
}
}

44
src/js/event-toggles.js Normal file
View File

@@ -0,0 +1,44 @@
const Recast = require('./bot/recast-ops.js');
const recastclient = new Recast();
const DomManipulator = require('./dom-ops.js');
const dom = new DomManipulator();
const Microbot = require('./microbot-ops.js');
const app = new Microbot();
module.exports = $(document).ready(function () {
$('#sidebarCollapse').on('click', function () {
$('#sidebar').toggleClass('active');
$('.hideable').toggleClass('hide');
});
$('#content nav div.collapse li a.nav-link i.far.fa-star').hover(function () {
$('#content nav div.collapse li a.nav-link i.far.fa-star').toggleClass('fas');
});
$('#content nav div.collapse li a.nav-link i.far.fa-trash-alt').hover(function () {
$('#content nav div.collapse li a.nav-link i.far.fa-trash-alt').toggleClass('fas');
});
$('#content nav div.collapse li a.nav-link i.far.fa-paper-plane').hover(function () {
$('#content nav div.collapse li a.nav-link i.far.fa-paper-plane').toggleClass('fas');
});
$('#command').keyup(function(e){
var code = (e.keyCode ? e.keyCode : e.which);
if(code == 13) {
$('widgets').children().hide();
var command = document.getElementById('command').value;
if(command) {
var text = { "text": command};
recastclient.getAndCallProcessIntent(command, text);
} else {
dom.showEmptyCommandMessage();
}
}
});
$('#submitGitData').on('click', function() {
var requestJSON = dom.getDataFromFormAsJSON();
app.createRepository(requestJSON);
})
$('#submitForm').click(function(e) {
e.preventDefault();
});
});

View File

@@ -1,42 +1,288 @@
const config = require('./config.js');
const GithubHelper = require('./helper.js');
const githubHelper = new GithubHelper();
const DomManipulator = require('./dom-ops.js');
const dom = new DomManipulator();
module.exports = class Github {
constructor() {
this.authorizationToken = "token " + config.gitToken;
}
getToken() {
}
createRepository(newRepoJson) {
$.ajax({
type: "POST",
headers: {'Authorization' : 'token bcce9020b0604acc8a535d6d0e026b04b4996432'},
url: "https://api.github.com/user/repos",
contentType: "application/json",
dataType: "jsonp",
data: newRepoJson
authenticate() {
}
viewRepositories() {
var repositories = '';
let url = 'https://api.github.com/user/repos';
fetch(url, {
method: "GET",
headers: {
"Content-Type": "application/json; charset=utf-8",
"Authorization": this.authorizationToken
}
}
)
.then(function(response) {
response.json().then(function(body){
repositories = body;
console.log(repositories);
return repositories;
});
})
.catch(error => console.error('Fetch Error =\n', error));
return repositories;
}
updateRepository(updateRepoJson) {
createRepository(newRepoJson) {
let url = 'https://api.github.com/user/repos';
var responsePromise = '';
fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json; charset=utf-8",
"Authorization": this.authorizationToken
},
body: JSON.stringify(newRepoJson)
}
)
.then(function(response) {
dom.toggleModals(response);
})
.catch(error => console.error('Fetch Error =\n', error));
}
deleteRepositoy(repoId) {
updateRepository(updateRepoJson, repoName) {
repoName = "Hello-World3";
let url = 'https://api.github.com/repos/mohiit1502/' + repoName;
fetch(url, {
method: "PATCH",
headers: {
"Content-Type": "application/json; charset=utf-8",
"Authorization": this.authorizationToken
},
body: JSON.stringify(updateRepoJson)
}
)
.then(response => response.json())
.catch(error => console.error('Fetch Error =\n', error));
}
deleteRepository(repoName) {
repoName = "Hello-World2";
let url = 'https://api.github.com/repos/mohiit1502/' + repoName;
fetch(url, {
method: "DELETE",
headers: {
"Content-Type": "application/json; charset=utf-8",
"Authorization": this.authorizationToken
}
}
)
.then(response => response.json())
.catch(error => console.error('Fetch Error =\n', error));
}
createIssue(newIssueJson) {
let url = 'https://api.github.com/repos/mohiit1502/stack_route_prj7/issues';
fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json; charset=utf-8",
"Authorization": this.authorizationToken
},
body: JSON.stringify(newIssueJson)
}
)
.then(response => response.json())
.catch(error => console.error('Fetch Error =\n', error));
}
updateIssue(updateIssueJson) {
updateIssue(updateIssueJson, repoName, issueNumber) {
repoName = 'stack_route_prj7';
issueNumber = 2;
let url = 'https://api.github.com/repos/mohiit1502/' + repoName + '/issues/' + issueNumber;
fetch(url, {
method: "PATCH",
headers: {
"Content-Type": "application/json; charset=utf-8",
"Authorization": this.authorizationToken
},
body: JSON.stringify(updateIssueJson)
}
)
.then(response => response.json())
.catch(error => console.error('Fetch Error =\n', error));
}
deleteIssue(issueId) {
closeIssue(closeIssueJson, repoName, issueNumber) {
repoName = 'stack_route_prj7';
issueNumber = 2;
let url = 'https://api.github.com/repos/mohiit1502/' + repoName + '/issues/' + issueNumber;
fetch(url, {
method: "PATCH",
headers: {
"Content-Type": "application/json; charset=utf-8",
"Authorization": this.authorizationToken
},
body: JSON.stringify(closeIssueJson)
}
)
.then(response => response.json())
.catch(error => console.error('Fetch Error =\n', error));
}
closeIssue(issueId) {
reopenIssue(reopenIssueJson, repoName, issueNumber) {
repoName = 'stack_route_prj7';
issueNumber = 2;
let url = 'https://api.github.com/repos/mohiit1502/' + repoName + '/issues/' + issueNumber;
fetch(url, {
method: "PATCH",
headers: {
"Content-Type": "application/json; charset=utf-8",
"Authorization": this.authorizationToken
},
body: JSON.stringify(reopenIssueJson)
}
)
.then(response => response.json())
.catch(error => console.error('Fetch Error =\n', error));
}
displayIssue(repoName, issueNumber) {
repoName = 'stack_route_prj7';
issueNumber = 2;
let url = 'https://api.github.com/repos/mohiit1502/' + repoName + '/issues/' + issueNumber;
var issues = '';
fetch(url, {
method: "GET",
headers: {
"Content-Type": "application/json; charset=utf-8",
"Authorization": this.authorizationToken
}
}
)
.then(function(response) {
response.json().then(function(body){
issues = body;
console.log(issues);
return issues;
});
})
.catch(error => console.error('Fetch Error =\n', error));
return issues;
}
addIssueComment(commentBodyJson, repoName, issueNumber) {
repoName = "stack_route_prj7";
issueNumber = 2;
let url = 'https://api.github.com/repos/mohiit1502/' + repoName + '/issues/' + issueNumber + "/comments";
fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json; charset=utf-8",
"Authorization": this.authorizationToken
},
body: JSON.stringify(commentBodyJson)
}
)
.then(response => response.json())
.catch(error => console.error('Fetch Error =\n', error));
}
displayLastComment(repoName, issueNumber) {
repoName = "stack_route_prj7";
issueNumber = 2;
let url = 'https://api.github.com/repos/mohiit1502/' + repoName + '/issues/' + issueNumber + "/comments";
var comments = [];
var latestComment = "";
fetch(url, {
method: "GET",
headers: {
"Content-Type": "application/json; charset=utf-8",
"Authorization": this.authorizationToken
}
}
)
.then(function(response) {
response.json().then(function(body){
comments = body;
latestComment = githubHelper.getLatestComment(comments);
console.log(comments);
console.log(latestComment);
return latestComment;
});
})
.catch(error => console.error('Fetch Error =\n', error));
}
displayIssuesForUser() {
let url = 'https://api.github.com/user/issues';
fetch(url, {
method: "GET",
headers: {
"Content-Type": "application/json; charset=utf-8",
"Authorization": this.authorizationToken
}
}
)
.then(response => response.json())
.catch(error => console.error('Fetch Error =\n', error));
}
displayIssuesOnRepo() {
repoName = 'stack_route_prj7';
issueNumber = 2;
let url = 'https://api.github.com/repos/mohiit1502/' + repoName + '/issues/';
fetch(url, {
method: "PATCH",
headers: {
"Content-Type": "application/json; charset=utf-8",
"Authorization": this.authorizationToken
},
body: JSON.stringify(updateIssueJson)
}
)
.then(response => response.json())
.catch(error => console.error('Fetch Error =\n', error));
}
addCollaborator(repoName, collaborator) {
repoName = 'stack_route_prj7';
collaborator = 'swat1508';
let url = 'https://api.github.com/repos/mohiit1502/' + repoName + '/collaborators/' + collaborator;
fetch(url, {
method: "PUT",
headers: {
"Content-Type": "application/json",
"Authorization": this.authorizationToken
}
}
)
.then(response => response.json())
.catch(error => console.error('Fetch Error =\n', error));
}
removeCollaborator(repoName, collaborator) {
repoName = 'stack_route_prj7';
collaborator = 'swat1508';
let url = 'https://api.github.com/repos/mohiit1502/' + repoName + '/collaborators/' + collaborator;
fetch(url, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
"Authorization": this.authorizationToken
}
}
)
.then(response => response.json())
.catch(error => console.error('Fetch Error =\n', error));
}
createUser(newuserJson) {
@@ -48,14 +294,6 @@ module.exports = class Github {
}
deleteUser(userId) {
}
addCollaborator(userId, collaboratorId) {
}
removeCollaborator(userId, collaboratorId) {
}
}

6
src/js/helper.js Normal file
View File

@@ -0,0 +1,6 @@
module.exports = class GithubHelper {
getLatestComment(comments) {
if(comments && comments.length > 0)
return comments[comments.length - 1]['body'];
}
}

View File

@@ -2,26 +2,116 @@ const Github = require('./github-ops.js');
const $github = new Github()
module.exports = class Microbot {
constructor(clientId, clientSecret) {
// TODO move to config or env variables
this.clientId = 'f6f649a1fe2dfea082ba';
this.clientSecret = '7e9a33d05ffdb36b4a498140bb9bb06d62de4f0e';
}
createRepository(repoName, repoType) {
$github.createRepository({
"name": "first-js-git-api-repo",
"description": "This is your first repository",
viewRepositories() {
return $github.viewRepositories();
}
createRepository(requestJson) {
var promise = $github.createRepository(requestJson);
// $github.createRepository({
// "name": "new-test-js-git-api-repo",
// "description": "This is your first repository",
// "homepage": "https://github.com",
// "private": false,
// "has_issues": true,
// "has_wiki": true
// })
}
updateRepository(repoName, repoType) {
$github.authenticate();
$github.updateRepository({
"name": "Hello-World4",
"description": "This is your test description",
"homepage": "https://github.com",
"private": false,
"has_issues": true,
"has_projects": true,
"has_wiki": true
})
}
// testingWebpackcalls() {
deleteRepository() {
$github.deleteRepository();
}
// console.log('call successful');
// }
createIssue() {
$github.createIssue({
"title": "Found a bug",
"body": "I'm having a problem with this.",
"assignees": [
"mohiit1502"
],
"labels": [
"bug"
]
})
}
updateIssue() {
$github.updateIssue({
"title": "Found a bug - title updated",
"body": "This is the updated problem description.",
"assignees": [
"mohiit1502"
],
"milestone": 1,
"state": "open",
"labels": [
"bug", "issue"
]
});
}
closeIssue() {
$github.closeIssue({
"milestone": 1,
"state": "close",
});
}
displayIssue() {
return $github.displayIssue();
}
reopenIssue() {
$github.reopenIssue({
"milestone": 1,
"state": "open",
})
}
addIssueComment() {
$github.addIssueComment({
"body": "This is another test issue comment"
});
}
displayLastComment() {
return $github.displayLastComment();
}
addCollaborator() {
$github.addCollaborator({
"title": "Found a bug",
"body": "I'm having a problem with this.",
"assignees": [
"mohiit1502"
],
"labels": [
"bug"
]
});
}
removeCollaborator() {
$github.removeCollaborator();
}
}

View File

@@ -131,7 +131,7 @@ span {
#sidebar ul.components {
padding: 20px 0;
border-bottom: 1px solid #47748b;
border-bottom: 3px solid $themeColor-Dark;
}
#sidebar ul li a {
@@ -286,6 +286,25 @@ ADDITIONS
margin: auto;
}
.good {
animation: anim .3s ease-in-out;
}
@keyframes anim {
0% {
display: none;
opacity: 0;
}
1% {
display: block;
opacity: 0;
transform: scale(0);
}
100% {
opacity: 1;
transform: scale(1);
}
}
@keyframes blinkingText {
0%{ color: #000; }
49%{ color: transparent; }
@@ -308,6 +327,7 @@ ADDITIONS
font-size: 1.8em;
padding: 0.2em;
}
/* --------------------------------------------------
OVERRIDES
--------------------------------------------------*/
@@ -330,4 +350,30 @@ ADDITIONS
.container-fluid {
padding-left: 0.3em;
}
}
.card-group {
flex-direction:column;
}
#command.form-control {
width: 87%;
}
.ml-auto {
margin-left: 0!important;
}
@media(min-width: 576px) {
.card-group>.card:first-child {
border-top-right-radius: .25rem;
border-bottom-right-radius: .25rem;
}
.card-group>.card:not(:first-child):not(:last-child):not(:only-child) {
border-radius: .25rem;
}
.card-group>.card:last-child {
border-top-left-radius: .25rem;
border-bottom-left-radius: .25rem;
}
}