Last active
October 3, 2024 14:32
-
-
Save firedev/9913283f940e7eb204ecbb4638a2fb87 to your computer and use it in GitHub Desktop.
url="";eval URI.parse(url).open { |f| f.read }
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
organization_id = 1 | |
def id | |
(Time.now.to_f * 1000000).to_i | |
end | |
o = Organization.find(organization_id) | |
i = Integration.find_by(organization_id: organization_id, integration_type: "git_hostings_github") || | |
Integration.create( | |
organization: o, | |
name: "Integration Test Github #{id}", | |
integration_type: "git_hostings_github", | |
configuration: { | |
integration_wizard: { | |
organization: "NetsoftHoldings" | |
}, | |
token: { | |
access_token: "test_access", | |
refresh_token: "test_refresh", | |
expires_at: 1.week.since, | |
} | |
} | |
) | |
r = GitHostings::Repository.find_by(integration_id: i.id) || GitHostings::Repository.create( | |
integration_id: i.id, | |
remote_id: "repo_#{id}", | |
name: "repository-#{id}", | |
organization_name: "Organization-#{id}" | |
) | |
def create_git_hostings_pull_request(**attrs) | |
$pr_glob_i ||= 0 | |
$pr_glob_i += 1 | |
index = $pr_glob_i | |
GitHostings::PullRequest.create( | |
remote_id: "remote_#{id}", | |
url: "CustomUrl", | |
number: "#{id}", | |
branch: "custom-branch-#{id}", | |
title: "PullRequest ##{id}", | |
**attrs | |
) | |
end | |
def create_git_hostings_review(**attrs) | |
$review_glob_i ||= 0 | |
$review_glob_i += 1 | |
index = $review_glob_i | |
GitHostings::Review.create( | |
remote_id: "Remote#{id}", | |
state: %w[commented changes_requested approved].sample, | |
submitted_at: rand(10).days.ago, | |
**attrs | |
) | |
end | |
sample_users = o.all_members.sample(20) | |
# Create user links for integration. You can skip this step if user links already added through UI | |
sample_users.map { i.user_links.find_or_create_by(link: _1, configuration: {name: _1.name, email: _1.email}, remote_id: _1.name) } | |
# Limit user links by 20 | |
sample_links = IntegrationLink.user_links.where(integration_id: i.id).limit(20) | |
# Create PRs | |
prs = [] | |
(sample_links.to_a * 3).each { |ul| | |
status = [:open, :merged, :closed].sample | |
merged_at = status == :open ? nil : Time.current | |
closed_at = rand(10).hours.ago if status == :closed | |
prs << create_git_hostings_pull_request( | |
merged_at: merged_at, state: status, pr_created_at: 1.week.ago, | |
first_review_at: (1..5).to_a.sample.days.ago, owner_link_id: ul.id, repository: r, | |
integration: i, closed_at: closed_at) | |
} | |
# Create 10 Reviews for random users | |
reviews = 40.times.map { | |
ul = sample_links.sample | |
pr = prs.sample | |
create_git_hostings_review(owner_link_id: ul.id, pull_request: pr, integration: i) | |
} | |
# Create 5 comment for random users | |
30.times { | |
ul = sample_links.sample | |
GitHostings::Comment.create( | |
remote_id: "Remote#{id}}", owner_link_id: ul.id, | |
repository_id: prs.sample.repository_id, integration: i, | |
comment_created_at: (1..5).to_a.sample.days.ago, | |
review_id: rand(3).zero? ? nil : reviews.sample.id) | |
} | |
100.times { | |
event_type = rand(2).zero? ? :push : :review_request | |
sent_at = rand(168).hours.ago | |
GitHostings::Event.create( | |
repository: r, integration: i, sent_at: sent_at, | |
data: event_type == :push ? {pusher: 'login', branch: 'custom-branch', commit_count: rand(1..10)} : {sender: 'login'}, | |
event_type: event_type, owner_link: sample_links.sample, | |
remote_id: id) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment