style: fix fmt config
This commit is contained in:
parent
2555d5f6c7
commit
66397eac5b
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"fmt": {
|
||||
"singleQuote": true,
|
||||
"semiColons": true,
|
||||
"semiColons": false,
|
||||
"useTabs": true,
|
||||
"indentWidth": 4
|
||||
},
|
||||
|
|
36
mod.ts
36
mod.ts
|
@ -1,19 +1,29 @@
|
|||
import { Redmine } from 'bluemine';
|
||||
import * as CSV from 'std:csv';
|
||||
import { CsvEntry } from './type.ts';
|
||||
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')
|
||||
const apiKey = Deno.env.get('API_KEY')
|
||||
const endpoint = Deno.env.get('ENDPOINT')
|
||||
const apiKey = Deno.env.get('API_KEY')
|
||||
|
||||
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')
|
||||
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',
|
||||
)
|
||||
}
|
||||
|
||||
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(';', ','), {
|
||||
skipFirstRow: true,
|
||||
}) as CsvEntry[];
|
||||
}
|
||||
const csv = CSV.parse(file.replaceAll(';', ','), {
|
||||
skipFirstRow: true,
|
||||
}) as CsvEntry[]
|
||||
}
|
||||
|
|
|
@ -1,35 +1,35 @@
|
|||
import { Redmine } from 'bluemine';
|
||||
import { CsvEntry } from '../type.ts';
|
||||
import { Redmine } from 'bluemine'
|
||||
import { CsvEntry } from '../type.ts'
|
||||
|
||||
async function addUsersToGroup(redmine: Redmine, csv: CsvEntry[]) {
|
||||
const users: { id: number; login: string }[] = [];
|
||||
|
||||
for (const { firstname, lastname } of csv) {
|
||||
const login = `${firstname.toLowerCase()}.${lastname.toLowerCase()}`;
|
||||
|
||||
try {
|
||||
const list = await redmine.users.list({ limit: 1, name: login });
|
||||
const user = list.users[0];
|
||||
|
||||
console.log(`get user: ${user.login}#${user.id}`);
|
||||
users.push(user);
|
||||
} catch {
|
||||
console.error(`error list: ${login}`);
|
||||
}
|
||||
}
|
||||
|
||||
const { groups } = await redmine.unstableGroups.list() as unknown as {
|
||||
groups: { id: number; name: string }[];
|
||||
};
|
||||
|
||||
const { id } = groups.filter(({ name }) => name === 'entrepreneur-01-24')[0];
|
||||
|
||||
for (const user of users) {
|
||||
try {
|
||||
console.error(`ok: ${user.login}#${user.id}`);
|
||||
await redmine.unstableGroups.addUser(id, user);
|
||||
} catch {
|
||||
console.error(`error: ${user.login}`);
|
||||
}
|
||||
}
|
||||
const users: { id: number; login: string }[] = []
|
||||
|
||||
for (const { firstname, lastname } of csv) {
|
||||
const login = `${firstname.toLowerCase()}.${lastname.toLowerCase()}`
|
||||
|
||||
try {
|
||||
const list = await redmine.users.list({ limit: 1, name: login })
|
||||
const user = list.users[0]
|
||||
|
||||
console.log(`get user: ${user.login}#${user.id}`)
|
||||
users.push(user)
|
||||
} catch {
|
||||
console.error(`error list: ${login}`)
|
||||
}
|
||||
}
|
||||
|
||||
const { groups } = await redmine.unstableGroups.list() as unknown as {
|
||||
groups: { id: number; name: string }[]
|
||||
}
|
||||
|
||||
const { id } = groups.filter(({ name }) => name === 'entrepreneur-01-24')[0]
|
||||
|
||||
for (const user of users) {
|
||||
try {
|
||||
console.error(`ok: ${user.login}#${user.id}`)
|
||||
await redmine.unstableGroups.addUser(id, user)
|
||||
} catch {
|
||||
console.error(`error: ${user.login}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,32 +1,34 @@
|
|||
import { Redmine } from 'bluemine';
|
||||
import { CsvEntry } from '../type.ts';
|
||||
import { Redmine } from 'bluemine'
|
||||
import { CsvEntry } from '../type.ts'
|
||||
|
||||
async function createUsers(redmine: Redmine, csv: CsvEntry[]) {
|
||||
const userIds: number[] = [];
|
||||
|
||||
function capitalize(str: string): string {
|
||||
const [first, ...tail] = str.split('');
|
||||
return `${first.toLocaleUpperCase()}${tail.join('').toLocaleLowerCase()}`;
|
||||
}
|
||||
|
||||
for (const { firstname, lastname, mail } of csv) {
|
||||
const login = `${firstname.toLowerCase()}.${lastname.toLowerCase()}`;
|
||||
|
||||
try {
|
||||
const { user } = await redmine.users.create({
|
||||
firstname: capitalize(firstname),
|
||||
lastname: capitalize(lastname),
|
||||
mail: mail,
|
||||
login,
|
||||
sendCreationMail: true,
|
||||
generatePassword: true,
|
||||
});
|
||||
|
||||
userIds.push(user.id);
|
||||
} catch {
|
||||
console.error(login);
|
||||
}
|
||||
}
|
||||
|
||||
await redmine.unstableGroups.create({ name: 'entrepreneur-01-24', userIds });
|
||||
const userIds: number[] = []
|
||||
|
||||
function capitalize(str: string): string {
|
||||
const [first, ...tail] = str.split('')
|
||||
return `${first.toLocaleUpperCase()}${
|
||||
tail.join('').toLocaleLowerCase()
|
||||
}`
|
||||
}
|
||||
|
||||
for (const { firstname, lastname, mail } of csv) {
|
||||
const login = `${firstname.toLowerCase()}.${lastname.toLowerCase()}`
|
||||
|
||||
try {
|
||||
const { user } = await redmine.users.create({
|
||||
firstname: capitalize(firstname),
|
||||
lastname: capitalize(lastname),
|
||||
mail: mail,
|
||||
login,
|
||||
sendCreationMail: true,
|
||||
generatePassword: true,
|
||||
})
|
||||
|
||||
userIds.push(user.id)
|
||||
} catch {
|
||||
console.error(login)
|
||||
}
|
||||
}
|
||||
|
||||
await redmine.unstableGroups.create({ name: 'entrepreneur-01-24', userIds })
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue