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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a5fc0a110fa694a431b08d1d858c624c8c52f73e56c34ae1e9225b9bf6680693
4
- data.tar.gz: aa5308fc8d5cf0fc08c0432f7e39cce7c1d92041906c5625894c71787a71216a
3
+ metadata.gz: 1baa55ddcda2d170f8130520fc2a25a382818a32bae8391d1564da225aa0b4cf
4
+ data.tar.gz: 60b841a9815cef4d58c88048f5e53ebcc78cc31c20144cd0a09370e2daa60f98
5
5
  SHA512:
6
- metadata.gz: fc1fb6e22c7235b1fbccbc13fbc9263a0f98f2412b4c7b58c4fd47d934f0d5321768eca04d8711209e45d86baa99a6f6487e97b6084f5e4117cc7d577ee20e6e
7
- data.tar.gz: 165ac2091fe71892595c936258a97cc2243573e3817170b67cd251210f9d8156e2a9c702fcf45c1f0b8164e73b332430bb4136c176fdd6f37e8f57c209841086
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
+ ```
@@ -1,3 +1,52 @@
1
1
  #!/usr/bin/env ruby
2
+ require_relative '../lib/gitlab-mirror-pull.rb'
2
3
 
3
- require_relative '../lib/gitlab-mirror-pull.rb'
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])
@@ -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
- # Parse commandline arguments
11
- options = {
12
- :config => File.join(File.dirname(__FILE__), "../config.example.yml"),
13
- :log_level => Logger::ERROR
14
- }
15
- OptionParser.new do |opts|
16
- opts.banner = "Usage: gitlab-mirror-pull.rb [options]"
17
- opts.set_summary_indent(' ')
18
- opts.set_summary_width(50)
19
- opts.define_head "Fetch gitlab repositories when remote set.
20
- Default config #{File.join(File.dirname(__FILE__), "../config.example.yml")}\n\n"
21
-
22
- # Config argument
23
- opts.on("-c", "--config [config.yml]", "Specify config yaml") do |yml|
24
- options[:config] = yml
25
- end
26
-
27
- # LogLevel argument
28
- opts.on("-l", "--log-level [INFO|WARN|ERROR|DEBUG]", "Define log level") do |level|
29
- case level
30
- when "INFO"
31
- log.level = Logger::INFO
32
- when "WARN"
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
- # Load config.yml
49
- yml = YAML.load_file(options[:config])
50
-
51
- # Init git settings
52
- Git.configure do |config|
53
- config.binary_path = "#{yml['git']['path']}"
54
- end
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
- # Find all .git Repositories - Ignore *.wiki.git
57
- repos = Dir.glob("#{yml['git']['repos']}/*/*{[!.wiki]}.git")
50
+ end
58
51
 
59
- # Build up array of NOT ignored repositories
60
- delete_path = []
61
- yml['ignore'].each do |ignored|
62
- path = File.join(yml['git']['repos'], ignored)
63
- delete_path += repos.grep /^#{path}/
64
- repos.delete(delete_path)
65
- end
66
- repos_to_fetch = repos - delete_path
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.each do |repo|
70
- if File.directory?(repo)
71
- # Get branches
72
- g = Git.bare("#{repo}", :log => log)
73
- g.remotes.each do |remote|
74
- # Determine which "remote" to fetch e.g. "git fetch github"
75
- if yml['provider'].include?("#{remote}")
76
- log.info("Fetching remote #{remote} in #{repo}")
77
- g.remote(remote).fetch
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
- end
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.1.6
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