gitlab-mirror-pull 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1baa55ddcda2d170f8130520fc2a25a382818a32bae8391d1564da225aa0b4cf
4
- data.tar.gz: 60b841a9815cef4d58c88048f5e53ebcc78cc31c20144cd0a09370e2daa60f98
3
+ metadata.gz: b15d0e74a6360ab77acbe253ef27090096ffc09d804b344e4cea78bdc2f39c29
4
+ data.tar.gz: 222f13c94f457ff212bf22f177a1c456d9d21a6c66cb4c5fb8109f6be63c4a1d
5
5
  SHA512:
6
- metadata.gz: f3dfd3c8fcda7925aefe071e3b545df7169f6d7b684a5357f7b37fbd5deb717b1d4d1a88b968663d46ca6fcb56c519874c6e7cb50aac125b93be957e0ace25aa
7
- data.tar.gz: 4093eea445259d232ff45ced78320d628ff59e3ed147542a673827b095662d56a87f1570fe654af49cb9bcadf61324b89c44d88f400e79f5bc591f13285fa2d4
6
+ metadata.gz: 776c4d83f81c23240b19acc8b060b6a6efdb6b4e329a54e714b7b6d430245d6b381d32f5e6488239ee42f329a257d157ccf2a2f07abe71a19624657f603b7ebd
7
+ data.tar.gz: 26d63570d46067220172d5902f9e372927f4377ffd98def24bf36accf00904fa4b3bbd85d68b3affc125927a0acc77a489d9a7b49a2e83a12b50a02a1d51feaf
@@ -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
- :config => File.join(File.dirname(__FILE__), "../config.example.yml"),
6
- :log_level => Logger::ERROR
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
- 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
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
- # Run `git fetch` depending on options[:config]
52
- GitlabMirrorPull.new(options[:config],options[:log_level])
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
@@ -7,4 +7,8 @@ ignore:
7
7
  provider: # provider equals to "remote" set in your repository
8
8
  - "github"
9
9
  - "gitlab"
10
-
10
+ server:
11
+ port: 8088
12
+ bind: "localhost"
13
+ redis:
14
+ socket: "/var/run/redis/redis.sock"
@@ -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
- # 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
8
+ attr_accessor :config, :log_level
49
9
 
50
- end
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
- # 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
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
- # 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
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
- end
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
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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ochorocho