feat(remote/github): add dry run option
This commit is contained in:
parent
0f410203c3
commit
4460c98e9b
|
@ -0,0 +1,11 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [GithubRemote](./cautious-journey.githubremote.md) > [forReal](./cautious-journey.githubremote.forreal.md)
|
||||
|
||||
## GithubRemote.forReal property
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
protected get forReal(): boolean;
|
||||
```
|
|
@ -23,6 +23,7 @@ export declare class GithubRemote implements Remote
|
|||
|
||||
| Property | Modifiers | Type | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [forReal](./cautious-journey.githubremote.forreal.md) | | boolean | |
|
||||
| [options](./cautious-journey.githubremote.options.md) | | [RemoteOptions](./cautious-journey.remoteoptions.md) | |
|
||||
| [request](./cautious-journey.githubremote.request.md) | | Octokit | |
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
## RemoteOptions.data property
|
||||
|
||||
Arbitrary key-value data for this remote, usually credentials and base URLs.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [RemoteOptions](./cautious-journey.remoteoptions.md) > [dryrun](./cautious-journey.remoteoptions.dryrun.md)
|
||||
|
||||
## RemoteOptions.dryrun property
|
||||
|
||||
If set, do not make any real changes.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
dryrun: boolean;
|
||||
```
|
|
@ -14,6 +14,7 @@ export interface RemoteOptions
|
|||
|
||||
| Property | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [data](./cautious-journey.remoteoptions.data.md) | Record<string, string> | |
|
||||
| [type](./cautious-journey.remoteoptions.type.md) | string | |
|
||||
| [data](./cautious-journey.remoteoptions.data.md) | Record<string, string> | Arbitrary key-value data for this remote, usually credentials and base URLs. |
|
||||
| [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. |
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
## RemoteOptions.type property
|
||||
|
||||
Remote class/type name.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
|
|
|
@ -14,6 +14,7 @@ interface Parser<TData> {
|
|||
|
||||
export interface ParsedArgs {
|
||||
config: string;
|
||||
dryrun: boolean;
|
||||
remote: string;
|
||||
}
|
||||
|
||||
|
@ -38,6 +39,12 @@ export function createParser(modeset: Modeback): Parser<ParsedArgs> {
|
|||
demand: true,
|
||||
type: 'string',
|
||||
},
|
||||
dryrun: {
|
||||
alias: ['d'],
|
||||
default: true,
|
||||
demand: false,
|
||||
type: 'boolean',
|
||||
},
|
||||
remote: {
|
||||
alias: ['r'],
|
||||
demand: true,
|
||||
|
|
|
@ -57,7 +57,10 @@ export async function main(argv: Array<string>): Promise<number> {
|
|||
});
|
||||
|
||||
for (const project of config.projects) {
|
||||
const remote = new GithubRemote(project.remote);
|
||||
const remote = new GithubRemote({
|
||||
...project.remote,
|
||||
dryrun: args.dryrun,
|
||||
});
|
||||
await remote.connect();
|
||||
|
||||
// mode switch
|
||||
|
|
|
@ -13,6 +13,9 @@ export class GithubRemote implements Remote {
|
|||
|
||||
constructor(options: RemoteOptions) {
|
||||
this.options = options;
|
||||
|
||||
/* eslint-disable-next-line */
|
||||
console.log('options:', options);
|
||||
}
|
||||
|
||||
public async connect() {
|
||||
|
@ -46,6 +49,7 @@ export class GithubRemote implements Remote {
|
|||
|
||||
// TODO: check if the label already exists
|
||||
|
||||
if (this.forReal) {
|
||||
await mustExist(this.request).issues.createLabel({
|
||||
color: options.color,
|
||||
description: options.desc,
|
||||
|
@ -53,6 +57,7 @@ export class GithubRemote implements Remote {
|
|||
owner: path.owner,
|
||||
repo: path.repo,
|
||||
});
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
@ -62,11 +67,13 @@ export class GithubRemote implements Remote {
|
|||
|
||||
// TODO: check if the label is in use
|
||||
|
||||
if (this.forReal) {
|
||||
await mustExist(this.request).issues.deleteLabel({
|
||||
name: options.name,
|
||||
owner: path.owner,
|
||||
repo: path.repo,
|
||||
});
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
@ -81,9 +88,11 @@ export class GithubRemote implements Remote {
|
|||
|
||||
public async listIssues(options: ProjectQuery): Promise<Array<IssueUpdate>> {
|
||||
const path = await this.splitProject(options.project);
|
||||
const repo = await mustExist(this.request).issues.listForRepo(path);
|
||||
|
||||
const issues: Array<IssueUpdate> = [];
|
||||
|
||||
if (this.forReal) {
|
||||
const repo = await mustExist(this.request).issues.listForRepo(path);
|
||||
for (const issue of repo.data) {
|
||||
issues.push({
|
||||
issue: issue.id.toString(10),
|
||||
|
@ -92,15 +101,18 @@ export class GithubRemote implements Remote {
|
|||
project: options.project,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return issues;
|
||||
}
|
||||
|
||||
public async listLabels(options: ProjectQuery): Promise<Array<LabelUpdate>> {
|
||||
const path = await this.splitProject(options.project);
|
||||
const repo = await mustExist(this.request).issues.listLabelsForRepo(path);
|
||||
|
||||
const labels: Array<LabelUpdate> = [];
|
||||
|
||||
if (this.forReal) {
|
||||
const repo = await mustExist(this.request).issues.listLabelsForRepo(path);
|
||||
for (const label of repo.data) {
|
||||
labels.push({
|
||||
color: label.color,
|
||||
|
@ -109,6 +121,7 @@ export class GithubRemote implements Remote {
|
|||
project: options.project,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return labels;
|
||||
}
|
||||
|
@ -119,6 +132,8 @@ export class GithubRemote implements Remote {
|
|||
|
||||
public async updateLabel(options: LabelUpdate): Promise<LabelUpdate> {
|
||||
const path = await this.splitProject(options.project);
|
||||
|
||||
if (this.forReal) {
|
||||
const data = await mustExist(this.request).issues.updateLabel({
|
||||
color: options.color,
|
||||
description: options.desc,
|
||||
|
@ -133,5 +148,12 @@ export class GithubRemote implements Remote {
|
|||
name: data.data.name,
|
||||
project: options.project,
|
||||
};
|
||||
} else {
|
||||
return options;
|
||||
}
|
||||
}
|
||||
|
||||
protected get forReal(): boolean {
|
||||
return !this.options.dryrun;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,19 @@ export interface LabelUpdate extends LabelQuery {
|
|||
}
|
||||
|
||||
export interface RemoteOptions {
|
||||
/**
|
||||
* Arbitrary key-value data for this remote, usually credentials and base URLs.
|
||||
*/
|
||||
data: Record<string, string>;
|
||||
|
||||
/**
|
||||
* If set, do not make any real changes.
|
||||
*/
|
||||
dryrun: boolean;
|
||||
|
||||
/**
|
||||
* Remote class/type name.
|
||||
*/
|
||||
type: string;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue