-
Notifications
You must be signed in to change notification settings - Fork 0
/
Code.gs
119 lines (107 loc) · 3.55 KB
/
Code.gs
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
const persons = [
{
name: "Rahim Mia",
email: "rahim.mia@xyz.com",
role: "Manager",
},
{
name: "Zorina Beghum",
email: "zorina.begum@xyz.com",
role: "QA",
},
{
name: "Karim Mia",
email: "karim.mia@xyz.com",
role: "Developer",
},
{
name: "Jobbar Khan",
email: "jobbar.khan@xyz.com",
role: "Developer",
},
];
function sendMail(recipientEmail, subject, body) {
try {
GmailApp.sendEmail(recipientEmail, subject, body);
console.log(`Email send to ${subject}`);
} catch (error) {
console.error("Failed to send email:", error);
}
}
function autoUpdateToManager(body) {
const recipientEmail = persons.find(
(person) => person.role === "Manager"
)?.email;
if (recipientEmail) {
const subject = `General Update | Bug List Update | Manager | ${new Date()}`;
sendMail(recipientEmail, subject, body);
} else {
console.warning("Manager's email not found.");
}
}
function unassignedBugNotify() {
const recipientEmail = persons.find(
(person) => person.role === "Manager"
)?.email;
if (recipientEmail) {
const subject = `Unassigned Bug | Manager | ${new Date()}`;
const body = "A new bug has been listed into the Spreadsheet Bug List.";
sendMail(recipientEmail, subject, body);
} else {
console.warning("Manager's email not found.");
}
}
function notifyQA() {
const qaEmail = persons.find(
(person) => person.role === "QA"
)?.email;
if (qaEmail) {
const subject = `Bug Fixed | QA | ${new Date()}`;
const body = "A bug has been fixed/resolved. Please take a look into it.";
sendMail(qaEmail, subject, body);
} else {
console.warning("QA's email not found.");
}
}
function notifyDeveloper(name, message) {
const developerEmail = persons.find(
(person) => person.name === name
)?.email;
if (developerEmail) {
const subject = `Bug Update | Developer | ${new Date()}`;
sendMail(developerEmail, subject, message);
} else {
console.warning("Developer's email not found.");
}
}
function onEdit(e) {
console.log(`Author: Mehedi Hasan Shifat (www.github.com/jspw). App Version: 1.0.0`);
try {
const sheet = e.source.getActiveSheet();
const range = e.range;
const column = range.getColumn();
const value = range.getValue();
if (column === 9) { // Column 9 => Column: "Status"
// autoUpdateToManager("BUG Status has been changed to " + value);
if (value === "Unassigned") {
unassignedBugNotify();
} else if (value === "Fixed") {
notifyQA();
} else if (value === "Re Opened") {
const name = sheet.getRange(range.getRow(), 10).getValue();
autoUpdateToManager("A bug has been re-opened. Developer: " + name);
if (!name) {
unassignedBugNotify();
}
else {
notifyDeveloper(name, `One of your task has been re-opened. Please take a look into it.`);
}
}
} else if (column === 10) { // Column 10 => Column "Assignee"
// autoUpdateToManager("A new bug has been assigned to " + value);
notifyDeveloper(value, "A new bug has been assigned to you. Please take a look into it.");
}
} catch (error) {
console.error("Error:", error.message);
}
}