gurney_client 0.1.1 → 0.1.6

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: 64bb60a1de5168633f0f1fd0605030edffe46440472dfdf64bbb56862f40f3d4
4
- data.tar.gz: 3a95353020d09220c0dd989c59f8d4ff84579b2da7795a2fef630e5ca42d688e
3
+ metadata.gz: bb46098ee5a2a49bdccf9bb4d5db373b2ce5847ae1398f30fe2a676a9d732b07
4
+ data.tar.gz: 78b5b151888f590897f8869ae6d30788b4d4398ff122ef63525fd4048cb1bbd0
5
5
  SHA512:
6
- metadata.gz: 1967532e08ba47400be443ce8bdbd65b1690fc6dc75d1f35d6e5121dcd02b5948ff97c870cd60395c5b83288c432bc25db2f1bb9732286cb6e3da629ca2139a0
7
- data.tar.gz: b44ded67b9c21e227ba567722ca27546319590b6c5c895d2b1950455704ac45f34a843402b003f7618af348f298483cf861887697ec7cd8023f95ddbfeb0d349
6
+ metadata.gz: 0e1bf0ed5a79b112999cd347f383de248a2fbb5ff0c85a0ef1250e19bafde7b089f6e94b04b19d1c39f17791b6db0cf452bceb03b2d43e2d60beb4cc940305ec
7
+ data.tar.gz: c007024b0dc4197d983c66ba8182f7847fb04b4af8650cc6597f30f5fee5f89f7cd3e0bf16d92bfa47af276edb0dfcf2545752d61370498887b63cfa66c917f0
data/Gemfile CHANGED
@@ -1,8 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'colorize'
4
- gem 'httparty'
3
+ gemspec
4
+
5
5
  gem 'rspec'
6
6
  gem 'byebug'
7
- gem 'bundler'
8
- gem 'git'
data/Gemfile.lock CHANGED
@@ -1,3 +1,12 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gurney_client (0.1.6)
5
+ bundler (< 3)
6
+ colorize (~> 0.8)
7
+ git (~> 1.5)
8
+ httparty (~> 0.17.1)
9
+
1
10
  GEM
2
11
  remote: https://rubygems.org/
3
12
  specs:
@@ -30,11 +39,8 @@ PLATFORMS
30
39
  ruby
31
40
 
32
41
  DEPENDENCIES
33
- bundler
34
42
  byebug
35
- colorize
36
- git
37
- httparty
43
+ gurney_client!
38
44
  rspec
39
45
 
40
46
  BUNDLED WITH
data/README.md CHANGED
@@ -17,6 +17,8 @@ Usage: gurney [options]
17
17
  Token to be send to the api in the X-AuthToken header
18
18
  -c, --config [CONFIG FILE] Config file to use
19
19
  -h, --hook Run as a git post-receive hook
20
+ --client-hook
21
+ Run as a git pre-push hook
20
22
  -p, --project-id [PROJECT ID] Specify project id for api
21
23
  --help
22
24
  Prints this help
data/lib/gurney/cli.rb CHANGED
@@ -4,12 +4,12 @@ require 'colorize'
4
4
  require 'open3'
5
5
  require 'git'
6
6
  require 'fileutils'
7
- require 'byebug'
8
7
 
9
8
  module Gurney
10
9
  class CLI
11
10
 
12
11
  HOOK_STDIN_REGEX = /(?<old>[0-9a-f]{40}) (?<new>[0-9a-f]{40}) refs\/heads\/(?<ref>\w+)/m
12
+ CLIENT_HOOK_STDIN_REGEX = /refs\/heads\/(?<ref>\w+) (?<new>[0-9a-f]{40}) refs\/heads\/(?<remote_ref>\w+) (?<remote_sha>[0-9a-f]{40})/m
13
13
 
14
14
  def self.run(cmd_parameter=[])
15
15
  options = Gurney::CLI::OptionParser.parse(cmd_parameter)
@@ -31,6 +31,7 @@ module Gurney
31
31
  config_file ||= '---'
32
32
  config = Gurney::Config.from_yaml(config_file)
