1
0
Fork 0

feat(remote/github): add dry run option

This commit is contained in:
ssube 2020-08-13 19:31:51 -05:00 committed by BZ Libby
parent 0f410203c3
commit 4460c98e9b
10 changed files with 118 additions and 44 deletions

View File

@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [GithubRemote](./cautious-journey.githubremote.md) &gt; [forReal](./cautious-journey.githubremote.forreal.md)
## GithubRemote.forReal property
<b>Signature:</b>
```typescript
protected get forReal(): boolean;
```

View File

@ -23,6 +23,7 @@ export declare class GithubRemote implements Remote
| Property | Modifiers | Type | Description | | Property | Modifiers | Type | Description |
| --- | --- | --- | --- | | --- | --- | --- | --- |
| [forReal](./cautious-journey.githubremote.forreal.md) | | boolean | |
| [options](./cautious-journey.githubremote.options.md) | | [RemoteOptions](./cautious-journey.remoteoptions.md) | | | [options](./cautious-journey.githubremote.options.md) | | [RemoteOptions](./cautious-journey.remoteoptions.md) | |
| [request](./cautious-journey.githubremote.request.md) | | Octokit | | | [request](./cautious-journey.githubremote.request.md) | | Octokit | |

View File

@ -4,6 +4,8 @@
## RemoteOptions.data property ## RemoteOptions.data property
Arbitrary key-value data for this remote, usually credentials and base URLs.
<b>Signature:</b> <b>Signature:</b>
```typescript ```typescript

View File

@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [cautious-journey](./cautious-journey.md) &gt; [RemoteOptions](./cautious-journey.remoteoptions.md) &gt; [dryrun](./cautious-journey.remoteoptions.dryrun.md)
## RemoteOptions.dryrun property
If set, do not make any real changes.
<b>Signature:</b>
```typescript
dryrun: boolean;
```

View File

@ -14,6 +14,7 @@ export interface RemoteOptions
| Property | Type | Description | | Property | Type | Description |
| --- | --- | --- | | --- | --- | --- |
| [data](./cautious-journey.remoteoptions.data.md) | Record&lt;string, string&gt; | | | [data](./cautious-journey.remoteoptions.data.md) | Record&lt;string, string&gt; | Arbitrary key-value data for this remote, usually credentials and base URLs. |
| [type](./cautious-journey.remoteoptions.type.md) | string | | | [dryrun](./cautious-journey.remoteoptions.dryrun.md) | boolean | If set, do not make any real changes. |
| [type](./cautious-journey.remoteoptions.type.md) | string | Remote class/type name. |

View File

@ -4,6 +4,8 @@
## RemoteOptions.type property ## RemoteOptions.type property
Remote class/type name.
<b>Signature:</b> <b>Signature:</b>
```typescript ```typescript

View File

