Class: Ballantine::Repository
- Inherits:
-
Object
- Object
- Ballantine::Repository
- Defined in:
- lib/ballantine/repository.rb
Constant Summary collapse
- GITHUB_REGEXES =
[ '^https?://(.+)/(.+)/(.+)\.git/?$', # protocol: https -> https://github.com/oohyun15/ballantine.git | https://github.com/oohyun15/ballantine.git/ '^https?://(.+)/(.+)/(.+)/?$', # protocol: https -> https://github.com/oohyun15/ballantine | https://github.com/oohyun15/ballantine/ '^git@(.+):(.+)/(.+)\.git$', # protocol: ssh -> [email protected]:oohyun15/ballantine.git '^git@(.+):(.+)/(.+)/?$', # protocol: ssh -> [email protected]:oohyun15/ballantine | [email protected]:oohyun15/ballantine/ '^git:(.+)/(.+)/(.+)\.git$', # protocol: ssh -> git:github.com/oohyun15/ballantine.git '^git:(.+)/(.+)/(.+)/?$', # protocol: ssh -> git:github.com/oohyun15/ballantine | git:github.com/oohyun15/ballantine/ '^ssh://git@(.+)/(.+)/(.+)\.git$', # protocol: ssh -> ssh://[email protected]/oohyun15/ballantine.git ].freeze
- FILE_GITMODULES =
".gitmodules"
- PARSER_TOKEN =
"!#!#"
Instance Attribute Summary collapse
-
#commits ⇒ Object
readonly
associations.
-
#from ⇒ Object
readonly
attributes.
-
#main_repo ⇒ Object
readonly
associations.
-
#name ⇒ Object
readonly
attributes.
-
#owner ⇒ Object
readonly
attributes.
-
#path ⇒ Object
readonly
attributes.
-
#sub_repos ⇒ Object
readonly
associations.
-
#to ⇒ Object
readonly
attributes.
Class Method Summary collapse
- .all ⇒ Array<Repository>
- .find(path:) ⇒ Repository, NilClass
- .find_or_create_by(path:, remote_url: nil) ⇒ Repository
Instance Method Summary collapse
- #check_commits ⇒ Boolean
- #init_variables(target, source) ⇒ Boolean
-
#initialize(path:, remote_url:) ⇒ Repository
constructor
A new instance of Repository.
- #url ⇒ Object
Constructor Details
#initialize(path:, remote_url:) ⇒ Repository
Returns a new instance of Repository.
46 47 48 49 50 51 52 53 54 |
# File 'lib/ballantine/repository.rb', line 46 def initialize(path:, remote_url:) @path = path @commits = [] @sub_repos = retrieve_sub_repos @owner, @name = GITHUB_REGEXES.each do |regex| str = remote_url.match(regex) break [str[2], str[3]] if str end end |
Instance Attribute Details
#commits ⇒ Object (readonly)
associations
19 20 21 |
# File 'lib/ballantine/repository.rb', line 19 def commits @commits end |
#from ⇒ Object (readonly)
attributes
18 19 20 |
# File 'lib/ballantine/repository.rb', line 18 def from @from end |
#main_repo ⇒ Object (readonly)
associations
19 20 21 |
# File 'lib/ballantine/repository.rb', line 19 def main_repo @main_repo end |
#name ⇒ Object (readonly)
attributes
18 19 20 |
# File 'lib/ballantine/repository.rb', line 18 def name @name end |
#owner ⇒ Object (readonly)
attributes
18 19 20 |
# File 'lib/ballantine/repository.rb', line 18 def owner @owner end |
#path ⇒ Object (readonly)
attributes
18 19 20 |
# File 'lib/ballantine/repository.rb', line 18 def path @path end |
#sub_repos ⇒ Object (readonly)
associations
19 20 21 |
# File 'lib/ballantine/repository.rb', line 19 def sub_repos @sub_repos end |
#to ⇒ Object (readonly)
attributes
18 19 20 |
# File 'lib/ballantine/repository.rb', line 18 def to @to end |
Class Method Details
.all ⇒ Array<Repository>
37 38 39 40 41 |
# File 'lib/ballantine/repository.rb', line 37 def all return [] unless defined?(@_collections) @_collections.values end |
.find(path:) ⇒ Repository, NilClass
24 25 26 27 |
# File 'lib/ballantine/repository.rb', line 24 def find(path:) @_collections = {} unless defined?(@_collections) @_collections[path] end |
.find_or_create_by(path:, remote_url: nil) ⇒ Repository
32 33 34 |
# File 'lib/ballantine/repository.rb', line 32 def find_or_create_by(path:, remote_url: nil) find(path:) || @_collections[path] = new(path:, remote_url:) end |
Instance Method Details
#check_commits ⇒ Boolean
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/ballantine/repository.rb', line 102 def check_commits conf.print_log(binding) if conf.verbose = .each do || commits = retrieve_commits() next if commits.empty? .commits_hash[name] = commits # TODO: append `commits` to `repo.commits` end if sub_repos.any? sub_repos.each do |sub_repo| next if sub_repo.from.hash == sub_repo.to.hash Dir.chdir(sub_repo.path) sub_repo.check_commits end Dir.chdir(path) end true end |
#init_variables(target, source) ⇒ Boolean
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/ballantine/repository.rb', line 61 def init_variables(target, source) conf.print_log(binding) if conf.verbose current_revision = %x(git rev-parse --abbrev-ref HEAD).chomp foo = lambda do |hash, context| hash = check_tag(hash) system("git checkout #{hash} -f &> /dev/null") system("git pull &> /dev/null") hash = %x(git --no-pager log -1 --format='%h').chomp commit = Commit.find_or_create_by( hash: hash, repo: self, ) instance_variable_set("@#{context}", commit) if sub_repos.any? %x(git ls-tree HEAD #{sub_repos.map(&:path).join(" ")}).split("\n").map do |line| _, _, sub_hash, sub_path = line.split(" ") sub_repo = Repository.find( path: path + "/" + sub_path, ) sub_commit = Commit.find_or_create_by( hash: sub_hash, repo: sub_repo, ) sub_repo.instance_variable_set("@#{context}", sub_commit) end end end foo.call(target, "from") foo.call(source, "to") system("git checkout #{current_revision} -f &> /dev/null") true end |
#url ⇒ Object
56 |
# File 'lib/ballantine/repository.rb', line 56 def url; @url ||= "https://github.com/#{owner}/#{name}" end |