gitlab-mirror-pull 0.1.6 → 0.2.0
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/README.md +45 -0
- data/bin/gitlab-mirror-pull +50 -1
- data/lib/gitlab-mirror-pull.rb +70 -70
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1baa55ddcda2d170f8130520fc2a25a382818a32bae8391d1564da225aa0b4cf
|
4
|
+
data.tar.gz: 60b841a9815cef4d58c88048f5e53ebcc78cc31c20144cd0a09370e2daa60f98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3dfd3c8fcda7925aefe071e3b545df7169f6d7b684a5357f7b37fbd5deb717b1d4d1a88b968663d46ca6fcb56c519874c6e7cb50aac125b93be957e0ace25aa
|
7
|
+
data.tar.gz: 4093eea445259d232ff45ced78320d628ff59e3ed147542a673827b095662d56a87f1570fe654af49cb9bcadf61324b89c44d88f400e79f5bc591f13285fa2d4
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
Fetch/update gitlab repositories automatically
|
2
|
+
==============================================
|
3
|
+
|
4
|
+
Description
|
5
|
+
-----------
|
6
|
+
|
7
|
+
Update your git repositories automatically when `remote` is set
|
8
|
+
|
9
|
+
Install
|
10
|
+
-------
|
11
|
+
|
12
|
+
- Clone repository: `git clone https://github.com/ochorocho/gitlab-mirror-pull.git`
|
13
|
+
- Run bundler: `bundle install`
|
14
|
+
- Copy and modify `config.example.yml` to `config.yml`
|
15
|
+
|
16
|
+
Run
|
17
|
+
---
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
ruby gitlab-mirror-pull.rb
|
21
|
+
```
|
22
|
+
|
23
|
+
Setup a CronJob
|
24
|
+
---------------
|
25
|
+
|
26
|
+
If you want to trigger periodically
|
27
|
+
|
28
|
+
```bash
|
29
|
+
0 */1 * * * /usr/bin/ruby /path/to/gitlab-mirror-pull.rb
|
30
|
+
```
|
31
|
+
|
32
|
+
Using 'gem install'
|
33
|
+
-------------------
|
34
|
+
|
35
|
+
Install
|
36
|
+
|
37
|
+
```bash
|
38
|
+
gem install gitlab-mirror-pull
|
39
|
+
```
|
40
|
+
|
41
|
+
Run
|
42
|
+
|
43
|
+
```bash
|
44
|
+
gitlab-mirror-pull -c /path/to/config.yml
|
45
|
+
```
|
data/bin/gitlab-mirror-pull
CHANGED
@@ -1,3 +1,52 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
require_relative '../lib/gitlab-mirror-pull.rb'
|
2
3
|
|
3
|
-
|
4
|
+
options = {
|
5
|
+
:config => File.join(File.dirname(__FILE__), "../config.example.yml"),
|
6
|
+
:log_level => Logger::ERROR
|
7
|
+
}
|
8
|
+
|
9
|
+
# Parse commandline arguments
|
10
|
+
#
|
11
|
+
# == Parameters:
|
12
|
+
# :config => File.join(File.dirname(__FILE__), "../config.example.yml"),
|
13
|
+
# :log_level => Logger::ERROR
|
14
|
+
#
|
15
|
+
# == Returns:
|
16
|
+
# Log output (default: ERROR)
|
17
|
+
#
|
18
|
+
OptionParser.new do |opts|
|
19
|
+
opts.banner = "Usage: gitlab-mirror-pull.rb [options]"
|
20
|
+
opts.set_summary_indent(' ')
|
21
|
+
opts.set_summary_width(50)
|
22
|
+
opts.define_head "Fetch gitlab repositories when remote set.
|
23
|
+
Default config #{File.join(File.dirname(__FILE__), "../config.example.yml")}\n\n"
|
24
|
+
|
25
|
+
# Config argument
|
26
|
+
opts.on("-c", "--config [config.yml]", "Specify config yaml") do |yml|
|
27
|
+
options[:config] = yml
|
28
|
+
end
|
29
|
+
|
30
|
+
# LogLevel argument
|
31
|
+
opts.on("-l", "--log-level [INFO|WARN|ERROR|DEBUG]", "Define log level") do |level|
|
32
|
+
case level
|
33
|
+
when "INFO"
|
34
|
+
options[:log_level] = Logger::INFO
|
35
|
+
when "WARN"
|
36
|
+
options[:log_level] = Logger::WARN
|
37
|
+
when "ERROR"
|
38
|
+
options[:log_level] = Logger::ERROR
|
39
|
+
when "DEBUG"
|
40
|
+
options[:log_level] = Logger::DEBUG
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
45
|
+
puts opts
|
46
|
+
exit
|
47
|
+
end
|
48
|
+
|
49
|
+
end.parse!
|
50
|
+
|
51
|
+
# Run `git fetch` depending on options[:config]
|
52
|
+
GitlabMirrorPull.new(options[:config],options[:log_level])
|
data/lib/gitlab-mirror-pull.rb
CHANGED
@@ -1,81 +1,81 @@
|
|
1
|
+
require 'optparse'
|
1
2
|
require 'git'
|
2
3
|
require 'logger'
|
3
4
|
require 'yaml'
|
4
|
-
require 'optparse'
|
5
|
-
|
6
|
-
# Configure Logger
|
7
|
-
log = Logger.new(STDOUT)
|
8
|
-
log.level = Logger::ERROR
|
9
5
|
|
10
|
-
|
11
|
-
|
12
|
-
:config
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
log.level = Logger::WARN
|
34
|
-
when "ERROR"
|
35
|
-
log.level = Logger::ERROR
|
36
|
-
else
|
37
|
-
log.level = Logger::DEBUG
|
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
|
38
29
|
end
|
39
|
-
end
|
40
|
-
|
41
|
-
opts.on_tail("-h", "--help", "Show this message") do
|
42
|
-
puts opts
|
43
|
-
exit
|
44
|
-
end
|
45
|
-
|
46
|
-
end.parse!
|
47
30
|
|
48
|
-
#
|
49
|
-
|
50
|
-
|
51
|
-
#
|
52
|
-
|
53
|
-
|
54
|
-
|
31
|
+
# Prepare list of repositories
|
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
|
55
49
|
|
56
|
-
|
57
|
-
repos = Dir.glob("#{yml['git']['repos']}/*/*{[!.wiki]}.git")
|
50
|
+
end
|
58
51
|
|
59
|
-
#
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
52
|
+
# Fetch repositories return by `repositories_to_fetch`
|
53
|
+
#
|
54
|
+
# == Returns:
|
55
|
+
# Logging infos on fetched repos
|
56
|
+
#
|
57
|
+
def fetch_repositories
|
58
|
+
# Init git settings
|
59
|
+
Git.configure do |config|
|
60
|
+
config.binary_path = "#{@config['git']['path']}"
|
61
|
+
end
|
67
62
|
|
68
|
-
# Loop through repos and fetch it
|
69
|
-
repos_to_fetch
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
63
|
+
# Loop through repos and fetch it
|
64
|
+
repos_to_fetch = self.repositories_to_fetch
|
65
|
+
repos_to_fetch.each do |repo|
|
66
|
+
if File.directory?(repo)
|
67
|
+
# Get branches
|
68
|
+
g = Git.bare("#{repo}", :log => @log)
|
69
|
+
g.remotes.each do |remote|
|
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
|
78
76
|
end
|
79
|
-
end
|
77
|
+
end
|
78
|
+
|
80
79
|
end
|
81
|
-
|
80
|
+
|
81
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitlab-mirror-pull
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ochorocho
|
@@ -38,6 +38,7 @@ executables:
|
|
38
38
|
extensions: []
|
39
39
|
extra_rdoc_files: []
|
40
40
|
files:
|
41
|
+
- README.md
|
41
42
|
- bin/gitlab-mirror-pull
|
42
43
|
- config.example.yml
|
43
44
|
- lib/gitlab-mirror-pull.rb
|