diff options
-rwxr-xr-x | backends/github | 1 | ||||
-rw-r--r-- | git-mirror-backend.rb (renamed from backends/gitmirrorbackend.rb) | 0 | ||||
-rwxr-xr-x | git-mirror-cgit | 69 | ||||
-rwxr-xr-x | git-mirror-gitlab-ce (renamed from backends/gitlab-ce) | 5 | ||||
-rwxr-xr-x | git-mirror-gitlab-ee (renamed from backends/gitlab-ee) | 0 |
5 files changed, 70 insertions, 5 deletions
diff --git a/backends/github b/backends/github deleted file mode 100755 index 49ffd26..0000000 --- a/backends/github +++ /dev/null @@ -1 +0,0 @@ -#!/usr/bin/env ruby diff --git a/backends/gitmirrorbackend.rb b/git-mirror-backend.rb index 25f7c3e..25f7c3e 100644 --- a/backends/gitmirrorbackend.rb +++ b/git-mirror-backend.rb diff --git a/git-mirror-cgit b/git-mirror-cgit new file mode 100755 index 0000000..8c1b799 --- /dev/null +++ b/git-mirror-cgit @@ -0,0 +1,69 @@ +#!/usr/bin/env ruby +# coding: utf-8 + +load 'git-mirror-backend.rb' +require 'uri' +require 'open-uri' +require 'nokogiri' + +class Cgit < GitMirrorBackend + def initialize() + @config = {} + end + + def cmd_config(*args) + args.each do |arg| + key, val = arg.split('=', 2) + case key + when "url" + val = URI(val) + unless val.path.end_with?("/") + val.path += "/" + end + end + @config[key] = val + end + end + + def cmd_get_meta(path) + doc = Nokogiri::HTML(open(@config[url]+path)) + head = open(@config[url]+path+'/HEAD').read + return { + 'description' => doc.css('#header .sub')[0].text, + 'owner' => doc.css('#header .sub')[1].text, + 'default_branch' => head.split("\n")[0].sub(/^ref: /, '').sub(/^refs\/heads\//, ''), + } + end + + def cmd_set_meta(path, *pairs) + raise "no can do" + end + + def urls(path) + doc = Nokogiri::HTML(open(@config[url]+path)) + return doc.css('a[rel="vcs-git"]').map{|a| a['href']} + end + + def cmd_push_url(path) + prefs = ['ssh', 'https', 'http', 'git'] + return self.urls.sort_by{|url| prefs.index(url)} + end + + def cmd_pull_url(path) + # prefer https ahead of git because of a bug in git-daemon + # with '~'. + prefs = ['https', 'git', 'http', 'ssh'] + return self.urls.sort_by{|url| prefs.index(url)} + end + + def cmd_repo_mode(path) + return "passive" + end +end + +if __FILE__ == $0 + if ARGV.length != 1 + throw "Usage: $0 ACCOUNT_NAME" + end + Cgit.new().repl(ARGV[1]) +end diff --git a/backends/gitlab-ce b/git-mirror-gitlab-ce index 84cb933..a8d885e 100755 --- a/backends/gitlab-ce +++ b/git-mirror-gitlab-ce @@ -1,10 +1,7 @@ #!/usr/bin/env ruby # coding: utf-8 -# http://docs.gitlab.com/ee/workflow/repository_mirroring.html -# https://gitlab.com/gitlab-org/gitlab-ee/issues/767 - -load 'gitmirrorbackend.rb' +load 'git-mirror-backend.rb' require 'net/http' require 'uri' require 'cgi' diff --git a/backends/gitlab-ee b/git-mirror-gitlab-ee index 5467e16..5467e16 100755 --- a/backends/gitlab-ee +++ b/git-mirror-gitlab-ee |