forked from github/plane
Compare commits
1 Commits
preview
...
chore/slac
Author | SHA1 | Date | |
---|---|---|---|
|
387d206fac |
@ -1,9 +1,13 @@
|
|||||||
// services
|
// services
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import APIService from "services/api.service";
|
import APIService from "services/api.service";
|
||||||
|
import trackEventServices from "services/track-event.service";
|
||||||
|
|
||||||
const { NEXT_PUBLIC_API_BASE_URL } = process.env;
|
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 {
|
class AppInstallationsService extends APIService {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(NEXT_PUBLIC_API_BASE_URL || "http://localhost:8000");
|
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> {
|
async addInstallationApp(workspaceSlug: string, provider: string, data: any): Promise<any> {
|
||||||
return this.post(`/api/workspaces/${workspaceSlug}/workspace-integrations/${provider}/`, data)
|
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) => {
|
.catch((error) => {
|
||||||
throw error?.response;
|
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(
|
return this.post(
|
||||||
`/api/workspaces/${workspaceSlug}/projects/${projectId}/workspace-integrations/${integrationId}/project-slack-sync/`,
|
`/api/workspaces/${workspaceSlug}/projects/${projectId}/workspace-integrations/${integrationId}/project-slack-sync/`,
|
||||||
data
|
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) => {
|
.catch((error) => {
|
||||||
throw error?.response;
|
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(
|
return this.get(
|
||||||
`/api/workspaces/${workspaceSlug}/projects/${projectId}/workspace-integrations/${integrationId}/project-slack-sync/`
|
`/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(
|
return this.delete(
|
||||||
`/api/workspaces/${workspaceSlug}/projects/${projectId}/workspace-integrations/${integrationId}/project-slack-sync/${slackSyncId}`
|
`/api/workspaces/${workspaceSlug}/projects/${projectId}/workspace-integrations/${integrationId}/project-slack-sync/${slackSyncId}`
|
||||||
)
|
)
|
||||||
|
@ -63,7 +63,18 @@ export type MiscellaneousEventType =
|
|||||||
| "TOGGLE_STATE_ON"
|
| "TOGGLE_STATE_ON"
|
||||||
| "TOGGLE_STATE_OFF";
|
| "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";
|
type GitHubSyncEventType = "GITHUB_REPO_SYNC";
|
||||||
|
|
||||||
@ -84,6 +95,7 @@ type ImporterEventType =
|
|||||||
| "GITHUB_IMPORTER_DELETE"
|
| "GITHUB_IMPORTER_DELETE"
|
||||||
| "JIRA_IMPORTER_CREATE"
|
| "JIRA_IMPORTER_CREATE"
|
||||||
| "JIRA_IMPORTER_DELETE";
|
| "JIRA_IMPORTER_DELETE";
|
||||||
|
|
||||||
class TrackEventServices extends APIService {
|
class TrackEventServices extends APIService {
|
||||||
constructor() {
|
constructor() {
|
||||||
super("/");
|
super("/");
|
||||||
|
Loading…
Reference in New Issue
Block a user