collavre_github 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/collavre_github/creatives/integrations_controller.rb +61 -12
- data/app/controllers/collavre_github/webhooks_controller.rb +25 -4
- data/app/jobs/collavre_github/initial_markdown_sync_job.rb +19 -0
- data/app/jobs/collavre_github/markdown_sync_job.rb +16 -0
- data/app/models/collavre_github/repository_link.rb +7 -0
- data/app/services/collavre_github/client.rb +50 -0
- data/app/services/collavre_github/markdown_sync/content_processor.rb +113 -0
- data/app/services/collavre_github/markdown_sync/incremental_sync_service.rb +231 -0
- data/app/services/collavre_github/markdown_sync/initial_import_service.rb +190 -0
- data/app/services/collavre_github/tools/concerns/github_client_finder.rb +17 -0
- data/app/services/collavre_github/tools/github_pr_commits_service.rb +7 -10
- data/app/services/collavre_github/tools/github_pr_details_service.rb +21 -24
- data/app/services/collavre_github/tools/github_pr_diff_service.rb +13 -16
- data/app/services/collavre_github/webhook_provisioner.rb +18 -3
- data/app/views/collavre_github/auth/setup.html.erb +48 -3
- data/app/views/collavre_github/integrations/_modal.html.erb +18 -3
- data/config/locales/en.yml +9 -0
- data/config/locales/ko.yml +9 -0
- data/config/routes.rb +3 -1
- data/db/migrate/20260412000000_add_markdown_sync_to_repository_links.rb +10 -0
- data/db/migrate/20260416000000_add_markdown_root_creative_index.rb +5 -0
- data/lib/collavre_github/version.rb +1 -1
- data/lib/tasks/mock_import.rake +98 -0
- metadata +9 -1
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
namespace :collavre_github do
|
|
4
|
+
desc "Import markdown files from mock GitHub server into a creative tree"
|
|
5
|
+
task mock_import: :environment do
|
|
6
|
+
puts "=== GitHub Markdown Mock Import ==="
|
|
7
|
+
puts ""
|
|
8
|
+
|
|
9
|
+
# 1. Find or create user
|
|
10
|
+
user = User.first
|
|
11
|
+
abort "No user found. Run db:seed first." unless user
|
|
12
|
+
puts "User: #{user.name} (#{user.email})"
|
|
13
|
+
|
|
14
|
+
# 2. Find or create GitHub account (mock)
|
|
15
|
+
account = CollavreGithub::Account.find_or_initialize_by(user: user)
|
|
16
|
+
if account.new_record?
|
|
17
|
+
account.assign_attributes(
|
|
18
|
+
github_uid: "mock-12345",
|
|
19
|
+
login: "dev-user",
|
|
20
|
+
name: "Dev User (Mock)",
|
|
21
|
+
token: "mock-token-#{SecureRandom.hex(10)}"
|
|
22
|
+
)
|
|
23
|
+
account.save!
|
|
24
|
+
puts "Created mock GitHub account: #{account.login}"
|
|
25
|
+
else
|
|
26
|
+
puts "Using existing GitHub account: #{account.login}"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# 3. Find or create a root creative for the import
|
|
30
|
+
repo_name = ENV.fetch("MOCK_REPO", "dev-user/my-app")
|
|
31
|
+
root = Collavre::Creative.find_by(description: "GitHub Docs")
|
|
32
|
+
unless root
|
|
33
|
+
parent = Collavre::Creative.roots.first
|
|
34
|
+
root = Collavre::Creative.create!(
|
|
35
|
+
description: "GitHub Docs",
|
|
36
|
+
parent: parent,
|
|
37
|
+
user: user
|
|
38
|
+
)
|
|
39
|
+
puts "Created root creative: #{root.id} — 'GitHub Docs'"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# 4. Clean up existing sync (if re-running)
|
|
43
|
+
existing_link = root.github_repository_links.find_by(
|
|
44
|
+
github_account: account,
|
|
45
|
+
repository_full_name: repo_name
|
|
46
|
+
)
|
|
47
|
+
if existing_link
|
|
48
|
+
puts "Cleaning up existing sync..."
|
|
49
|
+
# Archive old markdown tree
|
|
50
|
+
if existing_link.markdown_root_creative
|
|
51
|
+
existing_link.markdown_root_creative.descendants.each do |c|
|
|
52
|
+
c.destroy if c.data.is_a?(Hash) && c.data.dig("source", "type") == "github_markdown"
|
|
53
|
+
end
|
|
54
|
+
existing_link.markdown_root_creative.destroy
|
|
55
|
+
end
|
|
56
|
+
existing_link.update!(markdown_root_creative_id: nil, last_synced_at: nil)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# 5. Create or reuse RepositoryLink
|
|
60
|
+
link = root.github_repository_links.find_or_create_by!(
|
|
61
|
+
github_account: account,
|
|
62
|
+
repository_full_name: repo_name
|
|
63
|
+
)
|
|
64
|
+
link.update!(markdown_sync_enabled: true, sync_branch: "main")
|
|
65
|
+
puts "RepositoryLink: #{link.id} — #{repo_name} (markdown_sync: enabled)"
|
|
66
|
+
|
|
67
|
+
# 6. Run InitialImportService
|
|
68
|
+
puts ""
|
|
69
|
+
puts "Starting import from mock server..."
|
|
70
|
+
puts "(Make sure mock server is running: bin/rails collavre_github:mock_server)"
|
|
71
|
+
puts ""
|
|
72
|
+
|
|
73
|
+
begin
|
|
74
|
+
result = CollavreGithub::MarkdownSync::InitialImportService.new(
|
|
75
|
+
repository_link: link,
|
|
76
|
+
user: user
|
|
77
|
+
).call
|
|
78
|
+
|
|
79
|
+
if result
|
|
80
|
+
puts ""
|
|
81
|
+
puts "✅ Import complete!"
|
|
82
|
+
puts " Created #{result.size} creatives"
|
|
83
|
+
puts " Root creative: #{link.reload.markdown_root_creative_id}"
|
|
84
|
+
puts " Last synced: #{link.last_synced_at}"
|
|
85
|
+
puts ""
|
|
86
|
+
puts " Open the app and navigate to the 'GitHub Docs' creative to see the tree."
|
|
87
|
+
else
|
|
88
|
+
puts "⚠️ No markdown files found in the repository."
|
|
89
|
+
end
|
|
90
|
+
rescue StandardError => e
|
|
91
|
+
puts "❌ Import failed: #{e.message}"
|
|
92
|
+
puts e.backtrace.first(5).join("\n")
|
|
93
|
+
puts ""
|
|
94
|
+
puts "Is the mock server running? Start it with:"
|
|
95
|
+
puts " bin/rails collavre_github:mock_server"
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: collavre_github
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Collavre
|
|
@@ -66,10 +66,15 @@ files:
|
|
|
66
66
|
- app/controllers/collavre_github/auth_controller.rb
|
|
67
67
|
- app/controllers/collavre_github/creatives/integrations_controller.rb
|
|
68
68
|
- app/controllers/collavre_github/webhooks_controller.rb
|
|
69
|
+
- app/jobs/collavre_github/initial_markdown_sync_job.rb
|
|
70
|
+
- app/jobs/collavre_github/markdown_sync_job.rb
|
|
69
71
|
- app/models/collavre_github/account.rb
|
|
70
72
|
- app/models/collavre_github/application_record.rb
|
|
71
73
|
- app/models/collavre_github/repository_link.rb
|
|
72
74
|
- app/services/collavre_github/client.rb
|
|
75
|
+
- app/services/collavre_github/markdown_sync/content_processor.rb
|
|
76
|
+
- app/services/collavre_github/markdown_sync/incremental_sync_service.rb
|
|
77
|
+
- app/services/collavre_github/markdown_sync/initial_import_service.rb
|
|
73
78
|
- app/services/collavre_github/tools/concerns/github_client_finder.rb
|
|
74
79
|
- app/services/collavre_github/tools/github_pr_commits_service.rb
|
|
75
80
|
- app/services/collavre_github/tools/github_pr_details_service.rb
|
|
@@ -84,10 +89,13 @@ files:
|
|
|
84
89
|
- db/migrate/20250927000000_add_webhook_secret_to_github_repository_links.rb
|
|
85
90
|
- db/migrate/20250928105957_add_github_gemini_prompt_to_creatives.rb
|
|
86
91
|
- db/migrate/20260219095224_remove_github_gemini_prompt_from_creatives.rb
|
|
92
|
+
- db/migrate/20260412000000_add_markdown_sync_to_repository_links.rb
|
|
93
|
+
- db/migrate/20260416000000_add_markdown_root_creative_index.rb
|
|
87
94
|
- db/seeds.rb
|
|
88
95
|
- lib/collavre_github.rb
|
|
89
96
|
- lib/collavre_github/engine.rb
|
|
90
97
|
- lib/collavre_github/version.rb
|
|
98
|
+
- lib/tasks/mock_import.rake
|
|
91
99
|
- lib/tasks/mock_server.rake
|
|
92
100
|
homepage: https://collavre.com
|
|
93
101
|
licenses:
|