forked from github/plane
chore: slack integrations
This commit is contained in:
parent
bf865f399f
commit
387d206fac
@ -1,9 +1,13 @@
|
||||
// services
|
||||
import axios from "axios";
|
||||
import APIService from "services/api.service";
|
||||
import trackEventServices from "services/track-event.service";
|
||||
|
||||
const { NEXT_PUBLIC_API_BASE_URL } = process.env;
|
||||
|
||||
const trackEvent =
|
||||
process.env.NEXT_PUBLIC_TRACK_EVENTS === "true" || process.env.NEXT_PUBLIC_TRACK_EVENTS === "1";
|
||||
|
||||
class AppInstallationsService extends APIService {
|
||||
constructor() {
|
||||
super(NEXT_PUBLIC_API_BASE_URL || "http://localhost:8000");
|
||||
@ -11,24 +15,67 @@ class AppInstallationsService extends APIService {
|
||||
|
||||
async addInstallationApp(workspaceSlug: string, provider: string, data: any): Promise<any> {
|
||||
return this.post(`/api/workspaces/${workspaceSlug}/workspace-integrations/${provider}/`, data)
|
||||
.then((response) => response?.data)
|
||||
.then((response) => {
|
||||
if (!trackEvent) return response?.data;
|
||||
|
||||
const eventType =
|
||||
provider === "slack"
|
||||
? "SLACK_INTEGRATION_CREATE"
|
||||
: provider === "github"
|
||||
? "GITHUB_INTEGRATION_CREATE"
|
||||
: null;
|
||||
|
||||
if (!eventType) return response?.data;
|
||||
|
||||
trackEventServices.trackAppIntegrationEvent(
|
||||
{
|
||||
workspaceSlug,
|
||||
provider,
|
||||
},
|
||||
eventType
|
||||
);
|
||||
|
||||
return response?.data;
|
||||
})
|
||||
.catch((error) => {
|
||||
throw error?.response;
|
||||
});
|
||||
}
|
||||
|
||||
async addSlackChannel(workspaceSlug: string, projectId: string, integrationId: string | null | undefined, data: any): Promise<any> {
|
||||
async addSlackChannel(
|
||||
workspaceSlug: string,
|
||||
projectId: string,
|
||||
integrationId: string | null | undefined,
|
||||
data: any
|
||||
): Promise<any> {
|
||||
return this.post(
|
||||
`/api/workspaces/${workspaceSlug}/projects/${projectId}/workspace-integrations/${integrationId}/project-slack-sync/`,
|
||||
data
|
||||
)
|
||||
.then((response) => response?.data)
|
||||
.then((response) => {
|
||||
if (!trackEvent) return response?.data;
|
||||
|
||||
trackEventServices.trackAppIntegrationEvent(
|
||||
{
|
||||
workspaceSlug,
|
||||
projectId,
|
||||
integrationId,
|
||||
},
|
||||
"SLACK_ADD_CHANNEL"
|
||||
);
|
||||
|
||||
return response?.data;
|
||||
})
|
||||
.catch((error) => {
|
||||
throw error?.response;
|
||||
});
|
||||
}
|
||||
|
||||
async getSlackChannelDetail(workspaceSlug: string, projectId: string, integrationId: string | null | undefined): Promise<any> {
|
||||
async getSlackChannelDetail(
|
||||
workspaceSlug: string,
|
||||
projectId: string,
|
||||
integrationId: string | null | undefined
|
||||
): Promise<any> {
|
||||
return this.get(
|
||||
`/api/workspaces/${workspaceSlug}/projects/${projectId}/workspace-integrations/${integrationId}/project-slack-sync/`
|
||||
)
|
||||
@ -38,7 +85,12 @@ class AppInstallationsService extends APIService {
|
||||
});
|
||||
}
|
||||
|
||||
async removeSlackChannel(workspaceSlug: string, projectId: string, integrationId: string | null | undefined, slackSyncId: string | undefined): Promise<any> {
|
||||
async removeSlackChannel(
|
||||
workspaceSlug: string,
|
||||
projectId: string,
|
||||
integrationId: string | null | undefined,
|
||||
slackSyncId: string | undefined
|
||||
): Promise<any> {
|
||||
return this.delete(
|
||||
`/api/workspaces/${workspaceSlug}/projects/${projectId}/workspace-integrations/${integrationId}/project-slack-sync/${slackSyncId}`
|
||||
)
|
||||
|
@ -63,7 +63,18 @@ export type MiscellaneousEventType =
|
||||
| "TOGGLE_STATE_ON"
|
||||
| "TOGGLE_STATE_OFF";
|
||||
|
||||
type IntegrationEventType = "ADD_WORKSPACE_INTEGRATION" | "REMOVE_WORKSPACE_INTEGRATION";
|
||||
type TProviders = "SLACK" | "GITHUB";
|
||||
|
||||
type TProviderEvents = "INTEGRATION_CREATE" | "INTEGRATION_DELETE";
|
||||
|
||||
type TFinalIntegrationEvents = `${TProviders}_${TProviderEvents}`;
|
||||
|
||||
type IntegrationEventType =
|
||||
| "ADD_WORKSPACE_INTEGRATION"
|
||||
| "REMOVE_WORKSPACE_INTEGRATION"
|
||||
| TFinalIntegrationEvents
|
||||
| "SLACK_ADD_CHANNEL"
|
||||
| "GITHUB_ADD_REPO";
|
||||
|
||||
type GitHubSyncEventType = "GITHUB_REPO_SYNC";
|
||||
|
||||
@ -84,6 +95,7 @@ type ImporterEventType =
|
||||
| "GITHUB_IMPORTER_DELETE"
|
||||
| "JIRA_IMPORTER_CREATE"
|
||||
| "JIRA_IMPORTER_DELETE";
|
||||
|
||||
class TrackEventServices extends APIService {
|
||||
constructor() {
|
||||
super("/");
|
||||
|
Loading…
Reference in New Issue
Block a user