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 * 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[];

View file

@ -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 }[] = [];

View file

@ -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[] = [];

5
type.ts Normal file
View file

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