style: fix fmt config

This commit is contained in:
Julien Oculi 2024-01-15 21:05:44 +01:00
parent 2555d5f6c7
commit 66397eac5b
5 changed files with 91 additions and 79 deletions

View file

@ -1,7 +1,7 @@
{ {
"fmt": { "fmt": {
"singleQuote": true, "singleQuote": true,
"semiColons": true, "semiColons": false,
"useTabs": true, "useTabs": true,
"indentWidth": 4 "indentWidth": 4
}, },

26
mod.ts
View file

@ -1,19 +1,29 @@
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'; 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')
const apiKey = Deno.env.get('API_KEY') const apiKey = Deno.env.get('API_KEY')
if (apiKey === undefined) throw new Error('Redmine REST API key is missing, please define API_KEY') if (apiKey === undefined) {
if (endpoint === undefined) throw new Error('Redmine REST endpoint is missing, please define ENDPOINT') 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',
)
}
const redmine = new Redmine({ endpoint, apiKey }); const redmine = new Redmine({ endpoint, apiKey })
const file = await Deno.readTextFile(prompt('Full path of the CSV file ?:') ?? ''); const file = await Deno.readTextFile(
prompt('Full path of the CSV file ?:') ?? '',
)
const csv = CSV.parse(file.replaceAll(';', ','), { const csv = CSV.parse(file.replaceAll(';', ','), {
skipFirstRow: true, skipFirstRow: true,
}) as CsvEntry[]; }) as CsvEntry[]
} }

View file

@ -1,35 +1,35 @@
import { Redmine } from 'bluemine'; import { Redmine } from 'bluemine'
import { CsvEntry } from '../type.ts'; import { CsvEntry } from '../type.ts'
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 }[] = []
for (const { firstname, lastname } of csv) { for (const { firstname, lastname } of csv) {
const login = `${firstname.toLowerCase()}.${lastname.toLowerCase()}`; const login = `${firstname.toLowerCase()}.${lastname.toLowerCase()}`
try { try {
const list = await redmine.users.list({ limit: 1, name: login }); const list = await redmine.users.list({ limit: 1, name: login })
const user = list.users[0]; const user = list.users[0]
console.log(`get user: ${user.login}#${user.id}`); console.log(`get user: ${user.login}#${user.id}`)
users.push(user); users.push(user)
} catch { } catch {
console.error(`error list: ${login}`); console.error(`error list: ${login}`)
} }
} }
const { groups } = await redmine.unstableGroups.list() as unknown as { const { groups } = await redmine.unstableGroups.list() as unknown as {
groups: { id: number; name: string }[]; groups: { id: number; name: string }[]
}; }
const { id } = groups.filter(({ name }) => name === 'entrepreneur-01-24')[0]; const { id } = groups.filter(({ name }) => name === 'entrepreneur-01-24')[0]
for (const user of users) { for (const user of users) {
try { try {
console.error(`ok: ${user.login}#${user.id}`); console.error(`ok: ${user.login}#${user.id}`)
await redmine.unstableGroups.addUser(id, user); await redmine.unstableGroups.addUser(id, user)
} catch { } catch {
console.error(`error: ${user.login}`); console.error(`error: ${user.login}`)
} }
} }
} }

View file

@ -1,16 +1,18 @@
import { Redmine } from 'bluemine'; import { Redmine } from 'bluemine'
import { CsvEntry } from '../type.ts'; import { CsvEntry } from '../type.ts'
async function createUsers(redmine: Redmine, csv: CsvEntry[]) { async function createUsers(redmine: Redmine, csv: CsvEntry[]) {
const userIds: number[] = []; const userIds: number[] = []
function capitalize(str: string): string { function capitalize(str: string): string {
const [first, ...tail] = str.split(''); const [first, ...tail] = str.split('')
return `${first.toLocaleUpperCase()}${tail.join('').toLocaleLowerCase()}`; return `${first.toLocaleUpperCase()}${
tail.join('').toLocaleLowerCase()
}`
} }
for (const { firstname, lastname, mail } of csv) { for (const { firstname, lastname, mail } of csv) {
const login = `${firstname.toLowerCase()}.${lastname.toLowerCase()}`; const login = `${firstname.toLowerCase()}.${lastname.toLowerCase()}`
try { try {
const { user } = await redmine.users.create({ const { user } = await redmine.users.create({
@ -20,13 +22,13 @@ async function createUsers(redmine: Redmine, csv: CsvEntry[]) {
login, login,
sendCreationMail: true, sendCreationMail: true,
generatePassword: true, generatePassword: true,
}); })
userIds.push(user.id); userIds.push(user.id)
} catch { } catch {
console.error(login); console.error(login)
} }
} }
await redmine.unstableGroups.create({ name: 'entrepreneur-01-24', userIds }); await redmine.unstableGroups.create({ name: 'entrepreneur-01-24', userIds })
} }

View file

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