-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the ability to update labels based on configuration
- Loading branch information
1 parent
5779fcb
commit 46b60af
Showing
8 changed files
with
273 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import * as fs from 'fs'; | ||
import * as fse from 'fs-extra'; | ||
import * as jsYaml from 'js-yaml'; | ||
import * as path from 'path'; | ||
|
||
import defaultLabelsConfig from './defaultLabelsConfig'; | ||
import LabelsConfig from './labelsConfig.type'; | ||
|
||
const checkConfig = async (config: any, log: any) => { | ||
const labelsConfig: LabelsConfig = defaultLabelsConfig; | ||
|
||
// Ensure index exists in Elasticsearch | ||
// If config file does not exists, initialize it: | ||
fse.ensureDirSync(config.configDir); | ||
|
||
if (!fs.existsSync(path.join(config.configDir, 'labels-config.yml'))) { | ||
fs.writeFileSync( | ||
path.join(config.configDir, 'labels-config.yml'), | ||
jsYaml.safeDump(labelsConfig), | ||
); | ||
log( | ||
'Initialized configuration file with defaults in: ' + | ||
path.join(config.configDir, 'labels-config.yml'), | ||
); | ||
log('Please EDIT the configuration file first'); | ||
} else { | ||
log( | ||
'Configuration file exists: ' + | ||
path.join(config.configDir, 'labels-config.yml'), | ||
); | ||
} | ||
}; | ||
|
||
export default checkConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const defaultImportConfig = { | ||
labels: [{ | ||
name: 'A Label', | ||
description: 'Description for my label', | ||
color: '#0e8a16', | ||
exactMatch: true, | ||
}, { | ||
name: 'Another Label', | ||
description: 'Description for my other label', | ||
color: '#A0315F', | ||
exactMatch: false, | ||
}], | ||
}; | ||
|
||
export default defaultImportConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import cli from 'cli-ux'; | ||
import { Client } from '@elastic/elasticsearch'; | ||
|
||
const fetchAllLabels = async (esClient: Client, esIndex: string) => { | ||
let labels: any[] = []; | ||
|
||
const scrollSearch = esClient.helpers.scrollSearch({ | ||
index: esIndex, | ||
body: { | ||
query: { | ||
// eslint-disable-next-line @typescript-eslint/camelcase | ||
match_all: {}, | ||
}, | ||
}, | ||
}); | ||
cli.action.start('Fetching all labels from: ' + esIndex); | ||
|
||
for await (const result of scrollSearch) { | ||
labels = [...labels, ...result.documents]; | ||
} | ||
cli.action.stop('done (' + labels.length + ' labels fetched)'); | ||
|
||
return labels; | ||
}; | ||
export default fetchAllLabels; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export interface Label { | ||
name: string; | ||
description: string; | ||
color: string; | ||
exactMatch: boolean; | ||
} | ||
|
||
export interface LabelsConfig { | ||
labels: Label[]; | ||
} | ||
|
||
export default LabelsConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import gql from 'graphql-tag'; | ||
|
||
const GQL_QUERY = gql` | ||
mutation($labelId: ID!, $color: String!, $description: String) { | ||
updateLabel(input: { id: $labelId, color: $color, description: $description }) { | ||
label { | ||
id | ||
} | ||
} | ||
} | ||
`; | ||
|
||
export default GQL_QUERY; |