Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 4567d52

Browse files
author
Parth Shah
committed
fixes #67
1 parent 0b8e801 commit 4567d52

File tree

3 files changed

+99
-45
lines changed

3 files changed

+99
-45
lines changed

src/common/constants.js

Lines changed: 97 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,22 @@ const _ = require('lodash');
1111
const config = require('config');
1212

1313
const projectTypes = {
14-
app_dev: 'Full App',
15-
generic: 'Work Project',
16-
visual_prototype: 'Design & Prototype',
17-
visual_design: 'Design',
14+
app_dev: {
15+
label: 'Full App',
16+
color: '#96d957'
17+
},
18+
generic: {
19+
label: 'Work Project',
20+
color: '#b47dd6'
21+
},
22+
visual_prototype: {
23+
label: 'Design & Prototype',
24+
color: '#67c5ef'
25+
},
26+
visual_design: {
27+
label: 'Design',
28+
color: '#67c5ef'
29+
}
1830
};
1931
const icons = {
2032
slack: {
@@ -39,14 +51,17 @@ module.exports = {
3951
projectInReview: (data) => {
4052
return {
4153
channel: `${config.get('SLACK_CHANNEL_MANAGERS')}`,
54+
color: projectTypes[data.project.type].color,
4255
pretext: 'A project is ready to be reviewed.',
4356
fallback: 'A project is ready to be reviewed.',
4457
title: _.get(data, 'project.name', ''),
4558
title_link: `https://connect.${config.get('AUTH_DOMAIN')}/projects/${data.project.id}/`,
46-
text: _.truncate(_.get(data, 'project.description', ''), { length: 200, separator: /,? +.,/ }),
59+
text: _.truncate(_.get(data, 'project.description', ''), {
60+
length: 200,
61+
separator: /,? +.,/
62+
}),
4763
ts: (new Date(_.get(data, 'project.updatedAt', null))).getTime() / 1000,
48-
fields: [
49-
{
64+
fields: [{
5065
title: 'Ref Code',
5166
value: _.get(data, 'project.details.utm.code', ''),
5267
short: false,
@@ -58,7 +73,7 @@ module.exports = {
5873
},
5974
{
6075
title: 'Project Type',
61-
value: projectTypes[data.project.type],
76+
value: projectTypes[data.project.type].label,
6277
short: false,
6378
},
6479
],
@@ -67,58 +82,64 @@ module.exports = {
6782
projectUnclaimed: (data) => {
6883
return {
6984
icon_url: icons.slack.CoderBotIcon,
85+
color: projectTypes[data.project.type].color,
7086
channel: `${config.get('SLACK_CHANNEL_COPILOTS')}`,
7187
pretext: 'A project has been reviewed and needs a copilot. Please check it out and claim it.',
7288
fallback: 'A project has been reviewed and needs a copilot. Please check it out and claim it.',
7389
title: _.get(data, 'project.name', ''),
7490
title_link: `https://connect.${config.get('AUTH_DOMAIN')}/projects/${data.project.id}/`,
75-
text: _.truncate(_.get(data, 'project.description', ''), { length: 200, separator: /,? +.,/ }),
91+
text: _.truncate(_.get(data, 'project.description', ''), {
92+
length: 200,
93+
separator: /,? +.,/
94+
}),
7695
ts: (new Date(_.get(data, 'project.updatedAt', null))).getTime() / 1000,
77-
fields: [
78-
{
79-
title: 'Project Type',
80-
value: projectTypes[data.project.type],
81-
short: false,
82-
},
83-
]
96+
fields: [{
97+
title: 'Project Type',
98+
value: projectTypes[data.project.type].label,
99+
short: false,
100+
}, ]
84101
}
85102
},
86103
projectUnclaimedReposted: (data) => {
87104
return {
88105
icon_url: icons.slack.CoderErrorIcon,
106+
color: projectTypes[data.project.type].color,
89107
channel: `${config.get('SLACK_CHANNEL_COPILOTS')}`,
90108
pretext: 'We\'re still looking for a copilot for a reviewed project. Please check it out and claim it.',
91109
fallback: 'We\'re still looking for a copilot for a reviewed project. Please check it out and claim it.',
92110
title: _.get(data, 'project.name', ''),
93111
title_link: `https://connect.${config.get('AUTH_DOMAIN')}/projects/${data.project.id}/`,
94-
text: _.truncate(_.get(data, 'project.description', ''), { length: 200, separator: /,? +.,/ }),
112+
text: _.truncate(_.get(data, 'project.description', ''), {
113+
length: 200,
114+
separator: /,? +.,/
115+
}),
95116
ts: (new Date(_.get(data, 'project.updatedAt', null))).getTime() / 1000,
96-
fields: [
97-
{
98-
title: 'Project Type',
99-
value: projectTypes[data.project.type],
100-
short: false,
101-
},
102-
]
117+
fields: [{
118+
title: 'Project Type',
119+
value: projectTypes[data.project.type].label,
120+
short: false,
121+
}, ]
103122
}
104123
},
105124
projectClaimed: (data) => {
106125
return {
107126
icon_url: icons.slack.CoderGrinningIcon,
127+
color: projectTypes[data.project.type].color,
108128
channel: `${config.get('SLACK_CHANNEL_COPILOTS')}`,
109129
pretext: `${data.firstName} ${data.lastName} has claimed a project. Welcome to the team!`,
110130
fallback: `${data.firstName} ${data.lastName} has claimed a project. Welcome to the team!`,
111131
title: _.get(data, 'project.name', ''),
112132
title_link: `https://connect.${config.get('AUTH_DOMAIN')}/projects/${data.project.id}/`,
113-
text: _.truncate(_.get(data, 'project.description', ''), { length: 200, separator: /,? +.,/ }),
133+
text: _.truncate(_.get(data, 'project.description', ''), {
134+
length: 200,
135+
separator: /,? +.,/
136+
}),
114137
ts: (new Date(_.get(data, 'project.updatedAt', null))).getTime() / 1000,
115-
fields: [
116-
{
117-
title: 'Project Type',
118-
value: projectTypes[data.project.type],
119-
short: false,
120-
},
121-
]
138+
fields: [{
139+
title: 'Project Type',
140+
value: projectTypes[data.project.type].label,
141+
short: false,
142+
}, ]
122143
}
123144
},
124145
},
@@ -177,19 +198,52 @@ module.exports = {
177198
},
178199
},
179200
project: {
180-
created: { notificationType: 'Project.Created', subject: 'Created' },
181-
submittedForReview: { notificationType: 'Project.SubmittedForReview', subject: 'Submitted for review' },
182-
availableForReview: { notificationType: 'Project.AvailableForReview', subject: 'Available for review' },
183-
reviewed: { notificationType: 'Project.Reviewed', subject: 'Reviewed' },
184-
availableToClaim: { notificationType: 'Project.AvailableToClaim', subject: 'Reviewed - Available to claim' },
201+
created: {
202+
notificationType: 'Project.Created',
203+
subject: 'Created'
204+
},
205+
submittedForReview: {
206+
notificationType: 'Project.SubmittedForReview',
207+
subject: 'Submitted for review'
208+
},
209+
availableForReview: {
210+
notificationType: 'Project.AvailableForReview',
211+
subject: 'Available for review'
212+
},
213+
reviewed: {
214+
notificationType: 'Project.Reviewed',
215+
subject: 'Reviewed'
216+
},
217+
availableToClaim: {
218+
notificationType: 'Project.AvailableToClaim',
219+
subject: 'Reviewed - Available to claim'
220+
},
185221
},
186222
teamMember: {
187-
added: { notificationType: 'Project.Member.Added', subject: 'Member added' },
188-
managerJoined: { notificationType: 'Project.Member.ManagerJoined', subject: 'Manager joined' },
189-
copilotJoined: { notificationType: 'Project.Member.CopilotJoined', subject: 'Copilot joined' },
190-
removed: { notificationType: 'Project.Member.Removed', subject: 'Member removed' },
191-
left: { notificationType: 'Project.Member.Left', subject: 'Member left' },
192-
ownerChanged: { notificationType: 'Project.Member.OwnerChanged', subject: 'Ownership changed' },
223+
added: {
224+
notificationType: 'Project.Member.Added',
225+
subject: 'Member added'
226+
},
227+
managerJoined: {
228+
notificationType: 'Project.Member.ManagerJoined',
229+
subject: 'Manager joined'
230+
},
231+
copilotJoined: {
232+
notificationType: 'Project.Member.CopilotJoined',
233+
subject: 'Copilot joined'
234+
},
235+
removed: {
236+
notificationType: 'Project.Member.Removed',
237+
subject: 'Member removed'
238+
},
239+
left: {
240+
notificationType: 'Project.Member.Left',
241+
subject: 'Member left'
242+
},
243+
ownerChanged: {
244+
notificationType: 'Project.Member.OwnerChanged',
245+
subject: 'Ownership changed'
246+
},
193247
},
194248
},
195249
projectStatuses: {

src/handlers/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ function buildSlackNotification(data, slackDataGenerator) {
203203
icon_url: slackData.url || config.get('SLACK_ICON_URL'),
204204
channel: slackData.channel,
205205
attachments: [{
206-
color: "#36a64f",
206+
color: slackData.color || "#36a64f",
207207
fallback: slackData.fallback,
208208
pretext: slackData.pretext,
209209
fields: slackData.fields,

src/test/app.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const expectedSlackNotficationBase = {
5252
attachments: [{
5353
pretext: "",
5454
fallback: "",
55-
color: "#36a64f",
55+
color: "#67c5ef",
5656
title: "test",
5757
title_link: "https://connect.topcoder-dev.com/projects/1/",
5858
text: "test",

0 commit comments

Comments
 (0)