-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from guidesmiths/refactor-publishers
Fix message when there are no celebrations
- Loading branch information
Showing
8 changed files
with
226 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates | ||
|
||
version: 2 | ||
|
||
updates: | ||
- package-ecosystem: "npm" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import moment from 'moment'; | ||
|
||
import { TWhosOut } from '..'; | ||
import { | ||
FRIDAY_ISO_WEEKDAY, | ||
HUMAN_READABLE_DATE, | ||
MONDAY_ISO_WEEKDAY, | ||
} from '../common'; | ||
import { postSlackMessage } from '../http'; | ||
|
||
export const pusblishBankHolidays = async ( | ||
bankHolidays: TWhosOut, | ||
today: moment.Moment | ||
): Promise<void> => { | ||
const monthBankHolidaysBlocks: any[] = []; | ||
let nextBankHolidaysBlocks: any[] = []; | ||
|
||
if ( | ||
bankHolidays.month.length > 0 && | ||
((today.date() === 1 && today.isoWeekday() <= FRIDAY_ISO_WEEKDAY) || | ||
(today.date() === 2 && today.isoWeekday() === MONDAY_ISO_WEEKDAY) || | ||
(today.date() === 3 && today.isoWeekday() === MONDAY_ISO_WEEKDAY)) | ||
) { | ||
monthBankHolidaysBlocks.push({ | ||
type: 'context', | ||
elements: [ | ||
{ | ||
type: 'mrkdwn', | ||
text: '*This month bank holidays:*', | ||
}, | ||
], | ||
}); | ||
|
||
monthBankHolidaysBlocks.push( | ||
...bankHolidays.month.map(holiday => ({ | ||
type: 'section', | ||
text: { | ||
type: 'mrkdwn', | ||
text: `*${holiday.name}*\n${moment(holiday.start).format( | ||
HUMAN_READABLE_DATE | ||
)}`, | ||
}, | ||
})) | ||
); | ||
|
||
monthBankHolidaysBlocks.push({ | ||
type: 'divider', | ||
}); | ||
} | ||
|
||
if (bankHolidays.next.length > 0) { | ||
nextBankHolidaysBlocks = bankHolidays.next.map(holiday => ({ | ||
type: 'section', | ||
text: { | ||
type: 'mrkdwn', | ||
text: `*${holiday.name}*\n${moment(holiday.start).format( | ||
HUMAN_READABLE_DATE | ||
)}`, | ||
}, | ||
})); | ||
} | ||
|
||
if (monthBankHolidaysBlocks.length > 0 || nextBankHolidaysBlocks.length > 0) { | ||
const message = { | ||
text: '🏖️ Bank Holidays', | ||
blocks: [ | ||
{ | ||
type: 'header', | ||
text: { | ||
type: 'plain_text', | ||
text: '🏖️ Bank Holidays', | ||
emoji: true, | ||
}, | ||
}, | ||
...monthBankHolidaysBlocks, | ||
...nextBankHolidaysBlocks, | ||
], | ||
}; | ||
|
||
await postSlackMessage( | ||
process.env.BANK_HOLIDAYS_WEBHOOK_URL ?? '', | ||
message | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import moment from 'moment'; | ||
|
||
import { | ||
TBambooHREmployeeAtOffice, | ||
TBambooHREmployeeExtended, | ||
TWhosOut, | ||
} from '..'; | ||
import { FRIDAY_ISO_WEEKDAY } from '../common'; | ||
import { postSlackMessage } from '../http'; | ||
|
||
export const publishEmployeesAtOffice = async ( | ||
employees: TBambooHREmployeeExtended[], | ||
employeesAtOffice: TBambooHREmployeeAtOffice[], | ||
today: moment.Moment | ||
): Promise<void> => { | ||
// First filter 'employeesAtOffice' to those included in 'employees' | ||
const filteredEmployeesAtOffice = employeesAtOffice.reduce< | ||
TBambooHREmployeeExtended[] | ||
>((previousValue, currentEmployee) => { | ||
const employee = employees.find(e => e.id === currentEmployee.employeeId); | ||
return employee ? previousValue.concat(employee) : previousValue; | ||
}, []); | ||
|
||
const blocks = | ||
filteredEmployeesAtOffice.length > 0 | ||
? filteredEmployeesAtOffice.map(e => ({ | ||
type: 'context', | ||
elements: [ | ||
{ | ||
type: 'image', | ||
image_url: e.photoUrl, | ||
alt_text: 'employee avatar', | ||
}, | ||
{ | ||
type: 'mrkdwn', | ||
text: `*${e.displayName}*`, | ||
}, | ||
], | ||
})) | ||
: [ | ||
{ | ||
type: 'context', | ||
elements: [ | ||
{ | ||
type: 'mrkdwn', | ||
text: ':eyes: *Nobody at the office!*', | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
const message = { | ||
text: `🏢 ${ | ||
today.isoWeekday() < FRIDAY_ISO_WEEKDAY ? 'Tomorrow' : 'Next Monday' | ||
} at One Beyond offices`, | ||
blocks: [ | ||
{ | ||
type: 'header', | ||
text: { | ||
type: 'plain_text', | ||
text: `🏢 ${ | ||
today.isoWeekday() < FRIDAY_ISO_WEEKDAY ? 'Tomorrow' : 'Next Monday' | ||
} at One Beyond offices`, | ||
emoji: true, | ||
}, | ||
}, | ||
...blocks, | ||
], | ||
}; | ||
|
||
await postSlackMessage(process.env.OFFICE_WEBHOOK_URL ?? '', message); | ||
}; |
Oops, something went wrong.