Update scripts

This commit is contained in:
freearhey 2023-10-16 14:45:12 +03:00
parent e2a5105e69
commit 4d5c6fee64
7 changed files with 140 additions and 104 deletions

View file

@ -3,3 +3,5 @@ export * from './issueParser'
export * from './issueLoader'
export * from './csvParser'
export * from './idCreator'
export * from './issueData'
export * from './issue'

19
scripts/core/issue.ts Normal file
View file

@ -0,0 +1,19 @@
import { IssueData } from './'
type IssueProps = {
number: number
labels: string[]
data: IssueData
}
export class Issue {
number: number
labels: string[]
data: IssueData
constructor({ number, labels, data }: IssueProps) {
this.number = number
this.labels = labels
this.data = data
}
}

40
scripts/core/issueData.ts Normal file
View file

@ -0,0 +1,40 @@
import { Dictionary } from '@freearhey/core'
export class IssueData {
_data: Dictionary
constructor(data: Dictionary) {
this._data = data
}
has(key: string): boolean {
return this._data.has(key)
}
missing(key: string): boolean {
return this._data.missing(key) || this._data.get(key) === undefined
}
getBoolean(key: string): boolean | undefined {
return this.missing(key) ? undefined : this._data.get(key)
}
getString(key: string): string | undefined {
const deleteSymbol = '~'
return this.missing(key)
? undefined
: this._data.get(key) === deleteSymbol
? ''
: this._data.get(key)
}
getArray(key: string): string[] | undefined {
const deleteSymbol = '~'
return this.missing(key)
? undefined
: this._data.get(key) === deleteSymbol
? []
: this._data.get(key).split(';')
}
}

View file

@ -1,5 +1,5 @@
import { Dictionary } from '@freearhey/core'
import { Issue } from '../models'
import { IssueData, Issue } from '../core'
const FIELDS = new Dictionary({
'Channel ID': 'channel_id',
@ -52,7 +52,8 @@ export class IssueParser {
if (!_label || !_value) return data
const id: string = FIELDS.get(_label)
const value: string = _value === '_No response_' || _value === 'None' ? '' : _value
const value: string | undefined =
_value === '_No response_' || _value === 'None' ? undefined : _value
if (!id) return
@ -61,6 +62,6 @@ export class IssueParser {
const labels = issue.labels.map(label => label.name)
return new Issue({ number: issue.number, labels, data })
return new Issue({ number: issue.number, labels, data: new IssueData(data) })
}
}