-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.js
48 lines (43 loc) · 1.39 KB
/
helpers.js
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
const { Configuration, OpenAIApi } = require("openai");
const { LinearClient } = require('@linear/sdk');
const linearClient = new LinearClient({
apiKey: process.env.LINEAR_API_KEY,
accessToken: process.env.APP_TOKEN
})
function millisecondsToStr(milliseconds) {
const seconds = Math.floor(milliseconds / 1000);
const minutes = Math.floor(seconds / 60);
const hours = Math.floor(minutes / 60);
const days = Math.floor(hours / 24);
const remainingSeconds = seconds % 60;
const remainingMinutes = minutes % 60;
const remainingHours = hours % 24;
let str = "";
if (days > 0) {
str += `${days}d `;
}
if (remainingHours > 0) {
str += `${remainingHours}h `;
}
if (remainingMinutes > 0) {
str += `${remainingMinutes}m `;
}
if (remainingSeconds > 0) {
str += `${remainingSeconds}s`;
}
return str.trim();
}
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
function replaceTemplateVars(template, vars) {
return template.replace(/\${(.*?)}/g, function(match, varName) {
if(varName.includes('.')) {
return vars[varName.split('.')[0]][varName.split('.')[1]] || '';
}else{
return vars[varName] || '';
}
});
}
module.exports = { millisecondsToStr, openai, linearClient, replaceTemplateVars };