feat: allow user to specify csv file to use

This commit is contained in:
Julien Oculi 2024-01-15 21:05:13 +01:00
parent f0ce8a4725
commit 2555d5f6c7
4 changed files with 10 additions and 15 deletions

6
mod.ts
View file

@ -1,5 +1,6 @@
import { Redmine } from 'bluemine'; import { Redmine } from 'bluemine';
import * as CSV from 'std:csv'; import * as CSV from 'std:csv';
import { CsvEntry } from './type.ts';
if (import.meta.main) { if (import.meta.main) {
const endpoint = Deno.env.get('ENDPOINT') const endpoint = Deno.env.get('ENDPOINT')
@ -10,9 +11,8 @@ if (import.meta.main) {
const redmine = new Redmine({ endpoint, apiKey }); const redmine = new Redmine({ endpoint, apiKey });
const file = await Deno.readTextFile( const file = await Deno.readTextFile(prompt('Full path of the CSV file ?:') ?? '');
'path',
);
const csv = CSV.parse(file.replaceAll(';', ','), { const csv = CSV.parse(file.replaceAll(';', ','), {
skipFirstRow: true, skipFirstRow: true,
}) as CsvEntry[]; }) as CsvEntry[];

View file

@ -1,10 +1,5 @@
import { Redmine } from 'bluemine'; import { Redmine } from 'bluemine';
import { CsvEntry } from '../type.ts';
type CsvEntry = {
firstname: string;
lastname: string;
mail: string;
};
async function addUsersToGroup(redmine: Redmine, csv: CsvEntry[]) { async function addUsersToGroup(redmine: Redmine, csv: CsvEntry[]) {
const users: { id: number; login: string }[] = []; const users: { id: number; login: string }[] = [];

View file

@ -1,10 +1,5 @@
import { Redmine } from 'bluemine'; import { Redmine } from 'bluemine';
import { CsvEntry } from '../type.ts';
type CsvEntry = {
firstname: string;
lastname: string;
mail: string;
};
async function createUsers(redmine: Redmine, csv: CsvEntry[]) { async function createUsers(redmine: Redmine, csv: CsvEntry[]) {
const userIds: number[] = []; const userIds: number[] = [];

5
type.ts Normal file
View file

@ -0,0 +1,5 @@
export type CsvEntry = {
firstname: string;
lastname: string;
mail: string;
};