Skip to content

Commit

Permalink
Merge pull request #23 from apiaryio/nadade/add-second-overlap-date
Browse files Browse the repository at this point in the history
feat: add the other overlapping shift date to messages
  • Loading branch information
miiila authored Jul 26, 2017
2 parents c0b6af2 + 830f64c commit 03e2b7c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/notify.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,18 @@ formatMessage = (messages, option = 'plain') ->
when 'plain'
outputMessage = "_Following overlaps found:_\n"
for message in messages
outputMessage += """#{message.user}: #{message.schedules[0]} and #{message.schedules[1]} on #{message.date.toUTCString()}\n"""
outputMessage += """#{message.user}: #{message.schedules[0]} and #{message.schedules[1]} (the first starting on #{message.date.toUTCString()}, the second on #{message.crossDate.toUTCString()})\n"""
when 'markdown'
outputMessage = "Following overlaps found:\n"
for message in messages
outputMessage += """*#{message.user}:* `#{message.schedules[0]}` and `#{message.schedules[1]}` on #{message.date.toUTCString()}\n"""
outputMessage += """*#{message.user}:* `#{message.schedules[0]}` and `#{message.schedules[1]}` (the first starting on #{message.date.toUTCString()}, the second on #{message.crossDate.toUTCString()})\n"""
when 'json'
outputMessage = messages.reduce((acc, curr)->
acc[curr.userId] ?= {}
acc[curr.userId].userId ?= curr.userId
acc[curr.userId].user ?= curr.user
acc[curr.userId].messages ?= []
acc[curr.userId].messages.push("#{curr.schedules[0]} and #{curr.schedules[1]} #{curr.date.toUTCString()}")
acc[curr.userId].messages.push("#{curr.schedules[0]} and #{curr.schedules[1]} (the first starting on #{curr.date.toUTCString()}, the second on #{curr.crossDate.toUTCString()})")
return acc
, {})

Expand Down
2 changes: 1 addition & 1 deletion src/pagerduty.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ processSchedules = (allSchedules, days = [], cb) ->
scheduleId = nconf.get("schedulesNames:#{schedule.id}")
crossScheduleId = nconf.get("schedulesNames:#{crossSchedule.id}")

message = {user: myUserName, userId: myUserId, schedules: [scheduleId, crossScheduleId], date: startDate}
message = {user: myUserName, userId: myUserId, schedules: [scheduleId, crossScheduleId], date: startDate, crossDate: new Date(crossCheckEntry.start)}

if myStart <= crossCheckEntry.start < myEnd and
crossCheckEntry.user.id == myUserId
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/incident.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"body": {
"type": "incident_body",
"details": "Primary and Secondary Sun, 19 Aug 2012 16:00:00 GMT"
"details": "Primary and Secondary (the first starting on Sun, 19 Aug 2012 16:00:00 GMT, the second on Sun, 19 Aug 2012 16:00:00 GMT)"
},
"assignments": [
{
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/incident2.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"body": {
"type": "incident_body",
"details": "Primary and Secondary Sun, 19 Aug 2012 04:00:00 GMT"
"details": "Primary and Secondary (the first starting on Sun, 19 Aug 2012 04:00:00 GMT, the second on Sun, 19 Aug 2012 04:00:00 GMT)"
},
"assignments": [
{
Expand Down
9 changes: 6 additions & 3 deletions test/notify-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ describe 'Test send message using notify.send for both', ->
actual = null

before (done) ->
overlapDate = new Date()
message =
user: 'Test user'
userId: '1234'
schedules: ['TEST1', 'TEST2']
date: new Date()
date: overlapDate
crossDate: overlapDate

expectBody =
text:"Following overlaps found:\n*Test user:* `TEST1` and `TEST2` on #{message.date.toUTCString()}\n"
text:"Following overlaps found:\n*Test user:* `TEST1` and `TEST2` (the first starting on #{overlapDate.toUTCString()}, the second on #{overlapDate.toUTCString()})\n"
channel:"#channel-name"

config.setupConfig configPath, (err) ->
Expand All @@ -44,7 +46,8 @@ describe 'Test send message using notify.send for both', ->
user: 'Test user'
userId: '1234'
schedules: ['TEST1', 'TEST2']
date: new Date()
date: overlapDate
crossDate: overlapDate

notify.send options, [ message ], (err, result) ->
if err then return done err
Expand Down

0 comments on commit 03e2b7c

Please sign in to comment.