2021-04-05 15:50:55 +00:00
|
|
|
import * as models from '../../models';
|
|
|
|
import type { GitRepository } from '../../models/git-repository';
|
|
|
|
|
2021-05-12 06:35:00 +00:00
|
|
|
export const createGitRepository = async (workspaceId: string, repo: Partial<GitRepository>) => {
|
2021-04-05 15:50:55 +00:00
|
|
|
const newRepo = await models.gitRepository.create(repo);
|
|
|
|
const meta = await models.workspaceMeta.getOrCreateByParentId(workspaceId);
|
2021-05-12 06:35:00 +00:00
|
|
|
await models.workspaceMeta.update(meta, {
|
|
|
|
gitRepositoryId: newRepo._id,
|
|
|
|
});
|
2021-04-05 15:50:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const deleteGitRepository = async (repo: GitRepository) => {
|
|
|
|
const id = repo._id;
|
|
|
|
const workspaceMeta = await models.workspaceMeta.getByGitRepositoryId(id);
|
|
|
|
|
|
|
|
if (workspaceMeta) {
|
|
|
|
await models.workspaceMeta.update(workspaceMeta, {
|
|
|
|
gitRepositoryId: null,
|
|
|
|
cachedGitLastCommitTime: null,
|
|
|
|
cachedGitRepositoryBranch: null,
|
|
|
|
cachedGitLastAuthor: null,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
await models.gitRepository.remove(repo);
|
|
|
|
};
|