Skip to content
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

Notification Visual Updates #306

Merged
merged 4 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lucky-beds-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@gitbook/integration-slack': minor
---

Reformats the notifications into a list
2 changes: 1 addition & 1 deletion integrations/slack/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Slack integration

To configure it for your environment, create an application on Slack and use the `slack-manifest.yaml` file to configure it. Don't forget to update the URLs to natch your environment.
To configure it for your environment, create an application on Slack and use the `slack-manifest.yaml` file to configure it. Don't forget to update the URLs to match your environment.


To publish it, run the command with the `SLACK_CLIENT_ID`, `SLACK_CLIENT_SECRET`, and `SLACK_SIGNING_SECRET ` environment variables defined:
Expand Down
25 changes: 15 additions & 10 deletions integrations/slack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createIntegration, EventCallback } from '@gitbook/runtime';
import { SlackRuntimeContext } from './configuration';
import { handleFetchEvent } from './router';
import { slackAPI } from './slack';
import { Spacer } from './ui';

/*
* Handle content being updated: send a notification on Slack.
Expand Down Expand Up @@ -100,6 +101,10 @@ const handleSpaceContentUpdated: EventCallback<
space.title || 'Space'
}>* has been updated.`;

const renderList = (list: string[]) => {
return list.map((item) => `• ${item}\n`);
};

if (
createdPages.length > 0 ||
editedPages.length > 0 ||
Expand All @@ -109,32 +114,30 @@ const handleSpaceContentUpdated: EventCallback<
editedFiles.length > 0 ||
deletedFiles.length > 0
) {
notificationText += '\n\nSummary of changes:';

if (createdPages.length > 0) {
notificationText += `\nNew pages: ${createdPages.join(', ')}`;
notificationText += `\n*New pages:*\n${renderList(createdPages)}\n\n`;
}
if (editedPages.length > 0) {
notificationText += `\nModified pages: ${editedPages.join(', ')}`;
notificationText += `\n*Modified pages:*\n${renderList(editedPages)}\n\n`;
}
if (deletedPages.length > 0) {
notificationText += `\nDeleted pages: ${deletedPages.join(', ')}`;
notificationText += `\n*Deleted pages:*\n${renderList(deletedPages)}\n\n`;
}
if (movedPages.length > 0) {
notificationText += `\nMoved pages: ${movedPages.join(', ')}`;
notificationText += `\n*Moved pages:*\n${renderList(movedPages)}\n\n`;
}
if (createdFiles.length > 0) {
notificationText += `\nNew files: ${createdFiles.join(', ')}`;
notificationText += `\n*New files:*\n${renderList(createdFiles)}\n\n`;
}
if (editedFiles.length > 0) {
notificationText += `\nModified files: ${editedFiles.join(', ')}`;
notificationText += `\n*Modified files:*\n${renderList(editedFiles)}\n\n`;
}
if (deletedFiles.length > 0) {
notificationText += `\nDeleted files: ${deletedFiles.join(', ')}`;
notificationText += `\n*Deleted files:*\n${renderList(deletedFiles)}\n\n`;
}

if (semanticChanges.more > 0) {
notificationText += `\n\nAnd another ${semanticChanges.more} changes not listed here.`;
notificationText += `\n\nAnd another ${semanticChanges.more} changes not listed here.\n`;
}
}

Expand All @@ -144,13 +147,15 @@ const handleSpaceContentUpdated: EventCallback<
payload: {
channel,
blocks: [
Spacer,
{
type: 'section',
text: {
type: 'mrkdwn',
text: notificationText,
},
},
Spacer,
],
},
});
Expand Down