Class: Octorule::Syncer

Inherits:
Object
  • Object
show all
Defined in:
lib/octorule/syncer.rb

Instance Method Summary collapse

Constructor Details

#initialize(client, org, settings, filters = {}, dry_run = false) ⇒ Syncer

Returns a new instance of Syncer.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/octorule/syncer.rb', line 5

def initialize(client, org, settings, filters = {}, dry_run = false)
  @client = client
  @org = org
  @settings = settings
  @filters = filters
  @dry_run = dry_run

  @repository_service = Services::Repository.new(client)
  @collaborators_service = Services::Collaborators.new(client)
  @branch_protection_service = Services::BranchProtection.new(client)
  @file_sync_service = Services::FileSync.new(client)
  @filters_service = Filters.new(client)
end

Instance Method Details

#syncObject



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
# File 'lib/octorule/syncer.rb', line 19

def sync
  puts "Starting settings sync for organization: #{@org}"
  puts "Running in dry-run mode - no changes will be made" if @dry_run

  repos = @repository_service.fetch_all(@org)
  puts "Found #{repos.length} repositories"

  processed_count = 0
  skipped_count = 0

  repos.each do |repo|
    if @filters_service.should_process?(repo, @filters)
      process_repository(repo)
      processed_count += 1
    else
      skipped_count += 1
    end
  end

  puts "Settings sync completed!"
  puts "Summary:"
  puts "    - Total repositories: #{repos.length}"
  puts "    - Processed: #{processed_count}"
  puts "    - Skipped: #{skipped_count}"
  puts "    - Mode: #{@dry_run ? "Dry Run" : "Live"}"
rescue StandardError => e
  warn "Error during sync: #{e.message}"
  raise
end