style: fix fmt config
This commit is contained in:
parent
2555d5f6c7
commit
66397eac5b
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"fmt": {
|
"fmt": {
|
||||||
"singleQuote": true,
|
"singleQuote": true,
|
||||||
"semiColons": true,
|
"semiColons": false,
|
||||||
"useTabs": true,
|
"useTabs": true,
|
||||||
"indentWidth": 4
|
"indentWidth": 4
|
||||||
},
|
},
|
||||||
|
|
34
mod.ts
34
mod.ts
|
@ -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[]
|
||||||
}
|
}
|
|
@ -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}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,32 +1,34 @@
|
||||||
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({
|
||||||
firstname: capitalize(firstname),
|
firstname: capitalize(firstname),
|
||||||
lastname: capitalize(lastname),
|
lastname: capitalize(lastname),
|
||||||
mail: mail,
|
mail: mail,
|
||||||
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 })
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue