2020-04-26 20:33:39 +00:00
|
|
|
// @flow
|
|
|
|
import type { BaseModel } from './index';
|
|
|
|
|
|
|
|
import * as db from '../common/database';
|
2020-05-15 02:11:06 +00:00
|
|
|
import type { GitCredentials } from '../sync/git/git-vcs';
|
2020-04-26 20:33:39 +00:00
|
|
|
|
|
|
|
type BaseGitRepository = {
|
|
|
|
needsFullClone: boolean,
|
|
|
|
uri: string,
|
2020-05-15 02:11:06 +00:00
|
|
|
credentials: GitCredentials | null,
|
2020-04-26 20:33:39 +00:00
|
|
|
author: {
|
|
|
|
name: string,
|
|
|
|
email: string,
|
|
|
|
},
|
2021-02-09 08:17:47 +00:00
|
|
|
uriNeedsMigration: boolean,
|
2020-04-26 20:33:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export type GitRepository = BaseModel & BaseGitRepository;
|
|
|
|
|
|
|
|
export const name = 'Git Repository';
|
|
|
|
export const type = 'GitRepository';
|
|
|
|
export const prefix = 'git';
|
|
|
|
export const canDuplicate = false;
|
|
|
|
export const canSync = false;
|
|
|
|
|
|
|
|
export function init(): BaseGitRepository {
|
|
|
|
return {
|
|
|
|
needsFullClone: false,
|
|
|
|
uri: '',
|
|
|
|
credentials: null,
|
|
|
|
author: {
|
|
|
|
name: '',
|
|
|
|
email: '',
|
|
|
|
},
|
2021-02-09 08:17:47 +00:00
|
|
|
uriNeedsMigration: true,
|
2020-04-26 20:33:39 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-02-09 08:17:47 +00:00
|
|
|
export function migrate(doc: GitRepository): GitRepository {
|
2020-04-26 20:33:39 +00:00
|
|
|
return doc;
|
|
|
|
}
|
|
|
|
|
2020-05-15 02:11:06 +00:00
|
|
|
export function create(patch: $Shape<GitRepository> = {}): Promise<GitRepository> {
|
2021-02-09 08:17:47 +00:00
|
|
|
return db.docCreate(type, {
|
|
|
|
uriNeedsMigration: false,
|
|
|
|
...patch,
|
|
|
|
});
|
2020-04-26 20:33:39 +00:00
|
|
|
}
|
|
|
|
|
2020-05-15 02:11:06 +00:00
|
|
|
export function update(repo: GitRepository, patch: $Shape<GitRepository>): Promise<GitRepository> {
|
2020-04-26 20:33:39 +00:00
|
|
|
return db.docUpdate(repo, patch);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function remove(repo: GitRepository): Promise<void> {
|
|
|
|
return db.remove(repo);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function all(): Promise<Array<GitRepository>> {
|
|
|
|
return db.all(type);
|
|
|
|
}
|