eslint quality changes
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
import './../styles/scss/base.scss';
|
||||
import './../styles/css/base.css';
|
||||
import '../styles/scss/base.scss';
|
||||
import '../styles/css/base.css';
|
||||
|
||||
require('./event-toggles.js');
|
||||
|
||||
|
||||
|
||||
180
src/js/config.js
180
src/js/config.js
@@ -1,92 +1,92 @@
|
||||
module.exports = {
|
||||
gitToken: "96ead73c54cbbf023a73ee57af145b205d460851",
|
||||
intentSlugToOperations: {
|
||||
'createrepo' : {
|
||||
"requestMethod": 'post',
|
||||
"intentMessage": "Create a Repository in Github",
|
||||
"getDataOperation": "getCreateRepoJson",
|
||||
"githubOperation": "createRepository",
|
||||
"showWidgetOperation": "showCreateRepoWidget",
|
||||
"populateDataOperation": "populateCreateRepoData",
|
||||
"successMessage": "Repository Added!",
|
||||
"cardMsg": "Requested Repository has been added and is available at ",
|
||||
"cardDataUrl": "html_url",
|
||||
"cardDataName": "name"
|
||||
},
|
||||
'createissue' : {
|
||||
"requestMethod": 'post',
|
||||
"intentMessage": "Raise an issue in Github",
|
||||
"getDataOperation": "getCreateIssueJson",
|
||||
"githubOperation": "createIssue",
|
||||
"showWidgetOperation": "showCreateIssueWidget",
|
||||
"populateDataOperation": "populateCreateIssueData",
|
||||
"successMessage": "Issue Created!",
|
||||
"cardMsg": "Issue Created as requested, issue details available at ",
|
||||
"cardDataUrl": "html_url",
|
||||
"cardDataName": "title"
|
||||
},
|
||||
'closeissue' : {
|
||||
"requestMethod": 'post',
|
||||
"intentMessage": "Close an issue in Github",
|
||||
"getDataOperation": "getCloseIssueJson",
|
||||
"githubOperation": "closeIssue",
|
||||
"showWidgetOperation": "showCloseIssueWidget",
|
||||
"populateDataOperation": "populateCloseIssueData",
|
||||
"successMessage": "Issue Closed!",
|
||||
"cardMsg": "Issue Closed as requested, closed issue available at: ",
|
||||
"cardDataUrl": "html_url",
|
||||
"cardDataName": "title"
|
||||
},
|
||||
'addissuecomment' : {
|
||||
"requestMethod": 'post',
|
||||
"intentMessage": "Add a comment on an issue in Github",
|
||||
"getDataOperation": "getAddCommentJson",
|
||||
"githubOperation": "addIssueComment",
|
||||
"showWidgetOperation": "showAddCommentWidget",
|
||||
"populateDataOperation": "populateAddCommentData",
|
||||
"successMessage": "Comment Added!",
|
||||
"cardMsg": "Comment Added as Requested, view here: ",
|
||||
"cardDataUrl": "html_url",
|
||||
"cardDataName": "title"
|
||||
},
|
||||
'displaylastcomment' : {
|
||||
"requestMethod": 'get',
|
||||
"intentMessage": "Display last comment of an issue in Github",
|
||||
"getDataOperation": "getDisplayCommentJson",
|
||||
"githubOperation": "displayLastComment",
|
||||
"showWidgetOperation": "showDisplayCommentWidget",
|
||||
"populateDataOperation": "populateDisplayCommentData",
|
||||
"successMessage": "Comment Retrieved!",
|
||||
"cardMsg": "Please find requested comment below: ",
|
||||
"cardDataUrl": "html_url",
|
||||
"cardDataName": "title"
|
||||
},
|
||||
'addcollab' : {
|
||||
"requestMethod": 'post',
|
||||
"intentMessage": "Add a collaborator",
|
||||
"getDataOperation": "getAddCollaboratorJson",
|
||||
"githubOperation": "addCollaborator",
|
||||
"showWidgetOperation": "showAddCollaboratorWidget",
|
||||
"populateDataOperation": "populateAddCollaboratorData",
|
||||
"successMessage": "Collaborator Added!",
|
||||
"cardMsg": "Collaborator added, details available at ",
|
||||
"cardDataUrl": "html_url",
|
||||
"cardDataName": "invitee,login"
|
||||
},
|
||||
'viewrepos': {
|
||||
"requestMethod": 'get',
|
||||
"intentMessage": "View Repositories for current user",
|
||||
"getDataOperation": "getViewRepositoryJson",
|
||||
"githubOperation": "viewRepositories",
|
||||
"showWidgetOperation": "showViewRepoWidget",
|
||||
"populateDataOperation": "populateViewRepoData",
|
||||
"successMessage": "Showing repositories",
|
||||
"cardMsg": "Repository Details available below: ",
|
||||
"cardDataUrl": "html_url",
|
||||
"cardDataName": "invitee,login"
|
||||
}
|
||||
gitToken: '96ead73c54cbbf023a73ee57af145b205d460851',
|
||||
intentSlugToOperations: {
|
||||
createrepo: {
|
||||
requestMethod: 'post',
|
||||
intentMessage: 'Create a Repository in Github',
|
||||
getDataOperation: 'getCreateRepoJson',
|
||||
githubOperation: 'createRepository',
|
||||
showWidgetOperation: 'showCreateRepoWidget',
|
||||
populateDataOperation: 'populateCreateRepoData',
|
||||
successMessage: 'Repository Added!',
|
||||
cardMsg: 'Requested Repository has been added and is available at ',
|
||||
cardDataUrl: 'html_url',
|
||||
cardDataName: 'name',
|
||||
},
|
||||
costants: {
|
||||
"hiddenIntentFieldId": "intentHidden",
|
||||
}
|
||||
}
|
||||
createissue: {
|
||||
requestMethod: 'post',
|
||||
intentMessage: 'Raise an issue in Github',
|
||||
getDataOperation: 'getCreateIssueJson',
|
||||
githubOperation: 'createIssue',
|
||||
showWidgetOperation: 'showCreateIssueWidget',
|
||||
populateDataOperation: 'populateCreateIssueData',
|
||||
successMessage: 'Issue Created!',
|
||||
cardMsg: 'Issue Created as requested, issue details available at ',
|
||||
cardDataUrl: 'html_url',
|
||||
cardDataName: 'title',
|
||||
},
|
||||
closeissue: {
|
||||
requestMethod: 'post',
|
||||
intentMessage: 'Close an issue in Github',
|
||||
getDataOperation: 'getCloseIssueJson',
|
||||
githubOperation: 'closeIssue',
|
||||
showWidgetOperation: 'showCloseIssueWidget',
|
||||
populateDataOperation: 'populateCloseIssueData',
|
||||
successMessage: 'Issue Closed!',
|
||||
cardMsg: 'Issue Closed as requested, closed issue available at: ',
|
||||
cardDataUrl: 'html_url',
|
||||
cardDataName: 'title',
|
||||
},
|
||||
addissuecomment: {
|
||||
requestMethod: 'post',
|
||||
intentMessage: 'Add a comment on an issue in Github',
|
||||
getDataOperation: 'getAddCommentJson',
|
||||
githubOperation: 'addIssueComment',
|
||||
showWidgetOperation: 'showAddCommentWidget',
|
||||
populateDataOperation: 'populateAddCommentData',
|
||||
successMessage: 'Comment Added!',
|
||||
cardMsg: 'Comment Added as Requested, view here: ',
|
||||
cardDataUrl: 'html_url',
|
||||
cardDataName: 'title',
|
||||
},
|
||||
displaylastcomment: {
|
||||
requestMethod: 'get',
|
||||
intentMessage: 'Display last comment of an issue in Github',
|
||||
getDataOperation: 'getDisplayCommentJson',
|
||||
githubOperation: 'displayLastComment',
|
||||
showWidgetOperation: 'showDisplayCommentWidget',
|
||||
populateDataOperation: 'populateDisplayCommentData',
|
||||
successMessage: 'Comment Retrieved!',
|
||||
cardMsg: 'Please find requested comment below: ',
|
||||
cardDataUrl: 'html_url',
|
||||
cardDataName: 'title',
|
||||
},
|
||||
addcollab: {
|
||||
requestMethod: 'post',
|
||||
intentMessage: 'Add a collaborator',
|
||||
getDataOperation: 'getAddCollaboratorJson',
|
||||
githubOperation: 'addCollaborator',
|
||||
showWidgetOperation: 'showAddCollaboratorWidget',
|
||||
populateDataOperation: 'populateAddCollaboratorData',
|
||||
successMessage: 'Collaborator Added!',
|
||||
cardMsg: 'Collaborator added, details available at ',
|
||||
cardDataUrl: 'html_url',
|
||||
cardDataName: 'invitee,login',
|
||||
},
|
||||
viewrepos: {
|
||||
requestMethod: 'get',
|
||||
intentMessage: 'View Repositories for current user',
|
||||
getDataOperation: 'getViewRepositoryJson',
|
||||
githubOperation: 'viewRepositories',
|
||||
showWidgetOperation: 'showViewRepoWidget',
|
||||
populateDataOperation: 'populateViewRepoData',
|
||||
successMessage: 'Showing repositories',
|
||||
cardMsg: 'Repository Details available below: ',
|
||||
cardDataUrl: 'html_url',
|
||||
cardDataName: 'invitee,login',
|
||||
},
|
||||
},
|
||||
costants: {
|
||||
hiddenIntentFieldId: 'intentHidden',
|
||||
},
|
||||
};
|
||||
|
||||
1202
src/js/dom-ops.js
1202
src/js/dom-ops.js
File diff suppressed because it is too large
Load Diff
@@ -1,81 +1,84 @@
|
||||
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();
|
||||
const $config = require('./config.js');
|
||||
|
||||
|
||||
module.exports = $(document).ready(function () {
|
||||
// console.log('test');
|
||||
app.setToken();
|
||||
$('#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().addClass('hide');
|
||||
$('#successAlert').addClass('hide');
|
||||
$('#dangetAlert').addClass('hide');
|
||||
$('#intentBox').addClass('hide');
|
||||
var command = document.getElementById('command').value;
|
||||
if (command) {
|
||||
var text = { "text": command };
|
||||
recastclient.getAndCallProcessIntent(command, text);
|
||||
} else {
|
||||
dom.showEmptyCommandMessage();
|
||||
}
|
||||
}
|
||||
});
|
||||
$('#btnSubmitConfirm').on('click', function () {
|
||||
$('#submitConfirm').removeClass('hide');
|
||||
});
|
||||
$('#submitGitData').on('click', function () {
|
||||
var data = dom.getDataFromFormAsJSON();
|
||||
var intent = $('#' + $config.costants.hiddenIntentFieldId).val();
|
||||
if (intent) {
|
||||
var operation = $config.intentSlugToOperations[intent]['githubOperation'];
|
||||
app[operation](data);
|
||||
}
|
||||
});
|
||||
$("#hideInfoAlert").on('click', function () {
|
||||
$('#intentBox').addClass('hide');
|
||||
})
|
||||
$("#hideSuccessAlert").on('click', function () {
|
||||
$('#successAlert').addClass('hide');
|
||||
});
|
||||
$('#conversations').on('click', '.close', function () {
|
||||
var $target = $(this).closest('.card');
|
||||
var line = $target.next();
|
||||
$target.hide('slow', function () { $target.remove(); });
|
||||
line.hide('slow', function () { line.remove(); });
|
||||
});
|
||||
$("#hideDangerAlert").on('click', function () {
|
||||
$('#dangerAlert').addClass('hide');
|
||||
});
|
||||
$('#git_bridge').on('click', function() {
|
||||
window.location.href = 'https://github.com/login/oauth/authorize?scope=user:email:repo&client_id=f6f649a1fe2dfea082ba';
|
||||
// var user = app.getCurrentUser();
|
||||
// if(user) {
|
||||
// window.location.href = './../continue.html'
|
||||
// } else {
|
||||
// window.location.href = 'https://github.com/login/oauth/authorize?scope=user:email:repo&client_id=f6f649a1fe2dfea082ba';
|
||||
// }
|
||||
})
|
||||
if(window.location.href.match(/\?code=(.*)/) ) {
|
||||
var code = window.location.href.match(/\?code=(.*)/)[1];
|
||||
app.getToken(code);
|
||||
module.exports = $(document).ready(() => {
|
||||
// console.log('test');
|
||||
app.setToken();
|
||||
$('#sidebarCollapse').on('click', () => {
|
||||
$('#sidebar').toggleClass('active');
|
||||
$('.hideable').toggleClass('hide');
|
||||
});
|
||||
$('#content nav div.collapse li a.nav-link i.far.fa-star').hover(() => {
|
||||
$('#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(() => {
|
||||
$('#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(() => {
|
||||
$('#content nav div.collapse li a.nav-link i.far.fa-paper-plane').toggleClass('fas');
|
||||
});
|
||||
$('#command').keyup((e) => {
|
||||
const code = (e.keyCode ? e.keyCode : e.which);
|
||||
if (code == 13) {
|
||||
$('#widgets').children().addClass('hide');
|
||||
$('#successAlert').addClass('hide');
|
||||
$('#dangetAlert').addClass('hide');
|
||||
$('#intentBox').addClass('hide');
|
||||
const command = document.getElementById('command').value;
|
||||
if (command) {
|
||||
const text = { text: command };
|
||||
recastclient.getAndCallProcessIntent(command, text);
|
||||
} else {
|
||||
dom.showEmptyCommandMessage();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
$('#btnSubmitConfirm').on('click', () => {
|
||||
$('#submitConfirm').removeClass('hide');
|
||||
});
|
||||
$('#submitGitData').on('click', () => {
|
||||
const data = dom.getDataFromFormAsJSON();
|
||||
const intent = $(`#${$config.costants.hiddenIntentFieldId}`).val();
|
||||
if (intent) {
|
||||
const operation = $config.intentSlugToOperations[intent].githubOperation;
|
||||
app[operation](data);
|
||||
}
|
||||
});
|
||||
$('#hideInfoAlert').on('click', () => {
|
||||
$('#intentBox').addClass('hide');
|
||||
});
|
||||
$('#hideSuccessAlert').on('click', () => {
|
||||
$('#successAlert').addClass('hide');
|
||||
});
|
||||
$('#conversations').on('click', '.close', function () {
|
||||
const $target = $(this).closest('.card');
|
||||
const line = $target.next();
|
||||
$target.hide('slow', () => { $target.remove(); });
|
||||
line.hide('slow', () => { line.remove(); });
|
||||
});
|
||||
$('#hideDangerAlert').on('click', () => {
|
||||
$('#dangerAlert').addClass('hide');
|
||||
});
|
||||
$('#git_bridge').on('click', () => {
|
||||
window.location.href = 'https://github.com/login/oauth/authorize?scope=user:email:repo&client_id=f6f649a1fe2dfea082ba';
|
||||
// var user = app.getCurrentUser();
|
||||
// if(user) {
|
||||
// window.location.href = './../continue.html'
|
||||
// } else {
|
||||
// window.location.href = 'https://github.com/login/oauth/authorize?scope=user:email:repo&client_id=f6f649a1fe2dfea082ba';
|
||||
// }
|
||||
});
|
||||
if (window.location.href.match(/\?code=(.*)/)) {
|
||||
const code = window.location.href.match(/\?code=(.*)/)[1];
|
||||
app.getToken(code);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,336 +1,323 @@
|
||||
const config = require('./config.js');
|
||||
const GithubHelper = require('./helper.js');
|
||||
|
||||
const githubHelper = new GithubHelper();
|
||||
const DomManipulator = require('./dom-ops.js');
|
||||
|
||||
const dom = new DomManipulator();
|
||||
const PersistentOps = require('./persistent-ops.js');
|
||||
|
||||
const persistentOps = new PersistentOps();
|
||||
|
||||
|
||||
module.exports = class Github {
|
||||
constructor() {
|
||||
this.authorizationToken = `token ${config.gitToken}`;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
this.authorizationToken = "token " + config.gitToken;
|
||||
}
|
||||
getToken(code) {
|
||||
let token = '';
|
||||
self = this;
|
||||
$.getJSON(`http://localhost:9999/authenticate/${code}`, (data) => {
|
||||
console.log(data.token);
|
||||
token = data.token;
|
||||
// set cookie here
|
||||
persistentOps.setCookie('gitToken', token, 30);
|
||||
// self.authorizationToken = "token " + persistentOps.getCookie('gitToken');
|
||||
dom.concealCodeInUrl();
|
||||
});
|
||||
return token;
|
||||
}
|
||||
|
||||
getToken(code) {
|
||||
var token = '';
|
||||
self = this;
|
||||
$.getJSON('http://localhost:9999/authenticate/' + code, function(data) {
|
||||
console.log(data.token);
|
||||
token = data.token;
|
||||
// set cookie here
|
||||
persistentOps.setCookie('gitToken', token, 30);
|
||||
// self.authorizationToken = "token " + persistentOps.getCookie('gitToken');
|
||||
dom.concealCodeInUrl();
|
||||
getCurrentUser() {
|
||||
let repositories = '';
|
||||
const url = 'https://api.github.com/user/';
|
||||
fetch(url, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
response.json().then((body) => {
|
||||
repositories = body;
|
||||
console.log(repositories);
|
||||
return repositories;
|
||||
});
|
||||
return token;
|
||||
}
|
||||
dom.toggleModals(response);
|
||||
})
|
||||
.catch(error => console.error('Fetch Error =\n', error));
|
||||
return repositories;
|
||||
}
|
||||
|
||||
getCurrentUser() {
|
||||
var repositories = '';
|
||||
let url = 'https://api.github.com/user/';
|
||||
fetch(url, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json; charset=utf-8"
|
||||
}
|
||||
}
|
||||
)
|
||||
.then(function(response) {
|
||||
response.json().then(function(body){
|
||||
repositories = body;
|
||||
console.log(repositories);
|
||||
return repositories;
|
||||
});
|
||||
dom.toggleModals(response);
|
||||
})
|
||||
.catch(error => console.error('Fetch Error =\n', error));
|
||||
return repositories;
|
||||
}
|
||||
authenticate() {
|
||||
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;
|
||||
// });
|
||||
dom.toggleModals(response);
|
||||
})
|
||||
.catch(error => console.error('Fetch Error =\n', error));
|
||||
return repositories;
|
||||
}
|
||||
viewRepositories() {
|
||||
const repositories = '';
|
||||
const url = 'https://api.github.com/user/repos';
|
||||
fetch(url, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
Authorization: this.authorizationToken,
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
// response.json().then(function(body){
|
||||
// repositories = body;
|
||||
// console.log(repositories);
|
||||
// return repositories;
|
||||
// });
|
||||
dom.toggleModals(response);
|
||||
})
|
||||
.catch(error => console.error('Fetch Error =\n', error));
|
||||
return repositories;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
createRepository(newRepoJson) {
|
||||
const url = 'https://api.github.com/user/repos';
|
||||
const responsePromise = '';
|
||||
fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
Authorization: this.authorizationToken,
|
||||
},
|
||||
body: JSON.stringify(newRepoJson),
|
||||
})
|
||||
.then((response) => {
|
||||
dom.toggleModals(response);
|
||||
})
|
||||
.catch(error => console.error('Fetch Error =\n', error));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
updateRepository(updateRepoJson, repoName) {
|
||||
repoName = 'Hello-World3';
|
||||
const 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));
|
||||
}
|
||||
deleteRepository(repoName) {
|
||||
repoName = 'Hello-World2';
|
||||
const 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, repoName) {
|
||||
let url = 'https://api.github.com/repos/mohiit1502/' + repoName + '/issues';
|
||||
fetch(url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json; charset=utf-8",
|
||||
"Authorization": this.authorizationToken
|
||||
},
|
||||
body: JSON.stringify(newIssueJson)
|
||||
}
|
||||
)
|
||||
.then(function(response) {
|
||||
dom.toggleModals(response);
|
||||
})
|
||||
.catch(error => console.error('Fetch Error =\n', error));
|
||||
}
|
||||
createIssue(newIssueJson, repoName) {
|
||||
const url = `https://api.github.com/repos/mohiit1502/${repoName}/issues`;
|
||||
fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
Authorization: this.authorizationToken,
|
||||
},
|
||||
body: JSON.stringify(newIssueJson),
|
||||
})
|
||||
.then((response) => {
|
||||
dom.toggleModals(response);
|
||||
})
|
||||
.catch(error => console.error('Fetch Error =\n', error));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
updateIssue(updateIssueJson, repoName, issueNumber) {
|
||||
repoName = 'stack_route_prj7';
|
||||
issueNumber = 2;
|
||||
const 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));
|
||||
}
|
||||
|
||||
closeIssue(closeIssueJson, repoName, issueNumber) {
|
||||
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(function(response) {
|
||||
dom.toggleModals(response);
|
||||
})
|
||||
.catch(error => console.error('Fetch Error =\n', error));
|
||||
}
|
||||
closeIssue(closeIssueJson, repoName, issueNumber) {
|
||||
const 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) => {
|
||||
dom.toggleModals(response);
|
||||
})
|
||||
.catch(error => console.error('Fetch Error =\n', error));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
reopenIssue(reopenIssueJson, repoName, issueNumber) {
|
||||
repoName = 'stack_route_prj7';
|
||||
issueNumber = 2;
|
||||
const 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;
|
||||
}
|
||||
displayIssue(repoName, issueNumber) {
|
||||
repoName = 'stack_route_prj7';
|
||||
issueNumber = 2;
|
||||
const url = `https://api.github.com/repos/mohiit1502/${repoName}/issues/${issueNumber}`;
|
||||
let issues = '';
|
||||
fetch(url, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
Authorization: this.authorizationToken,
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
response.json().then((body) => {
|
||||
issues = body;
|
||||
console.log(issues);
|
||||
return issues;
|
||||
});
|
||||
})
|
||||
.catch(error => console.error('Fetch Error =\n', error));
|
||||
return issues;
|
||||
}
|
||||
|
||||
addIssueComment(commentBodyJson, repoName, issueId) {
|
||||
let url = 'https://api.github.com/repos/mohiit1502/' + repoName + '/issues/' + issueId + "/comments";
|
||||
fetch(url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json; charset=utf-8",
|
||||
"Authorization": this.authorizationToken
|
||||
},
|
||||
body: JSON.stringify(commentBodyJson)
|
||||
}
|
||||
)
|
||||
.then(function(response) {
|
||||
dom.toggleModals(response);
|
||||
})
|
||||
.catch(error => console.error('Fetch Error =\n', error));
|
||||
}
|
||||
addIssueComment(commentBodyJson, repoName, issueId) {
|
||||
const url = `https://api.github.com/repos/mohiit1502/${repoName}/issues/${issueId}/comments`;
|
||||
fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
Authorization: this.authorizationToken,
|
||||
},
|
||||
body: JSON.stringify(commentBodyJson),
|
||||
})
|
||||
.then((response) => {
|
||||
dom.toggleModals(response);
|
||||
})
|
||||
.catch(error => console.error('Fetch Error =\n', error));
|
||||
}
|
||||
|
||||
displayLastComment(repoName, issueNumber) {
|
||||
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) {
|
||||
dom.toggleModals(response);
|
||||
// response.json().then(function(body){
|
||||
// comments = body;
|
||||
// latestComment = githubHelper.getLatestComment(comments);
|
||||
// console.log(comments);
|
||||
// console.log(latestComment);
|
||||
// });
|
||||
})
|
||||
.catch(error => console.error('Fetch Error =\n', error));
|
||||
}
|
||||
displayLastComment(repoName, issueNumber) {
|
||||
const url = `https://api.github.com/repos/mohiit1502/${repoName}/issues/${issueNumber}/comments`;
|
||||
const comments = [];
|
||||
const latestComment = '';
|
||||
fetch(url, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
Authorization: this.authorizationToken,
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
dom.toggleModals(response);
|
||||
// response.json().then(function(body){
|
||||
// comments = body;
|
||||
// latestComment = githubHelper.getLatestComment(comments);
|
||||
// console.log(comments);
|
||||
// console.log(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));
|
||||
}
|
||||
displayIssuesForUser() {
|
||||
const 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));
|
||||
}
|
||||
displayIssuesOnRepo() {
|
||||
repoName = 'stack_route_prj7';
|
||||
issueNumber = 2;
|
||||
const 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(function(response) {
|
||||
dom.toggleModals(response);
|
||||
})
|
||||
.catch(error => console.error('Fetch Error =\n', error));
|
||||
}
|
||||
addCollaborator(repoName, collaborator) {
|
||||
repoName = 'stack_route_prj7';
|
||||
collaborator = 'swat1508';
|
||||
const url = `https://api.github.com/repos/mohiit1502/${repoName}/collaborators/${collaborator}`;
|
||||
fetch(url, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: this.authorizationToken,
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
dom.toggleModals(response);
|
||||
})
|
||||
.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));
|
||||
}
|
||||
removeCollaborator(repoName, collaborator) {
|
||||
repoName = 'stack_route_prj7';
|
||||
collaborator = 'swat1508';
|
||||
const 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) {
|
||||
createUser(newuserJson) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
updateUser(updateUserJson) {
|
||||
updateUser(updateUserJson) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
deleteUser(userId) {
|
||||
deleteUser(userId) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
module.exports = class GithubHelper {
|
||||
getLatestComment(comments) {
|
||||
if(comments && comments.length > 0)
|
||||
return comments[comments.length - 1]['body'];
|
||||
}
|
||||
}
|
||||
getLatestComment(comments) {
|
||||
if (comments && comments.length > 0) { return comments[comments.length - 1].body; }
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,126 +1,127 @@
|
||||
const Github = require('./github-ops.js');
|
||||
const $github = new Github()
|
||||
|
||||
const $github = new Github();
|
||||
const PersistentOps = require('./persistent-ops.js');
|
||||
|
||||
const persistentOps = new PersistentOps();
|
||||
|
||||
module.exports = class Microbot {
|
||||
constructor(clientId, clientSecret) {
|
||||
// TODO move to config or env variables
|
||||
this.clientId = 'f6f649a1fe2dfea082ba';
|
||||
this.clientSecret = '7e9a33d05ffdb36b4a498140bb9bb06d62de4f0e';
|
||||
}
|
||||
|
||||
constructor(clientId, clientSecret) {
|
||||
// TODO move to config or env variables
|
||||
this.clientId = 'f6f649a1fe2dfea082ba';
|
||||
this.clientSecret = '7e9a33d05ffdb36b4a498140bb9bb06d62de4f0e';
|
||||
}
|
||||
getToken(code) {
|
||||
$github.getToken(code);
|
||||
}
|
||||
|
||||
getToken(code) {
|
||||
$github.getToken(code);
|
||||
}
|
||||
setToken() {
|
||||
$github.authorizationToken = `token ${persistentOps.getCookie('gitToken')}`;
|
||||
}
|
||||
|
||||
setToken() {
|
||||
$github.authorizationToken = "token " + persistentOps.getCookie('gitToken');
|
||||
}
|
||||
getCurrentUser() {
|
||||
$github.getCurrentUser();
|
||||
}
|
||||
|
||||
getCurrentUser() {
|
||||
$github.getCurrentUser();
|
||||
}
|
||||
viewRepositories() {
|
||||
return $github.viewRepositories();
|
||||
}
|
||||
|
||||
viewRepositories() {
|
||||
return $github.viewRepositories();
|
||||
}
|
||||
createRepository(requestData) {
|
||||
const requestJson = requestData.request;
|
||||
$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
|
||||
// })
|
||||
}
|
||||
|
||||
createRepository(requestData) {
|
||||
var requestJson = requestData.request;
|
||||
$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,
|
||||
});
|
||||
}
|
||||
|
||||
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
|
||||
})
|
||||
}
|
||||
deleteRepository() {
|
||||
$github.deleteRepository();
|
||||
}
|
||||
|
||||
deleteRepository() {
|
||||
$github.deleteRepository();
|
||||
}
|
||||
createIssue(requestData) {
|
||||
const requestJson = requestData.request;
|
||||
const repoName = requestData.urlParams.repoName;
|
||||
$github.createIssue(requestJson, repoName);
|
||||
}
|
||||
|
||||
createIssue(requestData) {
|
||||
var requestJson = requestData.request;
|
||||
var repoName = requestData.urlParams.repoName;
|
||||
$github.createIssue(requestJson, repoName);
|
||||
}
|
||||
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',
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
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(requestData) {
|
||||
const repoName = requestData.urlParams.repoName;
|
||||
const issueId = requestData.urlParams.issueId;
|
||||
$github.closeIssue({
|
||||
state: 'close',
|
||||
}, repoName, issueId);
|
||||
}
|
||||
|
||||
closeIssue(requestData) {
|
||||
var repoName = requestData.urlParams.repoName;
|
||||
var issueId = requestData.urlParams.issueId;
|
||||
$github.closeIssue({
|
||||
"state": "close",
|
||||
}, repoName, issueId);
|
||||
}
|
||||
displayIssue() {
|
||||
return $github.displayIssue();
|
||||
}
|
||||
|
||||
displayIssue() {
|
||||
return $github.displayIssue();
|
||||
}
|
||||
reopenIssue() {
|
||||
$github.reopenIssue({
|
||||
milestone: 1,
|
||||
state: 'open',
|
||||
});
|
||||
}
|
||||
|
||||
reopenIssue() {
|
||||
$github.reopenIssue({
|
||||
"milestone": 1,
|
||||
"state": "open",
|
||||
})
|
||||
}
|
||||
addIssueComment(requestData) {
|
||||
const requestJson = requestData.request;
|
||||
const repoName = requestData.urlParams.repoName;
|
||||
const issueId = requestData.urlParams.issueId;
|
||||
$github.addIssueComment(requestJson, repoName, issueId);
|
||||
}
|
||||
|
||||
addIssueComment(requestData) {
|
||||
var requestJson = requestData.request;
|
||||
var repoName = requestData.urlParams.repoName;
|
||||
var issueId = requestData.urlParams.issueId;
|
||||
$github.addIssueComment(requestJson, repoName, issueId);
|
||||
}
|
||||
displayLastComment(requestData) {
|
||||
const repoName = requestData.urlParams.repoName;
|
||||
const issueId = requestData.urlParams.issueId;
|
||||
return $github.displayLastComment(repoName, issueId);
|
||||
}
|
||||
|
||||
displayLastComment(requestData) {
|
||||
var repoName = requestData.urlParams.repoName;
|
||||
var issueId = requestData.urlParams.issueId;
|
||||
return $github.displayLastComment(repoName, issueId);
|
||||
}
|
||||
addCollaborator(requestData) {
|
||||
const repoName = requestData.urlParams.repoName;
|
||||
const collaborator = requestData.urlParams.collaborator;
|
||||
$github.addCollaborator(repoName, collaborator);
|
||||
}
|
||||
|
||||
addCollaborator(requestData) {
|
||||
var repoName = requestData.urlParams.repoName;
|
||||
var collaborator = requestData.urlParams.collaborator;
|
||||
$github.addCollaborator(repoName, collaborator);
|
||||
}
|
||||
removeCollaborator() {
|
||||
$github.removeCollaborator();
|
||||
}
|
||||
|
||||
removeCollaborator() {
|
||||
$github.removeCollaborator();
|
||||
}
|
||||
callAppropriate(intent) {
|
||||
|
||||
callAppropriate(intent) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,29 +1,28 @@
|
||||
module.exports = class PersistentOps {
|
||||
getLatestComment(comments) {
|
||||
if(comments && comments.length > 0)
|
||||
return comments[comments.length - 1]['body'];
|
||||
}
|
||||
getLatestComment(comments) {
|
||||
if (comments && comments.length > 0) { return comments[comments.length - 1].body; }
|
||||
}
|
||||
|
||||
setCookie(cname, cvalue, exdays) {
|
||||
var d = new Date();
|
||||
d.setTime(d.getTime() + (exdays*24*60*60*1000));
|
||||
var expires = "expires="+ d.toUTCString();
|
||||
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
|
||||
}
|
||||
setCookie(cname, cvalue, exdays) {
|
||||
const d = new Date();
|
||||
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
|
||||
const expires = `expires=${d.toUTCString()}`;
|
||||
document.cookie = `${cname}=${cvalue};${expires};path=/`;
|
||||
}
|
||||
|
||||
getCookie(cname) {
|
||||
var name = cname + "=";
|
||||
var decodedCookie = decodeURIComponent(document.cookie);
|
||||
var ca = decodedCookie.split(';');
|
||||
for(var i = 0; i <ca.length; i++) {
|
||||
var c = ca[i];
|
||||
while (c.charAt(0) == ' ') {
|
||||
c = c.substring(1);
|
||||
}
|
||||
if (c.indexOf(name) == 0) {
|
||||
return c.substring(name.length, c.length);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
getCookie(cname) {
|
||||
const name = `${cname}=`;
|
||||
const decodedCookie = decodeURIComponent(document.cookie);
|
||||
const ca = decodedCookie.split(';');
|
||||
for (let i = 0; i < ca.length; i++) {
|
||||
let c = ca[i];
|
||||
while (c.charAt(0) == ' ') {
|
||||
c = c.substring(1);
|
||||
}
|
||||
if (c.indexOf(name) == 0) {
|
||||
return c.substring(name.length, c.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user