Skip to content

Commit

Permalink
feat(sync): basic label sync logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Aug 13, 2020
1 parent fa81e86 commit 28c9ee8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
20 changes: 16 additions & 4 deletions src/labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ export interface BaseLabel {
* Display color.
*/
color?: string;

/**
*
*/
desc?: string;
priority: number;
requires: Array<unknown>;
Expand Down Expand Up @@ -71,3 +67,19 @@ export interface StateLabel extends BaseLabel, LabelSet {
*/
values: Array<StateValue>;
}

export function getLabelNames(flags: Array<FlagLabel>, states: Array<StateLabel>): Set<string> {
const labels = [];

for (const flag of flags) {
labels.push(flag.name);
}

for (const state of states) {
for (const value of state.values) {
labels.push(`${state.name}/${value.name}`);
}
}

return new Set(labels);
}
23 changes: 21 additions & 2 deletions src/sync.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ConfigData } from './config';
import { getLabelNames } from './labels';
import { Remote } from './remote';

// TODO: turn this back on/remove the disable pragma
Expand All @@ -16,7 +17,7 @@ export async function syncIssues(options: SyncOptions): Promise<unknown> {
});

for (const issue of issues) {
console.log('issue:', issue.name, issue.labels);
console.log('issue:', issue);
}

return undefined;
Expand All @@ -27,8 +28,26 @@ export async function syncLabels(options: SyncOptions): Promise<unknown> {
project: options.project,
});

const existingLabels = new Set(labels.map((l) => l.name));
const expectedLabels = getLabelNames(options.config.projects[0].flags, options.config.projects[0].states);

for (const label of labels) {
console.log('label:', label.name);
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
}
}
}

return undefined;
Expand Down

0 comments on commit 28c9ee8

Please sign in to comment.