2023-03-23 17:57:11 +00:00
|
|
|
import APIService from "services/api.service";
|
2023-09-20 15:03:25 +00:00
|
|
|
import trackEventServices from "services/track_event.service";
|
2023-09-13 14:51:02 +00:00
|
|
|
import { API_BASE_URL } from "helpers/common.helper";
|
2023-06-06 16:06:00 +00:00
|
|
|
import { ICurrentUserResponse, IGithubRepoInfo, IGithubServiceImportFormData } from "types";
|
2023-03-23 17:57:11 +00:00
|
|
|
|
2023-05-05 10:15:38 +00:00
|
|
|
const integrationServiceType: string = "github";
|
2023-09-20 15:03:25 +00:00
|
|
|
|
|
|
|
export class GithubIntegrationService extends APIService {
|
2023-03-23 17:57:11 +00:00
|
|
|
constructor() {
|
2023-09-13 14:51:02 +00:00
|
|
|
super(API_BASE_URL);
|
2023-03-23 17:57:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async listAllRepositories(workspaceSlug: string, integrationSlug: string): Promise<any> {
|
2023-09-20 15:03:25 +00:00
|
|
|
return this.get(`/api/workspaces/${workspaceSlug}/workspace-integrations/${integrationSlug}/github-repositories`)
|
2023-03-23 17:57:11 +00:00
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-09-20 15:03:25 +00:00
|
|
|
async getGithubRepoInfo(workspaceSlug: string, params: { owner: string; repo: string }): Promise<IGithubRepoInfo> {
|
2023-04-05 19:21:15 +00:00
|
|
|
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-06-06 16:06:00 +00:00
|
|
|
data: IGithubServiceImportFormData,
|
|
|
|
user: ICurrentUserResponse | undefined
|
2023-03-23 17:57:11 +00:00
|
|
|
): Promise<any> {
|
2023-09-20 15:03:25 +00:00
|
|
|
return this.post(`/api/workspaces/${workspaceSlug}/projects/importers/${integrationServiceType}/`, data)
|
2023-05-05 10:15:38 +00:00
|
|
|
.then((response) => {
|
2023-09-14 10:35:31 +00:00
|
|
|
trackEventServices.trackImporterEvent(response?.data, "GITHUB_IMPORTER_CREATE", user);
|
2023-05-05 10:15:38 +00:00
|
|
|
return response?.data;
|
|
|
|
})
|
2023-03-23 17:57:11 +00:00
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default new GithubIntegrationService();
|