This repository was archived by the owner on Jan 22, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommit.rb
More file actions
49 lines (42 loc) · 1.41 KB
/
Copy pathcommit.rb
File metadata and controls
49 lines (42 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
# frozen_string_literal: true
module Git
module Pkgs
module Models
class Commit < Sequel::Model
unrestrict_primary_key
plugin :validation_helpers
one_to_many :branch_commits
one_to_many :dependency_changes
one_to_many :dependency_snapshots
many_to_many :branches, join_table: :branch_commits
def self.find_or_create_from_rugged(rugged_commit)
find_or_create(sha: rugged_commit.oid) do |commit|
commit.message = rugged_commit.message&.strip
commit.author_name = rugged_commit.author[:name]
commit.author_email = rugged_commit.author[:email]
commit.committed_at = rugged_commit.time
end
end
def self.find_or_create_from_repo(repo, sha)
commit = first(sha: sha) || where(Sequel.like(:sha, "#{sha}%")).first
return commit if commit
rugged_commit = repo.lookup(sha)
return nil unless rugged_commit
create(
sha: rugged_commit.oid,
message: rugged_commit.message,
author_name: rugged_commit.author[:name],
author_email: rugged_commit.author[:email],
committed_at: rugged_commit.time,
has_dependency_changes: false
)
rescue Rugged::OdbError
nil
end
def short_sha
sha[0, 7]
end
end
end
end
end