2020-08-13 00:33:53 +00:00
|
|
|
import { FlagLabel, getLabelNames, StateLabel } from './labels';
|
2020-08-12 01:39:53 +00:00
|
|
|
import { Remote } from './remote';
|
|
|
|
|
|
|
|
// TODO: turn this back on/remove the disable pragma
|
|
|
|
/* eslint-disable no-console */
|
|
|
|
|
|
|
|
export interface SyncOptions {
|
2020-08-13 00:33:53 +00:00
|
|
|
flags: Array<FlagLabel>;
|
2020-08-12 01:39:53 +00:00
|
|
|
project: string;
|
|
|
|
remote: Remote;
|
2020-08-13 00:33:53 +00:00
|
|
|
states: Array<StateLabel>;
|
2020-08-12 01:39:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function syncIssues(options: SyncOptions): Promise<unknown> {
|
2020-08-12 23:21:35 +00:00
|
|
|
const issues = await options.remote.listIssues({
|
|
|
|
project: options.project,
|
|
|
|
});
|
2020-08-12 01:39:53 +00:00
|
|
|
|
|
|
|
for (const issue of issues) {
|
2020-08-13 00:24:05 +00:00
|
|
|
console.log('issue:', issue);
|
2020-08-12 01:39:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function syncLabels(options: SyncOptions): Promise<unknown> {
|
2020-08-12 23:21:35 +00:00
|
|
|
const labels = await options.remote.listLabels({
|
|
|
|
project: options.project,
|
|
|
|
});
|
2020-08-12 01:39:53 +00:00
|
|
|
|
2020-08-13 00:24:05 +00:00
|
|
|
const existingLabels = new Set(labels.map((l) => l.name));
|
2020-08-13 00:33:53 +00:00
|
|
|
const expectedLabels = getLabelNames(options.flags, options.states);
|
2020-08-13 00:24:05 +00:00
|
|
|
|
2020-08-12 01:39:53 +00:00
|
|
|
for (const label of labels) {
|
2020-08-13 00:24:05 +00:00
|
|
|
const exists = existingLabels.has(label.name);
|
|
|
|
const expected = expectedLabels.has(label.name);
|
|
|
|
|
|
|
|
if (exists) {
|
|
|
|
if (expected) {
|
|
|
|
console.log('update label:', label);
|
|
|
|
} else {
|
|
|
|
console.log('remove label:', label);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (expected) {
|
|
|
|
console.log('create label:', label);
|
|
|
|
} else {
|
|
|
|
// skip
|
|
|
|
}
|
|
|
|
}
|
2020-08-12 01:39:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
}
|