From 2555d5f6c7085e74f01ffca7337a47fb5b67ec1d Mon Sep 17 00:00:00 2001 From: Julien Oculi Date: Mon, 15 Jan 2024 21:05:13 +0100 Subject: [PATCH] feat: allow user to specify csv file to use --- mod.ts | 6 +++--- src/append_to_group.ts | 7 +------ src/create_users.ts | 7 +------ type.ts | 5 +++++ 4 files changed, 10 insertions(+), 15 deletions(-) create mode 100644 type.ts diff --git a/mod.ts b/mod.ts index 7d7c4e6..debb314 100644 --- a/mod.ts +++ b/mod.ts @@ -1,5 +1,6 @@ import { Redmine } from 'bluemine'; import * as CSV from 'std:csv'; +import { CsvEntry } from './type.ts'; if (import.meta.main) { const endpoint = Deno.env.get('ENDPOINT') @@ -10,9 +11,8 @@ if (import.meta.main) { const redmine = new Redmine({ endpoint, apiKey }); - const file = await Deno.readTextFile( - 'path', - ); + const file = await Deno.readTextFile(prompt('Full path of the CSV file ?:') ?? ''); + const csv = CSV.parse(file.replaceAll(';', ','), { skipFirstRow: true, }) as CsvEntry[]; diff --git a/src/append_to_group.ts b/src/append_to_group.ts index a74c707..11dc043 100644 --- a/src/append_to_group.ts +++ b/src/append_to_group.ts @@ -1,10 +1,5 @@ import { Redmine } from 'bluemine'; - -type CsvEntry = { - firstname: string; - lastname: string; - mail: string; -}; +import { CsvEntry } from '../type.ts'; async function addUsersToGroup(redmine: Redmine, csv: CsvEntry[]) { const users: { id: number; login: string }[] = []; diff --git a/src/create_users.ts b/src/create_users.ts index 5c6dc4d..f4b7f64 100644 --- a/src/create_users.ts +++ b/src/create_users.ts @@ -1,10 +1,5 @@ import { Redmine } from 'bluemine'; - -type CsvEntry = { - firstname: string; - lastname: string; - mail: string; -}; +import { CsvEntry } from '../type.ts'; async function createUsers(redmine: Redmine, csv: CsvEntry[]) { const userIds: number[] = []; diff --git a/type.ts b/type.ts new file mode 100644 index 0000000..5927f34 --- /dev/null +++ b/type.ts @@ -0,0 +1,5 @@ +export type CsvEntry = { + firstname: string; + lastname: string; + mail: string; +}; \ No newline at end of file