33
33
 
34
+ options.branches ||= config&.branches
34
35
  options.branches ||= config&.branches
35
36
  options.api_token ||= config&.api_token
36
37
  options.api_url ||= config&.api_url
@@ -41,11 +42,12 @@ module Gurney
41
42
  end
42
43
 
43
44
  branches = []
44
- if options.hook
45
+ if options.hook || options.client_hook
45
46
  # we get passed changed branches and refs via stdin
46
47
  $stdin.each_line do |line|
47
- matches = line.match(HOOK_STDIN_REGEX)
48
- unless matches[:new] == '0' * 40
48
+ regex = options.client_hook ? CLIENT_HOOK_STDIN_REGEX : HOOK_STDIN_REGEX
49
+ matches = line.match(regex)
50
+ if matches && matches[:new] != '0' * 40
49
51
  if options.branches.include? matches[:ref]
50
52
  branches << matches[:ref]
51
53
  end
@@ -63,10 +65,10 @@ module Gurney
63
65
  branches.each do |branch|
64
66
  dependencies = []
65
67
 
66
- yarn_source = Gurney::Source::Yarn.new(yarn_lock: read_file(g, options.hook, branch, 'yarn.lock'))
68
+ yarn_source = Gurney::Source::Yarn.new(yarn_lock: read_file(g, options.hook || options.client_hook, branch, 'yarn.lock'))
67
69
  dependencies.concat yarn_source.dependencies || []
68
70
 
69
- bundler_source = Gurney::Source::Bundler.new(gemfile_lock: read_file(g, options.hook, branch, 'Gemfile.lock'))
71
+ bundler_source = Gurney::Source::Bundler.new(gemfile_lock: read_file(g, options.hook || options.client_hook, branch, 'Gemfile.lock'))
70
72
  dependencies.concat bundler_source.dependencies || []
71
73
 
72
74
  dependencies.compact!
@@ -87,7 +89,7 @@ module Gurney
87
89
  puts e.message.red
88
90
  rescue Exception => e
89
91
  puts "Gurney: an unexpected error occurred".red
90
- puts "#{e.full_message}"
92
+ raise
91
93
  end
92
94
  end
93
95
 
@@ -95,8 +97,10 @@ module Gurney
95
97
 
96
98
  def self.read_file(git, from_git, branch, filename)
97
99
  if from_git
98
- if git.ls_tree(branch)['blob'].key?(filename)
99
- return git.show("#{branch}:#{filename}")
100
+ begin
101
+ git.show("#{branch}:#{filename}")
102
+ rescue Git::GitExecuteError
103
+ # happens if branch does not exist
100
104
  end
101
105
  else
102
106
  if File.exists? filename
@@ -8,6 +8,7 @@ module Gurney
8
8
  def self.parse(args)
9
9
  options = OpenStruct.new
10
10
  options.hook = false
11
+ options.client_hook = false
11
12
  options.config_file = 'gurney.yml'
12
13
 
13
14
  option_parser = ::OptionParser.new do |opts|
@@ -20,7 +21,7 @@ module Gurney
20
21
  options.api_url = api_url
21
22
  end
22
23
 
23
- opts.on('', '--api-token [API TOKEN]', 'Token to be send to api in the X-AuthToken header') do |api_token|
24
+ opts.on('', '--api-token [API TOKEN]', 'Token to be send to the api in the X-AuthToken header') do |api_token|
24
25
  options.api_token = api_token
25
26
  end
26
27
 
@@ -32,6 +33,10 @@ module Gurney
32
33
  options.hook = hook
33
34
  end
34
35
 
36
+ opts.on('', '--client-hook', 'Run as a git pre-push hook') do |client_hook|
37
+ options.client_hook = client_hook
38
+ end
39
+
35
40
  opts.on('-p', '--project-id [PROJECT ID]', 'Specify project id for api') do |project_id|
36
41
  options.project_id = project_id
37
42
  end
@@ -1,3 +1,3 @@
1
1
  module Gurney
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gurney_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Schaflitzl
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-18 00:00:00.000000000 Z
11
+ date: 2019-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize