gitlab-mirror-pull 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/gitlab-mirror-pull.rb +72 -0
  3. metadata +46 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4af41fc1c41e14d34367014cab5ccf7510d34b5e
4
+ data.tar.gz: f0ef042a4405eb2f28fe1b62988cdbcf36e1d9d7
5
+ SHA512:
6
+ metadata.gz: f9d654a421e15ad1cfa3eaccda2033b8c28fb2772bc18548475336bbfaffd01d728f810f33ff711b9071828c00948cf55ace04e309eb6a32949aac125b88525f
7
+ data.tar.gz: 6700eb57244f6b4a40aa23412b691e609642b9fc32575ce92eb69e3b7474060d584d64d2a6f4dee8d0dece7bced0a4dfef609d40d12dc28b671e89b4d03c8d33
@@ -0,0 +1,72 @@
1
+ require 'git'
2
+ require 'logger'
3
+ require 'yaml'
4
+ require 'optparse'
5
+
6
+ # Configure Logger
7
+ log = Logger.new(STDOUT)
8
+ log.level = Logger::ERROR
9
+
10
+ # Parse commandline arguments
11
+ options = {
12
+ :config => File.join(File.dirname(__FILE__), "../config.yml"),
13
+ :log_level => Logger::ERROR
14
+ }
15
+ OptionParser.new do |opts|
16
+ opts.banner = "Usage: gitlab-mirror-pull.rb [options]"
17
+
18
+ # Config argument
19
+ opts.on("-c", "--config [config.yml]", "Specify config yaml") do |yml|
20
+ options[:config] = yml
21
+ end
22
+
23
+ # LogLevel argument
24
+ opts.on("-l", "--log-level INFO|WARN|ERROR|DEBUG", "Define log level") do |level|
25
+ case level
26
+ when "INFO"
27
+ log.level = Logger::INFO
28
+ when "WARN"
29
+ log.level = Logger::WARN
30
+ when "ERROR"
31
+ log.level = Logger::ERROR
32
+ else
33
+ log.level = Logger::DEBUG
34
+ end
35
+ end
36
+
37
+ end.parse!
38
+
39
+ # Load config.yml
40
+ yml = YAML.load_file(options[:config])
41
+
42
+ # Init git settings
43
+ Git.configure do |config|
44
+ config.binary_path = "#{yml['git']['path']}"
45
+ end
46
+
47
+ # Find all .git Repositories - Ignore *.wiki.git
48
+ repos = Dir.glob("#{yml['git']['repos']}/*/*{[!.wiki]}.git")
49
+
50
+ # Build up array of NOT ignored repositories
51
+ delete_path = []
52
+ yml['ignore'].each do |ignored|
53
+ path = File.join(yml['git']['repos'], ignored)
54
+ delete_path += repos.grep /^#{path}/
55
+ repos.delete(delete_path)
56
+ end
57
+ repos_to_fetch = repos - delete_path
58
+
59
+ # Loop through repos and fetch it
60
+ repos_to_fetch.each do |repo|
61
+ if File.directory?(repo)
62
+ # Get branches
63
+ g = Git.bare("#{repo}", :log => log)
64
+ g.remotes.each do |remote|
65
+ # Determine which "remote" to fetch e.g. "git fetch github"
66
+ if yml['provider'].include?("#{remote}")
67
+ log.info("Fetching remote #{remote} in #{repo}")
68
+ g.remote(remote).fetch
69
+ end
70
+ end
71
+ end
72
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gitlab-mirror-pull
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ochorocho
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-06-11 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Checks for repositories with a set remote and run git fetch on these
14
+ ...
15
+ email: rothjochen@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/gitlab-mirror-pull.rb
21
+ homepage: https://github.com/ochorocho/gitlab-mirror-pull
22
+ licenses:
23
+ - MIT
24
+ metadata:
25
+ source_code_uri: https://github.com/ochorocho/gitlab-mirror-pull
26
+ post_install_message: Cheers mate!
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.5.2.1
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Fetch repos from remote if set
46
+ test_files: []