@ -14,6 +14,7 @@ interface Parser<TData> {
export interface ParsedArgs { export interface ParsedArgs {
config: string; config: string;
dryrun: boolean;
remote: string; remote: string;
} }
@ -38,6 +39,12 @@ export function createParser(modeset: Modeback): Parser<ParsedArgs> {
demand: true, demand: true,
type: 'string', type: 'string',
}, },
dryrun: {
alias: ['d'],
default: true,
demand: false,
type: 'boolean',
},
remote: { remote: {
alias: ['r'], alias: ['r'],
demand: true, demand: true,

View File

@ -57,7 +57,10 @@ export async function main(argv: Array<string>): Promise<number> {
}); });
for (const project of config.projects) { for (const project of config.projects) {
const remote = new GithubRemote(project.remote); const remote = new GithubRemote({
...project.remote,
dryrun: args.dryrun,
});
await remote.connect(); await remote.connect();
// mode switch // mode switch

View File

@ -13,6 +13,9 @@ export class GithubRemote implements Remote {
constructor(options: RemoteOptions) { constructor(options: RemoteOptions) {
this.options = options; this.options = options;
/* eslint-disable-next-line */
console.log('options:', options);
} }
public async connect() { public async connect() {
@ -46,13 +49,15 @@ export class GithubRemote implements Remote {
// TODO: check if the label already exists // TODO: check if the label already exists
await mustExist(this.request).issues.createLabel({ if (this.forReal) {
color: options.color, await mustExist(this.request).issues.createLabel({
description: options.desc, color: options.color,
name: options.name, description: options.desc,
owner: path.owner, name: options.name,
repo: path.repo, owner: path.owner,
}); repo: path.repo,
});
}
return options; return options;
} }
@ -62,11 +67,13 @@ export class GithubRemote implements Remote {
// TODO: check if the label is in use // TODO: check if the label is in use
await mustExist(this.request).issues.deleteLabel({ if (this.forReal) {
name: options.name, await mustExist(this.request).issues.deleteLabel({
owner: path.owner, name: options.name,
repo: path.repo, owner: path.owner,
}); repo: path.repo,
});
}
return options; return options;
} }
@ -81,16 +88,19 @@ export class GithubRemote implements Remote {
public async listIssues(options: ProjectQuery): Promise<Array<IssueUpdate>> { public async listIssues(options: ProjectQuery): Promise<Array<IssueUpdate>> {
const path = await this.splitProject(options.project); const path = await this.splitProject(options.project);
const repo = await mustExist(this.request).issues.listForRepo(path);
const issues: Array<IssueUpdate> = []; const issues: Array<IssueUpdate> = [];
for (const issue of repo.data) {
issues.push({ if (this.forReal) {
issue: issue.id.toString(10), const repo = await mustExist(this.request).issues.listForRepo(path);
labels: issue.labels.map((l) => l.name), for (const issue of repo.data) {
name: issue.title, issues.push({
project: options.project, issue: issue.id.toString(10),
}); labels: issue.labels.map((l) => l.name),
name: issue.title,
project: options.project,
});
}
} }
return issues; return issues;
@ -98,16 +108,19 @@ export class GithubRemote implements Remote {
public async listLabels(options: ProjectQuery): Promise<Array<LabelUpdate>> { public async listLabels(options: ProjectQuery): Promise<Array<LabelUpdate>> {
const path = await this.splitProject(options.project); const path = await this.splitProject(options.project);
const repo = await mustExist(this.request).issues.listLabelsForRepo(path);
const labels: Array<LabelUpdate> = []; const labels: Array<LabelUpdate> = [];
for (const label of repo.data) {
labels.push({ if (this.forReal) {
color: label.color, const repo = await mustExist(this.request).issues.listLabelsForRepo(path);
desc: label.description, for (const label of repo.data) {
name: label.name, labels.push({
project: options.project, color: label.color,
}); desc: label.description,
name: label.name,
project: options.project,
});
}
} }
return labels; return labels;
@ -119,19 +132,28 @@ export class GithubRemote implements Remote {
public async updateLabel(options: LabelUpdate): Promise<LabelUpdate> { public async updateLabel(options: LabelUpdate): Promise<LabelUpdate> {
const path = await this.splitProject(options.project); const path = await this.splitProject(options.project);
const data = await mustExist(this.request).issues.updateLabel({
color: options.color,
description: options.desc,
name: options.name,
owner: path.owner,
repo: path.repo,
});
return { if (this.forReal) {
color: data.data.color, const data = await mustExist(this.request).issues.updateLabel({
desc: data.data.description, color: options.color,
name: data.data.name, description: options.desc,
project: options.project, name: options.name,
}; owner: path.owner,
repo: path.repo,
});
return {
color: data.data.color,
desc: data.data.description,
name: data.data.name,
project: options.project,
};
} else {
return options;
}
}
protected get forReal(): boolean {
return !this.options.dryrun;
} }
} }

View File

@ -25,7 +25,19 @@ export interface LabelUpdate extends LabelQuery {
} }
export interface RemoteOptions { export interface RemoteOptions {
/**
* Arbitrary key-value data for this remote, usually credentials and base URLs.
*/
data: Record<string, string>; data: Record<string, string>;
/**
* If set, do not make any real changes.
*/
dryrun: boolean;
/**
* Remote class/type name.
*/
type: string; type: string;
} }