-
Notifications
You must be signed in to change notification settings - Fork 1
Fix message when there are no celebrations #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
add8bf8
refactor: split publishers in different files for better readability
inigomarquinez 9d730a9
refactor: split slack message builder for celebrations
inigomarquinez 270379a
refactor: move buildMessageToSend out
inigomarquinez 1ee4ded
fix: amend published message when there are no celebrations
inigomarquinez 8b13bf7
docs: improve README
inigomarquinez f382856
Merge branch 'main' into refactor-publishers
inigomarquinez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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', | ||
}); | ||
inigomarquinez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.