Class: LgPodPlugin::LGitUtil
- Inherits:
-
Object
- Object
- LgPodPlugin::LGitUtil
- Defined in:
- lib/lg_pod_plugin/gitlab_download.rb
Class Method Summary collapse
-
.git_ls_remote_refs(name, git, branch, tag, commit) ⇒ Object
获取最新的一条 commit 信息.
Instance Method Summary collapse
-
#git_clone_repository(path) ⇒ Object
clone 代码仓库.
-
#initialize(name, options = {}) ⇒ LGitUtil
constructor
A new instance of LGitUtil.
-
#pre_download_git_repository ⇒ Object
git 预下载.
Constructor Details
#initialize(name, options = {}) ⇒ LGitUtil
Returns a new instance of LGitUtil.
18 19 20 21 22 23 24 25 |
# File 'lib/lg_pod_plugin/gitlab_download.rb', line 18 def initialize(name, = {}) self.name = name self.git = [:git] self.tag = [:tag] self.path = [:path] self.branch = [:branch] self.commit = [:commit] end |
Class Method Details
.git_ls_remote_refs(name, git, branch, tag, commit) ⇒ Object
获取最新的一条 commit 信息
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/lg_pod_plugin/gitlab_download.rb', line 92 def self.git_ls_remote_refs(name,git, branch, tag, commit) ip = LRequest.shared.net_ping.ip network_ok = LRequest.shared.net_ping.network_ok return [nil, nil] unless (ip && network_ok) if branch LgPodPlugin.log_blue "git ls-remote #{git} #{branch}" begin result = %x(timeout 5 git ls-remote #{git} #{branch}) rescue result = %x(git ls-remote #{git} #{branch}) end unless result && result != "" id = LPodLatestRefs.get_pod_id(name, git) pod_info = LSqliteDb.shared.query_pod_refs(id) new_commit = pod_info.commit if pod_info return [branch, new_commit] end new_commit, new_branch = LUtils.commit_from_ls_remote(result, branch) if new_commit LSqliteDb.shared.insert_pod_refs(name, git, branch, tag, new_commit) end return [branch, new_commit] elsif tag LgPodPlugin.log_blue "git ls-remote --tags #{git}" begin result = %x(timeout 5 git ls-remote --tags #{git}) rescue result = %x(git ls-remote --tags #{git}) end unless result && result != "" id = LPodLatestRefs.get_pod_id(name, git) pod_info = LSqliteDb.shared.query_pod_refs(id) new_commit = pod_info.commit if pod_info new_branch = pod_info.branch if pod_info return [new_branch, new_commit] end new_commit, new_branch = LUtils.commit_from_ls_remote(result, tag) if new_commit LSqliteDb.shared.insert_pod_refs(name, git, branch, tag, new_commit) end return [new_branch, new_commit] elsif commit return nil, commit else LgPodPlugin.log_blue "git ls-remote #{git}" begin result = %x(timeout 5 git ls-remote -- #{git}) rescue result = %x(git ls-remote -- #{git}) end unless result && result != "" id = LPodLatestRefs.get_pod_id(name, git) pod_info = LSqliteDb.shared.query_pod_refs(id) new_commit = pod_info.commit if pod_info new_branch = pod_info.branch if pod_info return [new_branch, new_commit] end new_commit, new_branch = LUtils.commit_from_ls_remote(result, "HEAD") if new_commit LSqliteDb.shared.insert_pod_refs(name, git, new_branch, tag, new_commit) end return [new_branch, new_commit] end end |
Instance Method Details
#git_clone_repository(path) ⇒ Object
clone 代码仓库
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/lg_pod_plugin/gitlab_download.rb', line 28 def git_clone_repository(path) FileUtils.chdir(path) temp_name = "lg_temp_pod" git_archive = GitLabArchive.new(self.name, self.git, self.branch, self.tag, self.commit) if self.git && self.tag begin if LUtils.is_use_gitlab_archive_file(self.git) return git_archive.gitlab_download_tag_zip(path, temp_name) elsif self.git.include?("https://github.com") return git_archive.github_download_tag_zip path, temp_name else return git_archive.git_clone_by_tag(path, temp_name) end rescue return git_archive.git_clone_by_tag(path, temp_name) end elsif self.git && self.branch begin if LUtils.is_use_gitlab_archive_file(self.git) return git_archive.gitlab_download_branch_zip(path, temp_name) elsif self.git.include?("https://github.com") return git_archive.github_download_branch_zip path, temp_name else return git_archive.git_clone_by_branch(path, temp_name) end rescue return git_archive.git_clone_by_branch(path, temp_name) end elsif self.git && self.commit if LUtils.is_use_gitlab_archive_file(self.git) return git_archive.gitlab_download_commit_zip(path, temp_name) elsif self.git.include?("https://github.com") return git_archive.github_download_commit_zip path, temp_name else return git_archive.git_clone_by_commit(path, temp_name) end elsif self.git if LUtils.is_use_gitlab_archive_file(self.git) return git_archive.gitlab_download_branch_zip(path, temp_name) elsif self.git.include?("https://github.com") return git_archive.github_download_branch_zip path, temp_name else return git_archive.git_clone_by_branch(path, temp_name) end end end |
#pre_download_git_repository ⇒ Object
git 预下载
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/lg_pod_plugin/gitlab_download.rb', line 77 def pre_download_git_repository temp_path = LFileManager.download_director.join("temp") FileUtils.rm_rf(temp_path) if temp_path.exist? lg_pod_path = LRequest.shared.cache.cache_root lg_pod_path.mkdir(0700) unless lg_pod_path.exist? get_temp_folder = git_clone_repository(lg_pod_path) #下载 git 仓库失败 return nil unless (get_temp_folder && get_temp_folder.exist?) LgPodPlugin::LCache.cache_pod(self.name, get_temp_folder, { :git => self.git }) if LRequest.shared.single_git LgPodPlugin::LCache.cache_pod(self.name, get_temp_folder, LRequest.shared.get_cache_key_params) FileUtils.chdir(LFileManager.download_director) FileUtils.rm_rf(lg_pod_path) end |