draft-redmine_users_from_csv/mod.ts

35 lines
893 B
TypeScript
Raw Normal View History

2024-01-15 21:05:44 +01:00
import { Redmine } from 'bluemine'
import * as CSV from 'std:csv'
import { CsvEntry } from './type.ts'
2024-01-15 22:54:55 +01:00
import { createUsers } from './src/create_users.ts'
import { appendToGroup } from './src/append_to_group.ts'
if (import.meta.main) {
2024-01-15 21:05:44 +01:00
const endpoint = Deno.env.get('ENDPOINT')
const apiKey = Deno.env.get('API_KEY')
2024-01-15 21:05:44 +01:00
if (apiKey === undefined) {
throw new Error(
'Redmine REST API key is missing, please define API_KEY',
)
}
if (endpoint === undefined) {
throw new Error(
'Redmine REST endpoint is missing, please define ENDPOINT',
)
}
2024-01-15 21:05:44 +01:00
const redmine = new Redmine({ endpoint, apiKey })
2024-01-15 21:05:44 +01:00
const file = await Deno.readTextFile(
2024-01-15 22:54:55 +01:00
prompt('Full path of the CSV file ?: ') ?? '',
2024-01-15 21:05:44 +01:00
)
2024-01-15 21:05:44 +01:00
const csv = CSV.parse(file.replaceAll(';', ','), {
skipFirstRow: true,
}) as CsvEntry[]
2024-01-15 22:54:55 +01:00
createUsers(redmine, csv)
appendToGroup(redmine, csv, prompt('Enter a group name ?: ') ?? '')
2024-01-15 21:05:44 +01:00
}