gitlab-mirror-pull 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/gitlab-mirror-pull +41 -15
- data/config.example.yml +5 -1
- data/lib/gitlab-mirror-pull.rb +61 -68
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b15d0e74a6360ab77acbe253ef27090096ffc09d804b344e4cea78bdc2f39c29
|
4
|
+
data.tar.gz: 222f13c94f457ff212bf22f177a1c456d9d21a6c66cb4c5fb8109f6be63c4a1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 776c4d83f81c23240b19acc8b060b6a6efdb6b4e329a54e714b7b6d430245d6b381d32f5e6488239ee42f329a257d157ccf2a2f07abe71a19624657f603b7ebd
|
7
|
+
data.tar.gz: 26d63570d46067220172d5902f9e372927f4377ffd98def24bf36accf00904fa4b3bbd85d68b3affc125927a0acc77a489d9a7b49a2e83a12b50a02a1d51feaf
|
data/bin/gitlab-mirror-pull
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
|
2
3
|
require_relative '../lib/gitlab-mirror-pull.rb'
|
3
4
|
|
4
5
|
options = {
|
5
|
-
|
6
|
-
|
6
|
+
:config => File.join(File.dirname(__FILE__), "../config.example.yml"),
|
7
|
+
:log_level => Logger::ERROR
|
7
8
|
}
|
8
9
|
|
9
10
|
# Parse commandline arguments
|
@@ -21,24 +22,29 @@ OptionParser.new do |opts|
|
|
21
22
|
opts.set_summary_width(50)
|
22
23
|
opts.define_head "Fetch gitlab repositories when remote set.
|
23
24
|
Default config #{File.join(File.dirname(__FILE__), "../config.example.yml")}\n\n"
|
24
|
-
|
25
|
+
|
25
26
|
# Config argument
|
26
27
|
opts.on("-c", "--config [config.yml]", "Specify config yaml") do |yml|
|
27
28
|
options[:config] = yml
|
28
29
|
end
|
29
30
|
|
31
|
+
# Run Webserver
|
32
|
+
opts.on("-r", "--run [server]", "Run webserver for gitlab webhooks") do |server|
|
33
|
+
options[:run] = server
|
34
|
+
end
|
35
|
+
|
30
36
|
# LogLevel argument
|
31
37
|
opts.on("-l", "--log-level [INFO|WARN|ERROR|DEBUG]", "Define log level") do |level|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
case level
|
39
|
+
when "INFO"
|
40
|
+
options[:log_level] = Logger::INFO
|
41
|
+
when "WARN"
|
42
|
+
options[:log_level] = Logger::WARN
|
43
|
+
when "ERROR"
|
44
|
+
options[:log_level] = Logger::ERROR
|
45
|
+
when "DEBUG"
|
46
|
+
options[:log_level] = Logger::DEBUG
|
47
|
+
end
|
42
48
|
end
|
43
49
|
|
44
50
|
opts.on_tail("-h", "--help", "Show this message") do
|
@@ -48,5 +54,25 @@ Default config #{File.join(File.dirname(__FILE__), "../config.example.yml")}\n\n
|
|
48
54
|
|
49
55
|
end.parse!
|
50
56
|
|
51
|
-
|
52
|
-
|
57
|
+
if options[:run] == 'server'
|
58
|
+
|
59
|
+
require 'sinatra'
|
60
|
+
require 'multi_json'
|
61
|
+
|
62
|
+
config = YAML.load_file(options[:config])
|
63
|
+
|
64
|
+
# Configure server
|
65
|
+
set :port, config['server']['port']
|
66
|
+
set :bind, config['server']['bind']
|
67
|
+
|
68
|
+
post '/commit' do
|
69
|
+
gitlab_json = MultiJson.load(request.body.read)
|
70
|
+
# File.join(File.dirname(__FILE__), "../config.example.yml")
|
71
|
+
repo_path = File.join(config['git']['repos'], gitlab_json['project']['namespace'].downcase, gitlab_json['project']['name'].downcase)
|
72
|
+
puts repo_path
|
73
|
+
end
|
74
|
+
|
75
|
+
else
|
76
|
+
# Run `git fetch` depending on options[:config]
|
77
|
+
GitlabMirrorPull.new(options[:config], options[:log_level])
|
78
|
+
end
|
data/config.example.yml
CHANGED
data/lib/gitlab-mirror-pull.rb
CHANGED
@@ -4,78 +4,71 @@ require 'logger'
|
|
4
4
|
require 'yaml'
|
5
5
|
|
6
6
|
class GitlabMirrorPull
|
7
|
-
|
8
|
-
attr_accessor :config, :log_level
|
9
|
-
|
10
|
-
# Parse commandline arguments
|
11
|
-
#
|
12
|
-
# == Parameters:
|
13
|
-
# config::
|
14
|
-
# Path to config file (e.g. ../config.example.yml)
|
15
|
-
#
|
16
|
-
# log_level::
|
17
|
-
# Set log level. Possible values: `Logger::INFO`, `Logger::WARN`, `Logger::ERROR`, `Logger::DEBUG`
|
18
|
-
#
|
19
|
-
# == Returns:
|
20
|
-
# Returns `@log` and `@config`
|
21
|
-
#
|
22
|
-
def initialize(config = File.join(File.dirname(__FILE__), "../config.example.yml"), log_level = Logger::ERROR)
|
23
|
-
|
24
|
-
# Configure Logger
|
25
|
-
@log = Logger.new(STDOUT)
|
26
|
-
@log.level = log_level
|
27
|
-
@config = YAML.load_file(config)
|
28
|
-
self.fetch_repositories
|
29
|
-
end
|
30
7
|
|
31
|
-
|
32
|
-
#
|
33
|
-
# == Returns:
|
34
|
-
# List of repositories to update using `git fetch`. Excludes `*.wiki` and repositories defined in `config.yml -> git -> repos`
|
35
|
-
#
|
36
|
-
def repositories_to_fetch
|
37
|
-
# Find all .git Repositories - Ignore *.wiki.git
|
38
|
-
repos = Dir.glob("#{config['git']['repos']}/*/*{[!.wiki]}.git")
|
39
|
-
|
40
|
-
# Build up array of NOT ignored repositories
|
41
|
-
delete_path = []
|
42
|
-
@config['ignore'].each do |ignored|
|
43
|
-
path = File.join(@config['git']['repos'], ignored)
|
44
|
-
delete_path += repos.grep /^#{path}/
|
45
|
-
repos.delete(delete_path)
|
46
|
-
end
|
47
|
-
|
48
|
-
return repos - delete_path
|
8
|
+
attr_accessor :config, :log_level
|
49
9
|
|
50
|
-
|
10
|
+
# Initialize class
|
11
|
+
#
|
12
|
+
# @param config Path to config file (e.g. ../config.example.yml)
|
13
|
+
# @param log_level Set log level. Possible values: `Logger::INFO`, `Logger::WARN`, `Logger::ERROR`, `Logger::DEBUG`
|
14
|
+
#
|
15
|
+
# @return Returns `@log` and `@config`
|
16
|
+
#
|
17
|
+
def initialize(config = File.join(File.dirname(__FILE__), "../config.example.yml"), log_level = Logger::ERROR)
|
51
18
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
# Init git settings
|
59
|
-
Git.configure do |config|
|
60
|
-
config.binary_path = "#{@config['git']['path']}"
|
61
|
-
end
|
19
|
+
# Configure Logger
|
20
|
+
@log = Logger.new(STDOUT)
|
21
|
+
@log.level = log_level
|
22
|
+
@config = YAML.load_file(config)
|
23
|
+
self.fetch_repositories
|
24
|
+
end
|
62
25
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
# Determine which "remote" to fetch e.g. "git fetch github"
|
71
|
-
if @config['provider'].include?("#{remote}")
|
72
|
-
@log.info("Fetching remote #{remote} in #{repo}")
|
73
|
-
g.remote(remote).fetch
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
26
|
+
# Prepare list of repositories
|
27
|
+
#
|
28
|
+
# @return List of repositories to update using `git fetch`. Excludes `*.wiki` and repositories defined in `config.yml -> git -> repos`
|
29
|
+
#
|
30
|
+
def repositories_to_fetch
|
31
|
+
# Find all .git Repositories - Ignore *.wiki.git
|
32
|
+
repos = Dir.glob("#{config['git']['repos']}/*/*{[!.wiki]}.git")
|
78
33
|
|
79
|
-
|
34
|
+
# Build up array of NOT ignored repositories
|
35
|
+
delete_path = []
|
36
|
+
@config['ignore'].each do |ignored|
|
37
|
+
path = File.join(@config['git']['repos'], ignored)
|
38
|
+
delete_path += repos.grep /^#{path}/
|
39
|
+
repos.delete(delete_path)
|
40
|
+
end
|
41
|
+
|
42
|
+
return repos - delete_path
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
# Fetch repositories return by `repositories_to_fetch`
|
47
|
+
#
|
48
|
+
# @return Logging infos on fetched repos
|
49
|
+
#
|
50
|
+
def fetch_repositories
|
51
|
+
# Init git settings
|
52
|
+
Git.configure do |config|
|
53
|
+
config.binary_path = "#{@config['git']['path']}"
|
54
|
+
end
|
55
|
+
|
56
|
+
# Loop through repos and fetch it
|
57
|
+
repos_to_fetch = self.repositories_to_fetch
|
58
|
+
repos_to_fetch.each do |repo|
|
59
|
+
if File.directory?(repo)
|
60
|
+
# Get branches
|
61
|
+
g = Git.bare("#{repo}", :log => @log)
|
62
|
+
g.remotes.each do |remote|
|
63
|
+
# Determine which "remote" to fetch e.g. "git fetch github"
|
64
|
+
if @config['provider'].include?("#{remote}")
|
65
|
+
@log.info("Fetching remote #{remote} in #{repo}")
|
66
|
+
g.remote(remote).fetch
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
80
73
|
|
81
74
|
end
|