-
-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into Api-client_invitationList
- Loading branch information
Showing
30 changed files
with
8,260 additions
and
394 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
30 changes: 30 additions & 0 deletions
30
apps/api/src/integration/plugins/slack/slack.integration.spec.ts
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,30 @@ | ||
import { IntegrationType } from '@prisma/client' | ||
import { SlackIntegration } from './slack.integration' | ||
|
||
describe('Slack Integration Test', () => { | ||
let integration: SlackIntegration | ||
|
||
beforeEach(() => { | ||
integration = new SlackIntegration() | ||
}) | ||
|
||
it('should generate slack integration', () => { | ||
expect(integration).toBeDefined() | ||
expect(integration.integrationType).toBe(IntegrationType.SLACK) | ||
}) | ||
|
||
it('should have the correct permitted events', () => { | ||
const events = integration.getPermittedEvents() | ||
expect(events).toBeDefined() | ||
expect(events.size).toBe(26) | ||
}) | ||
|
||
it('should have the correct required metadata parameters', () => { | ||
const metadata = integration.getRequiredMetadataParameters() | ||
expect(metadata).toBeDefined() | ||
expect(metadata.size).toBe(3) | ||
expect(metadata.has('botToken')).toBe(true) | ||
expect(metadata.has('signingSecret')).toBe(true) | ||
expect(metadata.has('channelId')).toBe(true) | ||
}) | ||
}) |
120 changes: 120 additions & 0 deletions
120
apps/api/src/integration/plugins/slack/slack.integration.ts
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,120 @@ | ||
import { EventType, IntegrationType } from '@prisma/client' | ||
import { | ||
SlackIntegrationMetadata, | ||
IntegrationEventData | ||
} from '../../integration.types' | ||
import { App } from '@slack/bolt' | ||
import { BaseIntegration } from '../base.integration' | ||
import { Logger } from '@nestjs/common' | ||
|
||
export class SlackIntegration extends BaseIntegration { | ||
private readonly logger = new Logger('SlackIntegration') | ||
private app: App | ||
constructor() { | ||
super(IntegrationType.SLACK) | ||
} | ||
|
||
public getPermittedEvents(): Set<EventType> { | ||
return new Set([ | ||
EventType.INTEGRATION_ADDED, | ||
EventType.INTEGRATION_UPDATED, | ||
EventType.INTEGRATION_DELETED, | ||
EventType.INVITED_TO_WORKSPACE, | ||
EventType.REMOVED_FROM_WORKSPACE, | ||
EventType.ACCEPTED_INVITATION, | ||
EventType.DECLINED_INVITATION, | ||
EventType.CANCELLED_INVITATION, | ||
EventType.LEFT_WORKSPACE, | ||
EventType.WORKSPACE_UPDATED, | ||
EventType.WORKSPACE_CREATED, | ||
EventType.WORKSPACE_ROLE_CREATED, | ||
EventType.WORKSPACE_ROLE_UPDATED, | ||
EventType.WORKSPACE_ROLE_DELETED, | ||
EventType.PROJECT_CREATED, | ||
EventType.PROJECT_UPDATED, | ||
EventType.PROJECT_DELETED, | ||
EventType.SECRET_UPDATED, | ||
EventType.SECRET_DELETED, | ||
EventType.SECRET_ADDED, | ||
EventType.VARIABLE_UPDATED, | ||
EventType.VARIABLE_DELETED, | ||
EventType.VARIABLE_ADDED, | ||
EventType.ENVIRONMENT_UPDATED, | ||
EventType.ENVIRONMENT_DELETED, | ||
EventType.ENVIRONMENT_ADDED, | ||
EventType.INTEGRATION_ADDED, | ||
EventType.INTEGRATION_UPDATED, | ||
EventType.INTEGRATION_DELETED | ||
]) | ||
} | ||
|
||
public getRequiredMetadataParameters(): Set<string> { | ||
return new Set(['botToken', 'signingSecret', 'channelId']) | ||
} | ||
|
||
async emitEvent( | ||
data: IntegrationEventData, | ||
metadata: SlackIntegrationMetadata | ||
): Promise<void> { | ||
this.logger.log(`Emitting event to Slack: ${data.title}`) | ||
try { | ||
if (!this.app) { | ||
this.app = new App({ | ||
token: metadata.botToken, | ||
signingSecret: metadata.signingSecret | ||
}) | ||
} | ||
const block = [ | ||
{ | ||
type: 'header', | ||
text: { | ||
type: 'plain_text', | ||
text: 'Update occurred on keyshade', | ||
emoji: true | ||
} | ||
}, | ||
{ | ||
type: 'section', | ||
text: { | ||
type: 'mrkdwn', | ||
text: `*${data.title ?? 'No title provided'}*\n${data.description ?? 'No description provided'}` | ||
} | ||
}, | ||
{ | ||
type: 'divider' | ||
}, | ||
{ | ||
type: 'section', | ||
fields: [ | ||
{ | ||
type: 'mrkdwn', | ||
text: `*Event:*\n${data.title}` | ||
}, | ||
{ | ||
type: 'mrkdwn', | ||
text: `*Source:*\n${data.source}` | ||
} | ||
] | ||
}, | ||
{ | ||
type: 'context', | ||
elements: [ | ||
{ | ||
type: 'mrkdwn', | ||
text: '<https://keyshade.xyz|View in Keyshade>' | ||
} | ||
] | ||
} | ||
] | ||
await this.app.client.chat.postMessage({ | ||
channel: metadata.channelId, | ||
blocks: block, | ||
text: data.title | ||
}) | ||
} catch (error) { | ||
this.logger.error(`Failed to emit event to Slack: ${error.message}`) | ||
console.error(error) | ||
throw error | ||
} | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
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
Oops, something went wrong.