feat: add initial labels to project
This commit is contained in:
parent
0ea5791a8f
commit
1f3cbac598
|
@ -0,0 +1,11 @@
|
||||||
|
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||||
|
|
||||||
|
[Home](./index.md) > [cautious-journey](./cautious-journey.md) > [ResolveInput](./cautious-journey.resolveinput.md) > [initial](./cautious-journey.resolveinput.initial.md)
|
||||||
|
|
||||||
|
## ResolveInput.initial property
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
initial: Array<string>;
|
||||||
|
```
|
|
@ -17,6 +17,7 @@ export interface ResolveInput
|
||||||
| Property | Type | Description |
|
| Property | Type | Description |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| [flags](./cautious-journey.resolveinput.flags.md) | Array<[FlagLabel](./cautious-journey.flaglabel.md)<!-- -->> | |
|
| [flags](./cautious-journey.resolveinput.flags.md) | Array<[FlagLabel](./cautious-journey.flaglabel.md)<!-- -->> | |
|
||||||
|
| [initial](./cautious-journey.resolveinput.initial.md) | Array<string> | |
|
||||||
| [labels](./cautious-journey.resolveinput.labels.md) | Array<string> | |
|
| [labels](./cautious-journey.resolveinput.labels.md) | Array<string> | |
|
||||||
| [states](./cautious-journey.resolveinput.states.md) | Array<[StateLabel](./cautious-journey.statelabel.md)<!-- -->> | |
|
| [states](./cautious-journey.resolveinput.states.md) | Array<[StateLabel](./cautious-journey.statelabel.md)<!-- -->> | |
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,8 @@ export interface ProjectConfig {
|
||||||
*/
|
*/
|
||||||
flags: Array<FlagLabel>;
|
flags: Array<FlagLabel>;
|
||||||
|
|
||||||
|
initial: Array<string>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Project name or path.
|
* Project name or path.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -121,6 +121,7 @@ definitions:
|
||||||
- colors
|
- colors
|
||||||
- comment
|
- comment
|
||||||
- flags
|
- flags
|
||||||
|
- initial
|
||||||
- name
|
- name
|
||||||
- remote
|
- remote
|
||||||
- states
|
- states
|
||||||
|
@ -138,6 +139,11 @@ definitions:
|
||||||
items:
|
items:
|
||||||
$ref: "#/definitions/flag-label"
|
$ref: "#/definitions/flag-label"
|
||||||
default: []
|
default: []
|
||||||
|
initial:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
default: []
|
||||||
name:
|
name:
|
||||||
type: string
|
type: string
|
||||||
remote:
|
remote:
|
||||||
|
|
|
@ -34,6 +34,9 @@ export abstract class BaseRemote<TClient, TOptions extends RemoteOptions> implem
|
||||||
case ChangeVerb.CREATED:
|
case ChangeVerb.CREATED:
|
||||||
lines.push(`- \`${change.label}\` was created by \`${change.cause}\`.`);
|
lines.push(`- \`${change.label}\` was created by \`${change.cause}\`.`);
|
||||||
break;
|
break;
|
||||||
|
case ChangeVerb.INITIAL:
|
||||||
|
lines.push(`- \`${change.label}\` is an initial label.`);
|
||||||
|
break;
|
||||||
case ChangeVerb.REMOVED:
|
case ChangeVerb.REMOVED:
|
||||||
lines.push(`- \`${change.label}\` was removed by \`${change.cause}\`.`);
|
lines.push(`- \`${change.label}\` was removed by \`${change.cause}\`.`);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -10,6 +10,7 @@ export enum ChangeVerb {
|
||||||
BECAME = 'became',
|
BECAME = 'became',
|
||||||
CONFLICTED = 'conflicted',
|
CONFLICTED = 'conflicted',
|
||||||
CREATED = 'created',
|
CREATED = 'created',
|
||||||
|
INITIAL = 'initial',
|
||||||
REMOVED = 'removed',
|
REMOVED = 'removed',
|
||||||
REQUIRED = 'required',
|
REQUIRED = 'required',
|
||||||
}
|
}
|
||||||
|
@ -44,6 +45,7 @@ export interface ErrorRecord {
|
||||||
*/
|
*/
|
||||||
export interface ResolveInput {
|
export interface ResolveInput {
|
||||||
flags: Array<FlagLabel>;
|
flags: Array<FlagLabel>;
|
||||||
|
initial: Array<string>;
|
||||||
labels: Array<string>;
|
labels: Array<string>;
|
||||||
states: Array<StateLabel>;
|
states: Array<StateLabel>;
|
||||||
}
|
}
|
||||||
|
@ -187,6 +189,18 @@ export function resolveProject(options: ResolveInput): ResolveResult {
|
||||||
errors: [],
|
errors: [],
|
||||||
labels: [],
|
labels: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (options.labels.length === 0) {
|
||||||
|
result.labels.push(...options.initial);
|
||||||
|
|
||||||
|
for (const i of options.initial) {
|
||||||
|
result.changes.push({
|
||||||
|
cause: '',
|
||||||
|
effect: ChangeVerb.INITIAL,
|
||||||
|
label: i,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
const activeLabels = new Set(options.labels);
|
const activeLabels = new Set(options.labels);
|
||||||
|
|
||||||
const sortedFlags = prioritySort(options.flags);
|
const sortedFlags = prioritySort(options.flags);
|
||||||
|
@ -199,7 +213,9 @@ export function resolveProject(options: ResolveInput): ResolveResult {
|
||||||
resolveState(state, result, activeLabels);
|
resolveState(state, result, activeLabels);
|
||||||
}
|
}
|
||||||
|
|
||||||
result.labels = Array.from(activeLabels).sort();
|
result.labels.push(...activeLabels);
|
||||||
|
}
|
||||||
|
|
||||||
|
result.labels.sort();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ export async function syncIssueLabels(options: SyncOptions): Promise<unknown> {
|
||||||
|
|
||||||
const { changes, errors, labels } = resolveProject({
|
const { changes, errors, labels } = resolveProject({
|
||||||
flags: project.flags,
|
flags: project.flags,
|
||||||
|
initial: project.initial,
|
||||||
labels: issue.labels,
|
labels: issue.labels,
|
||||||
states: project.states,
|
states: project.states,
|
||||||
});
|
});
|
||||||
|
|
|
@ -34,6 +34,7 @@ describe('main app', () => {
|
||||||
colors: [],
|
colors: [],
|
||||||
comment: false,
|
comment: false,
|
||||||
flags: [],
|
flags: [],
|
||||||
|
initial: [],
|
||||||
name: '',
|
name: '',
|
||||||
remote: {
|
remote: {
|
||||||
data: {},
|
data: {},
|
||||||
|
@ -68,6 +69,7 @@ describe('main app', () => {
|
||||||
colors: [],
|
colors: [],
|
||||||
comment: false,
|
comment: false,
|
||||||
flags: [],
|
flags: [],
|
||||||
|
initial: [],
|
||||||
name: '',
|
name: '',
|
||||||
remote: {
|
remote: {
|
||||||
data: {},
|
data: {},
|
||||||
|
@ -103,6 +105,7 @@ describe('main app', () => {
|
||||||
colors: [],
|
colors: [],
|
||||||
comment: false,
|
comment: false,
|
||||||
flags: [],
|
flags: [],
|
||||||
|
initial: [],
|
||||||
name: 'bar',
|
name: 'bar',
|
||||||
remote: {
|
remote: {
|
||||||
data: {},
|
data: {},
|
||||||
|
|
|
@ -10,6 +10,7 @@ describe('resolve labels', () => {
|
||||||
it('should return the existing labels', () => {
|
it('should return the existing labels', () => {
|
||||||
const result = resolveProject({
|
const result = resolveProject({
|
||||||
flags: [],
|
flags: [],
|
||||||
|
initial: [],
|
||||||
labels: TEST_LABELS,
|
labels: TEST_LABELS,
|
||||||
states: [],
|
states: [],
|
||||||
});
|
});
|
||||||
|
@ -20,6 +21,7 @@ describe('resolve labels', () => {
|
||||||
it('should not make any changes', () => {
|
it('should not make any changes', () => {
|
||||||
const result = resolveProject({
|
const result = resolveProject({
|
||||||
flags: [],
|
flags: [],
|
||||||
|
initial: [],
|
||||||
labels: TEST_LABELS,
|
labels: TEST_LABELS,
|
||||||
states: [],
|
states: [],
|
||||||
});
|
});
|
||||||
|
@ -28,6 +30,20 @@ describe('resolve labels', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('with empty labels', () => {
|
||||||
|
it('should return initial labels', () => {
|
||||||
|
const initial = ['bar', 'foo'];
|
||||||
|
const result = resolveProject({
|
||||||
|
flags: [],
|
||||||
|
initial,
|
||||||
|
labels: [],
|
||||||
|
states: [],
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.labels).to.deep.equal(initial);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// procedural tests
|
// procedural tests
|
||||||
describe('resolver test cases', () => {
|
describe('resolver test cases', () => {
|
||||||
for (const test of TEST_CASES) {
|
for (const test of TEST_CASES) {
|
||||||
|
|
|
@ -97,7 +97,12 @@ describe('github remote', () => {
|
||||||
|
|
||||||
const remote = await container.create(GithubRemote, REMOTE_OPTIONS);
|
const remote = await container.create(GithubRemote, REMOTE_OPTIONS);
|
||||||
|
|
||||||
for (const effect of [ChangeVerb.CONFLICTED, ChangeVerb.CREATED, ChangeVerb.REMOVED, ChangeVerb.REQUIRED]) {
|
for (const effect of [
|
||||||
|
ChangeVerb.CONFLICTED,
|
||||||
|
ChangeVerb.CREATED,
|
||||||
|
ChangeVerb.REMOVED,
|
||||||
|
ChangeVerb.REQUIRED,
|
||||||
|
]) {
|
||||||
const body = remote.formatBody({
|
const body = remote.formatBody({
|
||||||
changes: [{
|
changes: [{
|
||||||
cause: 'foo',
|
cause: 'foo',
|
||||||
|
@ -112,6 +117,32 @@ describe('github remote', () => {
|
||||||
expect(body).to.include('bar').and.include('foo');
|
expect(body).to.include('bar').and.include('foo');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should include initial labels', async () => {
|
||||||
|
const module = new RemoteModule();
|
||||||
|
const container = Container.from(module);
|
||||||
|
await container.configure();
|
||||||
|
|
||||||
|
const client = new Octokit();
|
||||||
|
stub(client.issues, 'createLabel');
|
||||||
|
module.bind(Octokit).toInstance(client);
|
||||||
|
|
||||||
|
const remote = await container.create(GithubRemote, REMOTE_OPTIONS);
|
||||||
|
|
||||||
|
const body = remote.formatBody({
|
||||||
|
changes: [{
|
||||||
|
cause: 'foo',
|
||||||
|
effect: ChangeVerb.INITIAL,
|
||||||
|
label: 'bar',
|
||||||
|
}],
|
||||||
|
errors: [],
|
||||||
|
issue: '',
|
||||||
|
project: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(body).to.include('bar').and.include('initial');
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('create comment endpoint', () => {
|
describe('create comment endpoint', () => {
|
||||||
|
|
|
@ -2,8 +2,6 @@ import { expect } from 'chai';
|
||||||
|
|
||||||
import { resolveProject } from '../../src/resolve';
|
import { resolveProject } from '../../src/resolve';
|
||||||
|
|
||||||
const TEST_LABELS = ['foo', 'bar'];
|
|
||||||
|
|
||||||
describe('resolve labels', () => {
|
describe('resolve labels', () => {
|
||||||
describe('flags with unfulfilled requires rule', () => {
|
describe('flags with unfulfilled requires rule', () => {
|
||||||
it('should be removed when required label is missing', () => {
|
it('should be removed when required label is missing', () => {
|
||||||
|
@ -17,6 +15,7 @@ describe('resolve labels', () => {
|
||||||
name: 'linda',
|
name: 'linda',
|
||||||
}],
|
}],
|
||||||
}],
|
}],
|
||||||
|
initial: [],
|
||||||
labels: ['gayle'],
|
labels: ['gayle'],
|
||||||
states: [],
|
states: [],
|
||||||
});
|
});
|
||||||
|
@ -37,6 +36,7 @@ describe('resolve labels', () => {
|
||||||
name: 'linda',
|
name: 'linda',
|
||||||
}],
|
}],
|
||||||
}],
|
}],
|
||||||
|
initial: [],
|
||||||
labels: ['gayle', 'linda'],
|
labels: ['gayle', 'linda'],
|
||||||
states: [],
|
states: [],
|
||||||
});
|
});
|
||||||
|
@ -57,6 +57,7 @@ describe('resolve labels', () => {
|
||||||
removes: [],
|
removes: [],
|
||||||
requires: [],
|
requires: [],
|
||||||
}],
|
}],
|
||||||
|
initial: [],
|
||||||
labels: ['bob'],
|
labels: ['bob'],
|
||||||
states: [],
|
states: [],
|
||||||
});
|
});
|
||||||
|
@ -77,6 +78,7 @@ describe('resolve labels', () => {
|
||||||
}],
|
}],
|
||||||
requires: [],
|
requires: [],
|
||||||
}],
|
}],
|
||||||
|
initial: [],
|
||||||
labels: ['bob', 'hugo'],
|
labels: ['bob', 'hugo'],
|
||||||
states: [],
|
states: [],
|
||||||
});
|
});
|
||||||
|
|
|
@ -114,6 +114,7 @@ const DEPENDENT_FLAG: FlagLabel = {
|
||||||
export const TEST_CASES: Array<ResolveTestCase> = [{
|
export const TEST_CASES: Array<ResolveTestCase> = [{
|
||||||
input: {
|
input: {
|
||||||
flags: [],
|
flags: [],
|
||||||
|
initial: [],
|
||||||
labels: [],
|
labels: [],
|
||||||
states: [],
|
states: [],
|
||||||
},
|
},
|
||||||
|
@ -126,6 +127,7 @@ export const TEST_CASES: Array<ResolveTestCase> = [{
|
||||||
}, {
|
}, {
|
||||||
input: {
|
input: {
|
||||||
flags: [SIMPLE_FLAG],
|
flags: [SIMPLE_FLAG],
|
||||||
|
initial: [],
|
||||||
labels: [
|
labels: [
|
||||||
'test',
|
'test',
|
||||||
],
|
],
|
||||||
|
@ -142,6 +144,7 @@ export const TEST_CASES: Array<ResolveTestCase> = [{
|
||||||
}, {
|
}, {
|
||||||
input: {
|
input: {
|
||||||
flags: [],
|
flags: [],
|
||||||
|
initial: [],
|
||||||
labels: ['foo/bar', 'next'],
|
labels: ['foo/bar', 'next'],
|
||||||
states: [TWO_STATE_CYCLE],
|
states: [TWO_STATE_CYCLE],
|
||||||
},
|
},
|
||||||
|
@ -153,6 +156,7 @@ export const TEST_CASES: Array<ResolveTestCase> = [{
|
||||||
}, {
|
}, {
|
||||||
input: {
|
input: {
|
||||||
flags: [],
|
flags: [],
|
||||||
|
initial: [],
|
||||||
labels: ['foo/bar', 'next', 'bob'],
|
labels: ['foo/bar', 'next', 'bob'],
|
||||||
states: [TWO_STATE_CYCLE],
|
states: [TWO_STATE_CYCLE],
|
||||||
},
|
},
|
||||||
|
@ -164,6 +168,7 @@ export const TEST_CASES: Array<ResolveTestCase> = [{
|
||||||
}, {
|
}, {
|
||||||
input: {
|
input: {
|
||||||
flags: [],
|
flags: [],
|
||||||
|
initial: [],
|
||||||
labels: ['foo/bar', 'foo/bin'],
|
labels: ['foo/bar', 'foo/bin'],
|
||||||
states: [TWO_STATE_CYCLE],
|
states: [TWO_STATE_CYCLE],
|
||||||
},
|
},
|
||||||
|
@ -175,6 +180,7 @@ export const TEST_CASES: Array<ResolveTestCase> = [{
|
||||||
}, {
|
}, {
|
||||||
input: {
|
input: {
|
||||||
flags: [],
|
flags: [],
|
||||||
|
initial: [],
|
||||||
labels: ['foo/bar', 'foo/bin'],
|
labels: ['foo/bar', 'foo/bin'],
|
||||||
states: [SECOND_STATE_FALLBACK],
|
states: [SECOND_STATE_FALLBACK],
|
||||||
},
|
},
|
||||||
|
@ -186,6 +192,7 @@ export const TEST_CASES: Array<ResolveTestCase> = [{
|
||||||
}, {
|
}, {
|
||||||
input: {
|
input: {
|
||||||
flags: [],
|
flags: [],
|
||||||
|
initial: [],
|
||||||
labels: ['foo/bar', 'foo/bin', 'bob'],
|
labels: ['foo/bar', 'foo/bin', 'bob'],
|
||||||
states: [SECOND_STATE_FALLBACK],
|
states: [SECOND_STATE_FALLBACK],
|
||||||
},
|
},
|
||||||
|
@ -197,6 +204,7 @@ export const TEST_CASES: Array<ResolveTestCase> = [{
|
||||||
}, {
|
}, {
|
||||||
input: {
|
input: {
|
||||||
flags: [],
|
flags: [],
|
||||||
|
initial: [],
|
||||||
labels: ['foo/bin', 'bob'],
|
labels: ['foo/bin', 'bob'],
|
||||||
states: [SECOND_STATE_FALLBACK],
|
states: [SECOND_STATE_FALLBACK],
|
||||||
},
|
},
|
||||||
|
@ -208,6 +216,7 @@ export const TEST_CASES: Array<ResolveTestCase> = [{
|
||||||
}, {
|
}, {
|
||||||
input: {
|
input: {
|
||||||
flags: [DEPENDENT_FLAG],
|
flags: [DEPENDENT_FLAG],
|
||||||
|
initial: [],
|
||||||
labels: ['test', 'bar'],
|
labels: ['test', 'bar'],
|
||||||
states: [],
|
states: [],
|
||||||
},
|
},
|
||||||
|
@ -219,6 +228,7 @@ export const TEST_CASES: Array<ResolveTestCase> = [{
|
||||||
}, {
|
}, {
|
||||||
input: {
|
input: {
|
||||||
flags: [DEPENDENT_FLAG],
|
flags: [DEPENDENT_FLAG],
|
||||||
|
initial: [],
|
||||||
labels: ['bar'],
|
labels: ['bar'],
|
||||||
states: [],
|
states: [],
|
||||||
},
|
},
|
||||||
|
@ -230,6 +240,7 @@ export const TEST_CASES: Array<ResolveTestCase> = [{
|
||||||
}, {
|
}, {
|
||||||
input: {
|
input: {
|
||||||
flags: [DEPENDENT_FLAG, SIMPLE_FLAG],
|
flags: [DEPENDENT_FLAG, SIMPLE_FLAG],
|
||||||
|
initial: [],
|
||||||
labels: [],
|
labels: [],
|
||||||
states: [TWO_STATE_CYCLE, SECOND_STATE_FALLBACK],
|
states: [TWO_STATE_CYCLE, SECOND_STATE_FALLBACK],
|
||||||
},
|
},
|
||||||
|
|
|
@ -46,6 +46,7 @@ describe('issue sync', () => {
|
||||||
name: 'yep',
|
name: 'yep',
|
||||||
}],
|
}],
|
||||||
}],
|
}],
|
||||||
|
initial: [],
|
||||||
name: 'foo',
|
name: 'foo',
|
||||||
remote: remoteData,
|
remote: remoteData,
|
||||||
states: [],
|
states: [],
|
||||||
|
|
|
@ -66,6 +66,7 @@ describe('project sync', () => {
|
||||||
],
|
],
|
||||||
comment: true,
|
comment: true,
|
||||||
flags: [TEST_FLAG],
|
flags: [TEST_FLAG],
|
||||||
|
initial: [],
|
||||||
name: '',
|
name: '',
|
||||||
remote: remoteConfig,
|
remote: remoteConfig,
|
||||||
states: [],
|
states: [],
|
||||||
|
@ -112,6 +113,7 @@ describe('project sync', () => {
|
||||||
colors: [],
|
colors: [],
|
||||||
comment: true,
|
comment: true,
|
||||||
flags: [TEST_FLAG],
|
flags: [TEST_FLAG],
|
||||||
|
initial: [],
|
||||||
name: '',
|
name: '',
|
||||||
remote: remoteConfig,
|
remote: remoteConfig,
|
||||||
states: [],
|
states: [],
|
||||||
|
@ -148,6 +150,7 @@ describe('project sync', () => {
|
||||||
colors: [],
|
colors: [],
|
||||||
comment: true,
|
comment: true,
|
||||||
flags: [],
|
flags: [],
|
||||||
|
initial: [],
|
||||||
name: '',
|
name: '',
|
||||||
remote: remoteConfig,
|
remote: remoteConfig,
|
||||||
states: [TEST_STATE],
|
states: [TEST_STATE],
|
||||||
|
@ -191,6 +194,7 @@ describe('project sync', () => {
|
||||||
colors: [],
|
colors: [],
|
||||||
comment: true,
|
comment: true,
|
||||||
flags: [],
|
flags: [],
|
||||||
|
initial: [],
|
||||||
name: '',
|
name: '',
|
||||||
remote: remoteConfig,
|
remote: remoteConfig,
|
||||||
states: [],
|
states: [],
|
||||||
|
@ -231,6 +235,7 @@ describe('project sync', () => {
|
||||||
colors: [],
|
colors: [],
|
||||||
comment: false,
|
comment: false,
|
||||||
flags: [],
|
flags: [],
|
||||||
|
initial: [],
|
||||||
name: '',
|
name: '',
|
||||||
remote: {
|
remote: {
|
||||||
data: {},
|
data: {},
|
||||||
|
@ -262,6 +267,7 @@ describe('project sync', () => {
|
||||||
colors: [],
|
colors: [],
|
||||||
comment: false,
|
comment: false,
|
||||||
flags: [],
|
flags: [],
|
||||||
|
initial: [],
|
||||||
name: '',
|
name: '',
|
||||||
remote: {
|
remote: {
|
||||||
data: {},
|
data: {},
|
||||||
|
|
Loading…
Reference in New Issue