-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataHandler.js
More file actions
122 lines (109 loc) · 3.26 KB
/
dataHandler.js
File metadata and controls
122 lines (109 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
const { Octokit } = require("@octokit/rest");
require('dotenv').config()
var JiraApi = require('jira-client');
const errorJiraTemplate = { icon: 'bi bi-x-circle' };
const jiraTemplate = { icon: 'bi bi-check-circle-fill' };
let jiraNums = [];
class DataHandler {
constructor(links, title ) {
this.links = links || [];
this.title = title || [];
this.jirasObj = [];
this.createJiraObject();
this.fetchGitHubData();
}
createJiraObject() {
for (let i = 0; i < this.title.length; i++) {
let icon = getIcon()
this.jirasObj.push({
link: this.links[i],
title: this.title[i],
...icon
});
}
return this.jirasObj;
}
async fetchGitHubData() {
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN
});
try {
const response = await octokit.rest.repos.listCommits({
owner: "thinlizee",
repo: "engineering-training",
});
// console.log('response', JSON.stringify(response));
for (let i = 0; i < response.data.length; i++) {
const regex = /[A-Z][A-Z]+-\d+/g;
const ticketNum = response.data[i].commit.message.match(regex);
if (ticketNum !== null && jiraNums.indexOf(ticketNum[0]) == -1) {
jiraNums.push(ticketNum[0]);
}
}
console.log(jiraNums);
for(let ts = 0; ts < 21; ts++) {
const message = response.data[ts].commit.message;
console.log('summary: ' + message + '\n');
}
}
catch (error) {
console.log("Error getting data:", error.message);
}
}
};
function getRandomIntInclusive(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1) + min); // The maximum is inclusive and the minimum is inclusive
};
let jiraLinks = ['https://totalwine.atlassian.net/browse/TT-2',
'https://totalwine.atlassian.net/browse/TT-16',
'https://totalwine.atlassian.net/browse/TT-17',
'https://totalwine.atlassian.net/browse/TT-18',
'https://totalwine.atlassian.net/browse/TT-19'
];
// console.log('Jira Links', jiraLinks);
let jiraTitles = ['Create a public repository under your GitHub account',
'Create a new script file, and import it into index.html and add a console log',
'JavaScript: Variables',
'JavaScript: Event Listeners - Add Toggle Button Inside of Modal',
'JavaScript: Functions - Write a function to toggle hidden class on modal'
];
// console.log('Jira Titles', jiraTitles);
function getIcon() {
let rNum = getRandomIntInclusive(0,2);
return rNum == 1 ? jiraTemplate : errorJiraTemplate;
};
const dataHandler = new DataHandler();
module.exports = dataHandler;
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
baseUrl: 'https://api.github.com',
log: {
debug: () => {},
info: () => {},
warn: console.warn,
error: console.error
},
request: {
agent: undefined,
fetch: undefined,
timeout: 0
}
});
var jira = new JiraApi({
protocol: "https",
host: "totalwine.atlassian.net",
username: process.env.JIRA_USERNAME,
password: process.env.JIRA_TOKEN,
apiVersion: "2",
strictSSL: true,
});
jira
.findIssue('TT-140')
.then(function(issue) {
console.log('Status: ' + issue.fields.status.name);
})
.catch(function(err) {
console.error(err);
});