41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
import { Command, flags } from '@oclif/command';
|
|
import assert from 'assert';
|
|
import Copycat from '../copycat';
|
|
import { ENTITY_TYPE } from '../types';
|
|
import { parsePath } from '../utils';
|
|
|
|
export default class Replicate extends Command {
|
|
static description = 'Replicate issues/MRs between repositories';
|
|
|
|
static flags = {
|
|
help: flags.help({ char: 'h' }),
|
|
|
|
source: flags.string({ char: 's', required: true }),
|
|
dest: flags.string({ char: 'd', required: true }),
|
|
};
|
|
|
|
static args = [];
|
|
|
|
async run() {
|
|
const { flags } = this.parse(Replicate);
|
|
|
|
const sourcePath = parsePath(flags.source);
|
|
const destPath = parsePath(flags.dest);
|
|
|
|
assert(sourcePath.entity === ENTITY_TYPE.ISSUE, 'Only issues are supported now');
|
|
|
|
const cc = new Copycat();
|
|
await cc.initialize();
|
|
const sourceVendor = cc.vendorManagers.find((v) => v.vendor.domain === sourcePath.domain);
|
|
assert(sourceVendor, 'Source vendor not found in config');
|
|
const destVendor = cc.vendorManagers.find((v) => v.vendor.domain === destPath.domain);
|
|
assert(destVendor, 'Destination vendor not found in config');
|
|
const sourceRepo = await sourceVendor.getRepo(sourcePath.path);
|
|
const destRepo = await destVendor.getRepo(destPath.path);
|
|
const sourceEntity = await sourceRepo.getIssue(sourcePath.entityID);
|
|
sourceEntity.content += `\n\nReplicated from ${sourceEntity.url} with Copycat`;
|
|
const replicatedEntity = await destRepo.replicateIssue(sourceEntity);
|
|
console.log(`Replicated successfully: ${replicatedEntity.url}`);
|
|
}
|
|
}
|