You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
695 B

  1. import {spawn} from './utils/process';
  2. import {mkdirp} from './utils/fs';
  3. export enum RepoVisibility {
  4. PRIVATE,
  5. INTERNAL,
  6. PUBLIC,
  7. }
  8. export enum OwnerType {
  9. USER,
  10. ORG,
  11. }
  12. type Owner = {
  13. name: string,
  14. type: OwnerType,
  15. }
  16. type CreateOptions = {
  17. name: string,
  18. owner: Owner,
  19. visibility: RepoVisibility,
  20. }
  21. const OWNER_TYPE_DIR_NAMES: Record<OwnerType, string> = {
  22. [OwnerType.USER]: 'users',
  23. [OwnerType.ORG]: 'orgs',
  24. }
  25. export const create = async (options: CreateOptions) => {
  26. const repoBasePath = `${OWNER_TYPE_DIR_NAMES[options.owner.type]}/${options.owner.name}/${options.name}`;
  27. await mkdirp(repoBasePath);
  28. return spawn(repoBasePath, 'git', ['init', '--bare']);
  29. }