add simple issue generator (#2302)

Signed-off-by: Ruslan Bayandinov <wazsone@ya.ru>
This commit is contained in:
Ruslan Bayandinov 2022-10-13 15:16:52 +07:00 committed by GitHub
parent d74fcb45a3
commit 4304066083
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 143 additions and 22 deletions

View File

@ -6,7 +6,8 @@ Random data generator
```bash
cd ./dev/generator
rushx run-local gen-recruit workspace 20
rushx run-local gen recruit workspace 20
rushx run-local gen issue workspace 20
```
Will generate 20 candidate cards.

View File

@ -16,6 +16,7 @@
import { program } from 'commander'
import { Client } from 'minio'
import { generateIssues } from './issues'
import { generateContacts } from './recruit'
const transactorUrl = process.env.TRANSACTOR_URL
@ -52,30 +53,40 @@ const minio = new Client({
program.version('0.0.1')
// available types: recruit, issue
program
.command('gen-recruit <workspace> <count>')
.description('generate a bunch of random candidates with attachemnts and comments.')
.command('gen <genType> <workspace> <count>')
.description('generate a bunch of random candidates with attachemnts and comments or issues')
.option('-r, --random', 'generate random ids. So every call will add count <count> more candidates.', false)
.option('-l, --lite', 'use same pdf and same account for applicant and candidates', false)
.action(async (workspace: string, count: number, cmd) => {
return await generateContacts(
transactorUrl,
workspace,
{
contacts: count,
random: cmd.random as boolean,
comments: { min: 1, max: 10, paragraphMin: 1, paragraphMax: 20, updateFactor: 30 },
attachments: {
min: 1,
max: 3,
deleteFactor: 20
},
vacancy: 3,
applicants: { min: 50, max: 200, applicantUpdateFactor: 70 },
lite: cmd.lite as boolean
},
minio
)
.action(async (genType: string, workspace: string, count: number, cmd) => {
switch (genType) {
case 'recruit':
return await generateContacts(
transactorUrl,
workspace,
{
contacts: count,
random: cmd.random as boolean,
comments: { min: 1, max: 10, paragraphMin: 1, paragraphMax: 20, updateFactor: 30 },
attachments: {
min: 1,
max: 3,
deleteFactor: 20
},
vacancy: 3,
applicants: { min: 50, max: 200, applicantUpdateFactor: 70 },
lite: cmd.lite as boolean
},
minio
)
case 'issue':
return await generateIssues(transactorUrl, workspace, {
count: count
})
default:
console.error(`Expected types: recruit, issue. Got type: ${genType}`)
}
})
program.parse(process.argv)

107
dev/generator/src/issues.ts Normal file
View File

@ -0,0 +1,107 @@
import faker from 'faker'
import contact from '@hcengineering/contact'
import core, {
TxOperations,
MeasureMetricsContext,
metricsToString,
AttachedData,
generateId,
Ref,
SortingOrder
} from '@hcengineering/core'
import tracker, { calcRank, Issue, IssuePriority, IssueStatus } from '../../../plugins/tracker/lib'
import { connect } from './connect'
let objectId: Ref<Issue> = generateId()
const space = tracker.team.DefaultTeam
const object: AttachedData<Issue> = {
title: '',
description: '',
assignee: null,
project: null,
sprint: null,
number: 0,
rank: '',
status: '' as Ref<IssueStatus>,
priority: IssuePriority.NoPriority,
dueDate: null,
comments: 0,
subIssues: 0,
parents: [],
reportedTime: 0,
estimation: 0,
reports: 0,
childInfo: []
}
export interface IssueOptions {
count: number // how many issues to add
}
export async function generateIssues (transactorUrl: string, dbName: string, options: IssueOptions): Promise<void> {
const connection = await connect(transactorUrl, dbName)
const accounts = await connection.findAll(contact.class.EmployeeAccount, {})
const account = faker.random.arrayElement(accounts)
const client = new TxOperations(connection, account._id)
const ctx = new MeasureMetricsContext('recruit', {})
for (let index = 0; index < options.count; index++) {
console.log(`Generating issue ${index + 1}...`)
await genIssue(client)
}
await connection.close()
ctx.end()
console.info(metricsToString(ctx.metrics, 'Client'))
}
async function genIssue (client: TxOperations): Promise<void> {
const lastOne = await client.findOne<Issue>(
tracker.class.Issue,
{ status: object.status },
{ sort: { rank: SortingOrder.Descending } }
)
const incResult = await client.updateDoc(
tracker.class.Team,
core.space.Space,
space,
{
$inc: { sequence: 1 }
},
true
)
const value: AttachedData<Issue> = {
title: faker.name.title(),
description: faker.lorem.paragraphs(),
assignee: object.assignee,
project: object.project,
sprint: object.sprint,
number: (incResult as any).object.sequence,
status: object.status,
priority: object.priority,
rank: calcRank(lastOne, undefined),
comments: 0,
subIssues: 0,
dueDate: object.dueDate,
parents: [],
reportedTime: 0,
estimation: object.estimation,
reports: 0,
relations: [],
childInfo: []
}
await client.addCollection(
tracker.class.Issue,
space,
tracker.ids.NoParent,
tracker.class.Issue,
'subIssues',
value,
objectId
)
objectId = generateId()
}

View File

@ -21,6 +21,7 @@ import { addComments, CommentOptions } from './comments'
import { connect } from './connect'
import { createUpdateSpaceKanban } from './kanban'
import { findOrUpdate, findOrUpdateAttached } from './utils'
export interface RecruitOptions {
random: boolean // random id prefix.
contacts: number // how many contacts to add
@ -73,6 +74,7 @@ export async function generateContacts (
console.info(metricsToString(ctx.metrics, 'Client'))
}
async function genVacansyApplicants (
ctx: MeasureContext,
accountIds: Ref<EmployeeAccount>[],