- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataHandler.js
More file actions
Latest commit
122 lines (109 loc) · 3.26 KB
/
Copy pathdataHandler.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()
varJiraApi=require('jira-client');
consterrorJiraTemplate={icon: 'bi bi-x-circle'};
constjiraTemplate={icon: 'bi bi-check-circle-fill'};
letjiraNums=[];
classDataHandler{
constructor(links,title){
this.links=links||[];
this.title=title||[];
this.jirasObj=[];
this.createJiraObject();
this.fetchGitHubData();
}
createJiraObject(){
for(leti=0;i<this.title.length;i++){
leticon=getIcon()
this.jirasObj.push({
link: this.links[i],
title: this.title[i],
...icon
});
}
returnthis.jirasObj;
}
asyncfetchGitHubData(){
constoctokit=newOctokit({
auth: process.env.GITHUB_TOKEN
});
try{
constresponse=awaitoctokit.rest.repos.listCommits({
owner: "thinlizee",
repo: "engineering-training",
});
// console.log('response', JSON.stringify(response));
for(leti=0;i<response.data.length;i++){
constregex=/[A-Z][A-Z]+-\d+/g;
constticketNum=response.data[i].commit.message.match(regex);
if(ticketNum!==null&&jiraNums.indexOf(ticketNum[0])==-1){
jiraNums.push(ticketNum[0]);
}
}
console.log(jiraNums);
for(letts=0;ts<21;ts++){
constmessage=response.data[ts].commit.message;
console.log('summary: '+message+'\n');
}
}
catch(error){
console.log("Error getting data:",error.message);
}
}
};
functiongetRandomIntInclusive(min,max){
min=Math.ceil(min);
max=Math.floor(max);
returnMath.floor(Math.random()*(max-min+1)+min);// The maximum is inclusive and the minimum is inclusive
};
letjiraLinks=['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);
letjiraTitles=['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);
functiongetIcon(){
letrNum=getRandomIntInclusive(0,2);
returnrNum==1 ? jiraTemplate : errorJiraTemplate;
};
constdataHandler=newDataHandler();
module.exports=dataHandler;
constoctokit=newOctokit({
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
}
});
varjira=newJiraApi({
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);
});