Module: CommitSynchronizer
- Defined in:
- app/concerns/commit_synchronizer.rb
Instance Method Summary collapse
- #between(commit0, commit1) ⇒ Object
- #find_or_create_by_sha(sha) ⇒ Object
- #sync! ⇒ Object
- #synchronize(native_commits) ⇒ Object
Instance Method Details
#between(commit0, commit1) ⇒ Object
25 26 27 28 29 |
# File 'app/concerns/commit_synchronizer.rb', line 25 def between(commit0, commit1) synchronize repo.commits_between(commit0, commit1) rescue Houston::Adapters::VersionControl::CommitNotFound [] end |
#find_or_create_by_sha(sha) ⇒ Object
16 17 18 19 20 21 22 |
# File 'app/concerns/commit_synchronizer.rb', line 16 def find_or_create_by_sha(sha) return nil if sha.nil? sha = sha.sha if sha.respond_to?(:sha) find_by_sha(sha) || create_missing_commit!(repo.native_commit(sha)) rescue Houston::Adapters::VersionControl::CommitNotFound nil end |
#sync! ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'app/concerns/commit_synchronizer.rb', line 4 def sync! repo.refresh! Houston.benchmark "Synchronize Commits" do existing_commits = project.commits.pluck(:sha) expected_commits = repo.all_commits create_missing_commits! expected_commits - existing_commits flag_unreachable_commits! existing_commits - expected_commits end end |
#synchronize(native_commits) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/concerns/commit_synchronizer.rb', line 32 def synchronize(native_commits) native_commits = native_commits.reject(&:nil?) return [] if native_commits.empty? Houston.benchmark("[commits.synchronize] synchronizing #{native_commits.length} commits") do shas = native_commits.map(&:sha) commits = where(sha: shas) native_commits.map do |native_commit| commit = commits.detect { |commit| commit.sha == native_commit.sha } || create_missing_commit!(native_commit) # There's no reason why this shouldn't be set, # but in order to reduce a bunch of useless hits # to the cache and a bunch of log output... commit.project = project commit end end end |