Class: Quality::Seeders::Issues
- Inherits:
-
Object
- Object
- Quality::Seeders::Issues
- Defined in:
- lib/quality/seeders/issues.rb
Constant Summary collapse
- DEFAULT_BACKFILL_WEEKS =
52
- DEFAULT_AVERAGE_ISSUES_PER_WEEK =
20
Instance Attribute Summary collapse
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(project:) ⇒ Issues
constructor
A new instance of Issues.
- #seed(backfill_weeks: DEFAULT_BACKFILL_WEEKS, average_issues_per_week: DEFAULT_AVERAGE_ISSUES_PER_WEEK) ⇒ Object
Constructor Details
#initialize(project:) ⇒ Issues
Returns a new instance of Issues.
12 13 14 |
# File 'lib/quality/seeders/issues.rb', line 12 def initialize(project:) @project = project end |
Instance Attribute Details
#project ⇒ Object (readonly)
Returns the value of attribute project.
10 11 12 |
# File 'lib/quality/seeders/issues.rb', line 10 def project @project end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
10 11 12 |
# File 'lib/quality/seeders/issues.rb', line 10 def user @user end |
Instance Method Details
#seed(backfill_weeks: DEFAULT_BACKFILL_WEEKS, average_issues_per_week: DEFAULT_AVERAGE_ISSUES_PER_WEEK) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/quality/seeders/issues.rb', line 16 def seed(backfill_weeks: DEFAULT_BACKFILL_WEEKS, average_issues_per_week: DEFAULT_AVERAGE_ISSUES_PER_WEEK) create_milestones! create_team_members! created_at = backfill_weeks.to_i.weeks.ago team = project.team.users created_issues_count = 0 loop do rand(1..average_issues_per_week).times do params = { title: FFaker::Lorem.sentence(6), description: FFaker::Lorem.sentence, created_at: created_at + rand(6).days, state: %w[opened closed].sample, milestone_id: project.milestones.sample&.id, assignee_ids: Array(team.pluck(:id).sample(rand(3))), due_date: rand(10).days.from_now, labels: labels.join(',') }.merge(additional_params) params[:closed_at] = params[:created_at] + rand(35).days if params[:state] == 'closed' create_result = ::Issues::CreateService.new(container: project, current_user: team.sample, params: params, perform_spam_check: false).execute_without_rate_limiting if create_result.success? created_issues_count += 1 print '.' # rubocop:disable Rails/Output end end created_at += 1.week break if created_at > Time.now end created_issues_count end |