lint(labels): fix helper names
This commit is contained in:
parent
365a23c85c
commit
838628c126
|
@ -1,4 +1,5 @@
|
|||
import { doesExist, InvalidArgumentError } from '@apextoaster/js-utils';
|
||||
|
||||
import { randomItem } from './utils';
|
||||
|
||||
/**
|
||||
|
@ -84,18 +85,18 @@ export function getLabelNames(flags: Array<FlagLabel>, states: Array<StateLabel>
|
|||
|
||||
for (const state of states) {
|
||||
for (const value of state.values) {
|
||||
labels.push(valueName(state, value));
|
||||
labels.push(getValueName(state, value));
|
||||
}
|
||||
}
|
||||
|
||||
return new Set(labels);
|
||||
}
|
||||
|
||||
export function splitName(name: string): Array<string> {
|
||||
export function splitValueName(name: string): Array<string> {
|
||||
return name.split('/');
|
||||
}
|
||||
|
||||
export function valueName(state: StateLabel, value: StateValue): string {
|
||||
export function getValueName(state: StateLabel, value: StateValue): string {
|
||||
return `${state.name}/${value.name}`;
|
||||
}
|
||||
|
||||
|
@ -104,7 +105,7 @@ export function valueName(state: StateLabel, value: StateValue): string {
|
|||
*
|
||||
* TODO: add some sort options: high-first or low-first, case-sensitivity
|
||||
*/
|
||||
export function prioritizeLabels<TLabel extends BaseLabel>(labels: Array<TLabel>): Array<TLabel> {
|
||||
export function prioritySort<TLabel extends BaseLabel>(labels: Array<TLabel>): Array<TLabel> {
|
||||
return labels.sort((a, b) => {
|
||||
if (a.priority === b.priority) {
|
||||
const aName = a.name.toLocaleLowerCase();
|
||||
|
@ -122,9 +123,9 @@ export function prioritizeLabels<TLabel extends BaseLabel>(labels: Array<TLabel>
|
|||
*
|
||||
* TODO: this is a terrible overload
|
||||
*/
|
||||
export function colorizeLabel(flag: FlagLabel, colors: Array<string>): string;
|
||||
export function colorizeLabel(state: StateLabel, value: StateValue, colors: Array<string>): string;
|
||||
export function colorizeLabel(label: BaseLabel, colorsOrValue: Array<string> | StateValue, maybeColors?: Array<string>): string {
|
||||
export function getLabelColor(flag: FlagLabel, colors: Array<string>): string;
|
||||
export function getLabelColor(state: StateLabel, value: StateValue, colors: Array<string>): string;
|
||||
export function getLabelColor(label: BaseLabel, colorsOrValue: Array<string> | StateValue, maybeColors?: Array<string>): string {
|
||||
if (Array.isArray(colorsOrValue)) {
|
||||
const { color } = label;
|
||||
if (doesExist(color)) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { FlagLabel, prioritizeLabels, StateLabel, valueName } from './labels';
|
||||
import { FlagLabel, getValueName, prioritySort, StateLabel } from './labels';
|
||||
|
||||
/**
|
||||
* How a label changed.
|
||||
|
@ -62,7 +62,7 @@ export function resolveLabels(options: ResolveInput): ResolveResult {
|
|||
const changes: Array<ChangeRecord> = [];
|
||||
const errors: Array<ErrorRecord> = [];
|
||||
|
||||
const sortedFlags = prioritizeLabels(options.flags);
|
||||
const sortedFlags = prioritySort(options.flags);
|
||||
for (const flag of sortedFlags) {
|
||||
const { name } = flag;
|
||||
if (activeLabels.has(name)) {
|
||||
|
@ -71,11 +71,11 @@ export function resolveLabels(options: ResolveInput): ResolveResult {
|
|||
}
|
||||
}
|
||||
|
||||
const sortedStates = prioritizeLabels(options.states);
|
||||
const sortedStates = prioritySort(options.states);
|
||||
for (const state of sortedStates) {
|
||||
const sortedValues = prioritizeLabels(state.values);
|
||||
const sortedValues = prioritySort(state.values);
|
||||
for (const value of sortedValues) {
|
||||
const name = valueName(state, value);
|
||||
const name = getValueName(state, value);
|
||||
if (activeLabels.has(name)) {
|
||||
// TODO: check higher-priority values
|
||||
// TODO: check removes
|
||||
|
|
18
src/sync.ts
18
src/sync.ts
|
@ -1,7 +1,7 @@
|
|||
import { doesExist, mustExist } from '@apextoaster/js-utils';
|
||||
import { Logger } from 'noicejs';
|
||||
|
||||
import { colorizeLabel, FlagLabel, getLabelNames, StateLabel, valueName } from './labels';
|
||||
import { FlagLabel, getLabelColor, getLabelNames, getValueName, StateLabel } from './labels';
|
||||
import { LabelUpdate, Remote } from './remote';
|
||||
import { resolveLabels } from './resolve';
|
||||
import { defaultTo, defaultUntil } from './utils';
|
||||
|
@ -89,7 +89,7 @@ export async function createLabel(options: SyncOptions, name: string) {
|
|||
const flag = options.flags.find((it) => name === it.name);
|
||||
if (doesExist(flag)) {
|
||||
await options.remote.createLabel({
|
||||
color: colorizeLabel(flag, options.colors),
|
||||
color: getLabelColor(flag, options.colors),
|
||||
desc: mustExist(flag.desc),
|
||||
name,
|
||||
project: options.project,
|
||||
|
@ -100,12 +100,12 @@ export async function createLabel(options: SyncOptions, name: string) {
|
|||
|
||||
const state = options.states.find((it) => name.startsWith(it.name));
|
||||
if (doesExist(state)) {
|
||||
const value = state.values.find((it) => valueName(state, it) === name);
|
||||
const value = state.values.find((it) => getValueName(state, it) === name);
|
||||
if (doesExist(value)) {
|
||||
await options.remote.createLabel({
|
||||
color: colorizeLabel(state, value, options.colors),
|
||||
color: getLabelColor(state, value, options.colors),
|
||||
desc: defaultUntil(value.desc, state.desc, ''),
|
||||
name: valueName(state, value),
|
||||
name: getValueName(state, value),
|
||||
project: options.project,
|
||||
});
|
||||
|
||||
|
@ -139,7 +139,7 @@ export async function syncSingleLabel(options: SyncOptions, label: LabelUpdate):
|
|||
const flag = options.flags.find((it) => label.name === it.name);
|
||||
if (doesExist(flag)) {
|
||||
await syncLabelDiff(options, label, {
|
||||
color: colorizeLabel(flag, options.colors),
|
||||
color: getLabelColor(flag, options.colors),
|
||||
desc: defaultTo(flag.desc, label.desc),
|
||||
name: flag.name,
|
||||
project: options.project,
|
||||
|
@ -150,12 +150,12 @@ export async function syncSingleLabel(options: SyncOptions, label: LabelUpdate):
|
|||
|
||||
const state = options.states.find((it) => label.name.startsWith(it.name));
|
||||
if (doesExist(state)) {
|
||||
const value = state.values.find((it) => valueName(state, it) === label.name);
|
||||
const value = state.values.find((it) => getValueName(state, it) === label.name);
|
||||
if (doesExist(value)) {
|
||||
await syncLabelDiff(options, label, {
|
||||
color: colorizeLabel(state, value, options.colors),
|
||||
color: getLabelColor(state, value, options.colors),
|
||||
desc: defaultTo(value.desc, label.desc),
|
||||
name: valueName(state, value),
|
||||
name: getValueName(state, value),
|
||||
project: options.project,
|
||||
});
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { expect } from 'chai';
|
||||
|
||||
import { getLabelNames, prioritizeLabels } from '../src/labels';
|
||||
import { getLabelNames, prioritySort } from '../src/labels';
|
||||
|
||||
describe('label helpers', () => {
|
||||
describe('label name helper', () => {
|
||||
|
@ -72,7 +72,7 @@ describe('label helpers', () => {
|
|||
requires: [],
|
||||
};
|
||||
|
||||
const sorted = prioritizeLabels([LOW_LABEL, HIGH_LABEL]);
|
||||
const sorted = prioritySort([LOW_LABEL, HIGH_LABEL]);
|
||||
expect(sorted[0]).to.deep.equal(HIGH_LABEL);
|
||||
});
|
||||
|
||||
|
@ -88,7 +88,7 @@ describe('label helpers', () => {
|
|||
requires: [],
|
||||
};
|
||||
|
||||
const sorted = prioritizeLabels([SECOND_LABEL, FIRST_LABEL]);
|
||||
const sorted = prioritySort([SECOND_LABEL, FIRST_LABEL]);
|
||||
expect(sorted[0]).to.deep.equal(FIRST_LABEL);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue