summaryrefslogtreecommitdiff
path: root/backends/gitlab-ee
diff options
context:
space:
mode:
Diffstat (limited to 'backends/gitlab-ee')
-rwxr-xr-xbackends/gitlab-ee120
1 files changed, 63 insertions, 57 deletions
diff --git a/backends/gitlab-ee b/backends/gitlab-ee
index b69b1fc..5467e16 100755
--- a/backends/gitlab-ee
+++ b/backends/gitlab-ee
@@ -20,74 +20,80 @@ require 'uri'
require 'nokogiri'
class GitLabEE < GitLabCE
- def _mirrorURL
- unless @cache.has_key?(:mirror)
- req = Net::HTTP::Get.new(URI(_info["web_url"]+"/mirror"))
- req.add_field("PRIVATE-TOKEN", @api_key)
- con = _connection(req.uri)
- res = con.request(req)
- if res.code != "200"
- throw res
- end
- @cache[:mirror_res]=res
- doc = Nokogiri::HTML(res.body)
+ def project(project_id)
+ unless @projects.has_key?(project_id)
+ @projects[project_id] = Project.new(self, project_id)
+ end
+ return @projects[project_id]
+ end
+ class Project < GitLabCE::Project
+ def mirrorURL
+ unless @cache.has_key?(:mirror)
+ req = Net::HTTP::Get.new(URI(_info["web_url"]+"/mirror"))
+ req.add_field("PRIVATE-TOKEN", @api_key)
+ res = @gl.connection(req.uri).request(req)
+ if res.code != "200"
+ throw res
+ end
+ @cache[:mirror_res]=res
+ doc = Nokogiri::HTML(res.body)
- @cache[:mirror_cookie] = res["set-cookie"]
- @cache[:mirror_token] = doc.css('input[name="authenticity_token"]').first["value"]
- is_mirror = doc.css("#project_mirror").first["checked"]
- if !is_mirror
- @cache[:mirror] = nil
- else
- @cache[:mirror] = URI(doc.css("#project_import_url").first["value"])
+ @cache[:mirror_cookie] = res["set-cookie"]
+ @cache[:mirror_token] = doc.css('input[name="authenticity_token"]').first["value"]
+ is_mirror = doc.css("#project_mirror").first["checked"]
+ if !is_mirror
+ @cache[:mirror] = nil
+ else
+ @cache[:mirror] = URI(doc.css("#project_import_url").first["value"])
+ end
end
+ return @cache[:mirror]
end
- return @cache[:mirror]
- end
- def _mirrorURL=(url)
- _mirrorURL
+ def mirrorURL=(url)
+ self.mirrorURL()
- req = Net::HTTP::Patch.new(URI(_info["web_url"]+"/mirror"))
- req.add_field("PRIVATE-TOKEN", @api_key) # authenticate
- req.add_field("Cookie", @cache[:mirror_cookie]) # session id
- req.form_data = {
- "utf8" => "✓",
- "authenticity_token" => @cache[:mirror_token], # session state
- "project[mirror]" => (url.nil? ? "0" : "1"),
- "project[import_url]" => url.to_s,
- }
+ req = Net::HTTP::Patch.new(URI(self.info["web_url"]+"/mirror"))
+ req.add_field("PRIVATE-TOKEN", @gl.config['apikey']) # authenticate
+ req.add_field("Cookie", @cache[:mirror_cookie]) # session id
+ req.form_data = {
+ "utf8" => "✓",
+ "authenticity_token" => @cache[:mirror_token], # session state
+ "project[mirror]" => (url.nil? ? "0" : "1"),
+ "project[import_url]" => url.to_s,
+ }
- con = _connection(req.uri)
- res = con.request(req)
- if res.code != "302"
- throw res
- end
+ res = @gl.connection(req.uri).request(req)
+ if res.code != "302"
+ throw res
+ end
- @cache.delete(:mirror)
- @cache.delete(:mirror_token)
- @cache.delete(:mirror_cookie)
- return URI(url)
- end
+ @cache.delete(:mirror)
+ @cache.delete(:mirror_token)
+ @cache.delete(:mirror_cookie)
+ return URI(url)
+ end
- def cmd_get_meta
- map = super
- map["mirror"] = _mirrorURL.to_s
- return map
- end
+ def get_meta
+ map = super
+ map["mirror"] = self.mirrorURL.to_s
+ return map
+ end
- def cmd_set_meta(map)
- if map.has_key?("mirror")
- mirror = map["mirror"]
- map.delete("mirror")
- super(map)
- self._mirrorURL=url
- else
- super(map)
+ def set_meta(map)
+ if map.has_key?("mirror")
+ url = map["mirror"]
+ map.delete("mirror")
+ super(map)
+ self.mirrorURL = url
+ else
+ super(map)
+ end
end
- end
- def cmd_repo_mode
- return "active"
+ def repo_mode
+ return (self.mirrorURL.nil? ? "active" : "passive")
+ end
end
end