2023-03-23 17:57:11 +00:00
|
|
|
import APIService from "services/api.service";
|
2023-05-05 10:15:38 +00:00
|
|
|
import trackEventServices from "services/track-event.service";
|
|
|
|
|
2023-04-05 19:21:15 +00:00
|
|
|
import { IGithubRepoInfo, IGithubServiceImportFormData } from "types";
|
2023-03-23 17:57:11 +00:00
|
|
|
|
|
|
|
const { NEXT_PUBLIC_API_BASE_URL } = process.env;
|
|
|
|
|
2023-05-05 10:15:38 +00:00
|
|
|
const trackEvent =
|
|
|
|
process.env.NEXT_PUBLIC_TRACK_EVENTS === "true" || process.env.NEXT_PUBLIC_TRACK_EVENTS === "1";
|
2023-03-23 17:57:11 +00:00
|
|
|
|
2023-05-05 10:15:38 +00:00
|
|
|
const integrationServiceType: string = "github";
|
2023-03-23 17:57:11 +00:00
|
|
|
class GithubIntegrationService extends APIService {
|
|
|
|
constructor() {
|
|
|
|
super(NEXT_PUBLIC_API_BASE_URL || "http://localhost:8000");
|
|
|
|
}
|
|
|
|
|
|
|
|
async listAllRepositories(workspaceSlug: string, integrationSlug: string): Promise<any> {
|
|
|
|
return this.get(
|
|
|
|
`/api/workspaces/${workspaceSlug}/workspace-integrations/${integrationSlug}/github-repositories`
|
|
|
|
)
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-04-05 19:21:15 +00:00
|
|
|
async getGithubRepoInfo(
|
|
|
|
workspaceSlug: string,
|
|
|
|
params: { owner: string; repo: string }
|
|
|
|
): Promise<IGithubRepoInfo> {
|
|
|
|
return this.get(`/api/workspaces/${workspaceSlug}/importers/${integrationServiceType}/`, {
|
|
|
|
params,
|
|
|
|
})
|
2023-03-23 17:57:11 +00:00
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-04-05 19:21:15 +00:00
|
|
|
async createGithubServiceImport(
|
2023-03-23 17:57:11 +00:00
|
|
|
workspaceSlug: string,
|
2023-04-05 19:21:15 +00:00
|
|
|
data: IGithubServiceImportFormData
|
2023-03-23 17:57:11 +00:00
|
|
|
): Promise<any> {
|
2023-04-05 19:21:15 +00:00
|
|
|
return this.post(
|
|
|
|
`/api/workspaces/${workspaceSlug}/projects/importers/${integrationServiceType}/`,
|
|
|
|
data
|
|
|
|
)
|
2023-05-05 10:15:38 +00:00
|
|
|
.then((response) => {
|
|
|
|
if (trackEvent)
|
|
|
|
trackEventServices.trackImporterEvent(response?.data, "GITHUB_IMPORTER_CREATE");
|
|
|
|
return response?.data;
|
|
|
|
})
|
2023-03-23 17:57:11 +00:00
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default new GithubIntegrationService();
|