Class: Perkins::Repo
- Defined in:
- lib/perkins/repo.rb
Constant Summary collapse
- DEFAULT_DIR =
"/tmp/"
Instance Attribute Summary collapse
-
#git ⇒ Object
Returns the value of attribute git.
-
#new_commit ⇒ Object
Returns the value of attribute new_commit.
-
#runner ⇒ Object
Returns the value of attribute runner.
Class Method Summary collapse
- .add_from_github(id) ⇒ Object
- .initialize_from_store(opts) ⇒ Object
- .store_from_github(repo) ⇒ Object
- .sync_github_repo(r) ⇒ Object
- .sync_github_repos(user) ⇒ Object
- .synced_records ⇒ Object
Instance Method Summary collapse
- #add_commit(sha, branch) ⇒ Object
- #branches ⇒ Object
- #build_runner_config(config) ⇒ Object
- #check_config_existence ⇒ Object
- #clone_or_load ⇒ Object
- #downloaded? ⇒ Boolean
- #downloading? ⇒ Boolean
- #enqueue_commit(sha, branch) ⇒ Object
- #exists? ⇒ Boolean
- #http_url ⇒ Object
- #last_report_id ⇒ Object
- #load_git ⇒ Object
- #local_path ⇒ Object
- #open ⇒ Object
- #runner_branch ⇒ Object
Instance Attribute Details
#git ⇒ Object
Returns the value of attribute git.
4 5 6 |
# File 'lib/perkins/repo.rb', line 4 def git @git end |
#new_commit ⇒ Object
Returns the value of attribute new_commit.
5 6 7 |
# File 'lib/perkins/repo.rb', line 5 def new_commit @new_commit end |
#runner ⇒ Object
Returns the value of attribute runner.
5 6 7 |
# File 'lib/perkins/repo.rb', line 5 def runner @runner end |
Class Method Details
.add_from_github(id) ⇒ Object
15 16 17 18 |
# File 'lib/perkins/repo.rb', line 15 def self.add_from_github(id) github_repo = synced_records.find_by(gb_id: id.to_i) store_from_github(github_repo) end |
.initialize_from_store(opts) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/perkins/repo.rb', line 49 def self.initialize_from_store(opts) repo = Repo.new repo.url = opts["github_data"]["ssh_url"] repo.name = opts["name"] repo.github_data = opts["github_data"] repo.gb_id = opts["github_data"]["id"] repo.working_dir = DEFAULT_DIR #this should be configurable from app repo end |
.store_from_github(repo) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/perkins/repo.rb', line 42 def self.store_from_github(repo) #repo repo.working_dir = DEFAULT_DIR #this should be configurable from app repo.cached = false repo.save end |
.sync_github_repo(r) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/perkins/repo.rb', line 26 def self.sync_github_repo(r) return if Repo.where(gb_id: r[:id]).any? repo = Repo.new repo.github_data = r.to_attrs.with_indifferent_access repo.cached = true repo.url = r[:clone_url] repo.name = r[:full_name] repo.gb_id = r[:id] repo.working_dir = DEFAULT_DIR repo.save end |
.sync_github_repos(user) ⇒ Object
20 21 22 23 24 |
# File 'lib/perkins/repo.rb', line 20 def self.sync_github_repos(user) user.api.repos.each do |repo| self.sync_github_repo(repo) end end |
.synced_records ⇒ Object
38 39 40 |
# File 'lib/perkins/repo.rb', line 38 def self.synced_records self.from_github end |
Instance Method Details
#add_commit(sha, branch) ⇒ Object
131 132 133 134 135 136 137 138 139 140 |
# File 'lib/perkins/repo.rb', line 131 def add_commit(sha, branch) if runner_branch.include?(branch) #@new_commit = Perkins::Commit.new(sha, self) #@new_commit.branch = branch #enqueue_commit(@new_commit) enqueue_commit(sha, branch) else puts "skipping commit from branch #{branch}" end end |
#branches ⇒ Object
107 108 109 |
# File 'lib/perkins/repo.rb', line 107 def branches self.git.branches.map(&:name) end |
#build_runner_config(config) ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/perkins/repo.rb', line 112 def build_runner_config(config) runner = Runner.new() runner.config = config runner.repo = self self.branch = runner_branch self.runner = runner end |
#check_config_existence ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/perkins/repo.rb', line 87 def check_config_existence config = self.git.chdir{ if File.exist?(".travis.yml") config = Travis::Yaml.parse( File.open(".travis.yml").read ) else config = Travis::Yaml.new end config } config end |
#clone_or_load ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/perkins/repo.rb', line 71 def clone_or_load if exists? open else ssh_url = self.github_data["ssh_url"] Git.clone(ssh_url, name, :path => working_dir) open end end |
#downloaded? ⇒ Boolean
63 64 65 |
# File 'lib/perkins/repo.rb', line 63 def downloaded? self.download_status.present? && self.download_status == "downloaded" end |
#downloading? ⇒ Boolean
67 68 69 |
# File 'lib/perkins/repo.rb', line 67 def downloading? self.download_status.present? && self.download_status == "downloading" end |
#enqueue_commit(sha, branch) ⇒ Object
142 143 144 |
# File 'lib/perkins/repo.rb', line 142 def enqueue_commit(sha, branch) BuildWorker.perform_async(self.id, sha, branch ) end |
#exists? ⇒ Boolean
99 100 101 |
# File 'lib/perkins/repo.rb', line 99 def exists? File.exist?(local_path) end |
#http_url ⇒ Object
146 147 148 149 150 151 |
# File 'lib/perkins/repo.rb', line 146 def http_url new_url = self.url.include?("http") ? self.url : self.url.gsub(":", "/") new_url.gsub!("git@", "https://") new_url.gsub!(".git", "") new_url end |
#last_report_id ⇒ Object
153 154 155 |
# File 'lib/perkins/repo.rb', line 153 def last_report_id build_reports.last.id if build_reports.any? end |
#load_git ⇒ Object
59 60 61 |
# File 'lib/perkins/repo.rb', line 59 def load_git clone_or_load end |
#local_path ⇒ Object
103 104 105 |
# File 'lib/perkins/repo.rb', line 103 def local_path self.working_dir + self.name.to_s end |
#open ⇒ Object
81 82 83 84 85 |
# File 'lib/perkins/repo.rb', line 81 def open self.git = Git.open(local_path) # :log => Logger.new(STDOUT) build_runner_config(self.check_config_existence) if self.check_config_existence self.update_column(:download_status, "downloaded") end |
#runner_branch ⇒ Object
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/perkins/repo.rb', line 120 def runner_branch case self.branch when :all self.branches when nil ["master"] else self.branches.include?(self.branch) ? [self.branch] : ["master"] end end |