-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabel-issues.js
166 lines (144 loc) · 5.37 KB
/
label-issues.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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
const { Octokit } = require("@octokit/rest");
const axios = require("axios");
const nodemailer = require("nodemailer");
const getCataegoryMap = () =>{
const categoryMap = new Map();
categoryMap.set('paportal', {owner: 'gshivi', contact: '[email protected]'});
categoryMap.set('pcf', {owner: 'gshivi', contact: '[email protected]'});
categoryMap.set('solution', {owner: 'gshivi', contact: '[email protected]'});
categoryMap.set('canvas-app', {owner: 'gshivi', contact: '[email protected]'});
categoryMap.set('unknown', {owner: 'gshivi', contact: '[email protected]'});
return categoryMap;
}
async function main() {
const octokit = new Octokit({ auth: process.env.PAT_TOKEN });
// Fetch the issue information
const issue = await octokit.issues.get({
owner: process.env.GITHUB_REPOSITORY_OWNER,
repo: process.env.GITHUB_REPOSITORY_NAME,
issue_number: process.env.GITHUB_ISSUE_NUMBER,
});
console.log(issue);
const issueTitle = issue.data.title;
const issueBody = issue.data.body;
const categoryMap = getCataegoryMap();
const categoryArray = [...categoryMap.keys()];
const prompt = `You are a classification tool and your primary purpose is to classify based on the issue title & issue description. Output must be one word only. Output must be one of the entries in this array: ${categoryArray}. Issue title: ${issueTitle}. Issue description: ${issueBody}. Refer to the following examples to determine the response. If the issue's title or body contains paportal, it should be labelled as paportal. If it contains pcf, label issue as pcf. If the issue can't be classified, label it as unknown.`;
let data = JSON.stringify({
prompt: prompt,
temperature: 0,
top_p: 1,
frequency_penalty: 0,
presence_penalty: 0,
max_tokens: 60,
best_of: 1,
stop: null,
});
let config = {
method: "post",
maxBodyLength: Infinity,
url: "https://nikhilhackathonjune.openai.azure.com/openai/deployments/NikhilDavinci003/completions?api-version=2022-12-01",
headers: {
"Content-Type": "application/json",
"api-key": process.env.API_KEY,
},
data: data,
};
axios
.request(config)
.then(async (response) => {
const gptResponse = response.data.choices[0].text;
// Add the label to the issue
const categoryKey = gptResponse.toLowerCase();
const label = categoryKey.trim().replace(/\n/g, "");
// octokit.issues.addLabels({
// owner: process.env.GITHUB_REPOSITORY_OWNER,
// repo: process.env.GITHUB_REPOSITORY_NAME,
// issue_number: process.env.GITHUB_ISSUE_NUMBER,
// labels: [label],
// });
const categoryRecord =
categoryMap.get(categoryKey ?? "unknown") ?? categoryMap.get("unknown");
// Assign the issue to the owner
// octokit.issues.addAssignees({
// owner: process.env.GITHUB_REPOSITORY_OWNER,
// repo: process.env.GITHUB_REPOSITORY_NAME,
// issue_number: process.env.GITHUB_ISSUE_NUMBER,
// assignees: [categoryRecord.owner],
// });
// Code-flow for sending mail
const transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: "[email protected]",
pass: process.env.MAIL_APP_PASSWORD,
},
port: 465,
});
const mailBody = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GitHub Issue Assigned</title>
<style>
/* GitHub Fonts */
@import url('https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@400;700&display=swap');
/* GitHub Styles */
body {
font-family: 'Roboto Mono', monospace;
font-size: 16px;
line-height: 1.6;
color: #333333;
}
h2 {
font-size: 24px;
font-weight: bold;
margin-bottom: 20px;
}
h3 {
color: #0366d6;
font-size: 20px;
font-weight: bold;
margin-top: 30px;
margin-bottom: 15px;
}
p {
margin-bottom: 10px;
}
</style>
</head>
<body>
<h2>GitHub Issue Assigned</h2>
<p>Dear ${categoryRecord.owner},</p>
<p>An issue has been assigned to you on GitHub:</p>
<h3>${issueTitle}</h3>
<p>${issueBody}</p>
<p>Please take appropriate action and provide necessary updates as needed.</p>
<p>Thank you!</p>
<p>Sincerely,</p>
<p>Your Team</p>
</body>
</html>
`;
const mailOptions = {
from: "[email protected]",
to: categoryRecord.contact,
subject: `Assignment Notification: [${issue.data.title}] assigned to your ownership`,
html: mailBody,
};
//send();
async function send() {
const result = await transporter.sendMail(mailOptions);
console.log(JSON.stringify(result, null, 4));
}
})
.catch((error) => {
console.log(error);
});
}
main().catch((error) => {
console.error("Error:", error);
process.exit(1);
});