loadrunner 0.1.0 → 0.2.0

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
- SHA1:
3
- metadata.gz: 45e2aa0edf131bb75fdac7ac306131ba87791958
4
- data.tar.gz: b6380a094f0d73e15e3922b3b2caea0e90db56b6
2
+ SHA256:
3
+ metadata.gz: e03188ae2b98426dceaa6986c04cc177fd52756d7842440b17567912a6076959
4
+ data.tar.gz: 534fe583d3b7ade5df62bc79ebc46fc8083eb515f157e054dbede9619d3e8152
5
5
  SHA512:
6
- metadata.gz: a8775a42b092fb08485fdf72525ed2dcaa48f59f908f593c4ba8859a22739abdb671b0d3edfc92f3cc086198d875cccc5bc8322190f2202998846182506667be
7
- data.tar.gz: 3fe722e065dab62c742d337c006b2cd2ccea46920cd2a70692a645250d721d609b47574e5af23c1d0d50d040df22cb5afa64e3c760384eb04e397430a4ed65c5
6
+ metadata.gz: baa121b508967453f6fa27c758e07791de8fdadec5380b422b1ecf407eb85ed5a07f4e3b5148be9ca3c960f7fea0ad88d2380d0a8a527b61c9f0cb4e09616d8e
7
+ data.tar.gz: f6cda33832faf0e4ec94102e68fbb16eb6882050bb7c6145d271e97899d5711a925a238db7db7d1111560a09ff0d4fb663f4df08de7106ee75d927f7c59ab713
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  LoadRunner - GitHub Webhook Server and Event Simulator
2
2
  ======================================================
3
3
 
4
- [![Gem](https://img.shields.io/gem/v/loadrunner.svg?style=flat-square)](https://rubygems.org/gems/loadrunner)
5
- [![Travis](https://img.shields.io/travis/DannyBen/loadrunner.svg?style=flat-square)](https://travis-ci.org/DannyBen/loadrunner)
6
- [![Code Climate](https://img.shields.io/codeclimate/github/DannyBen/loadrunner.svg?style=flat-square)](https://codeclimate.com/github/DannyBen/loadrunner)
7
- [![Gemnasium](https://img.shields.io/gemnasium/DannyBen/loadrunner.svg?style=flat-square)](https://gemnasium.com/DannyBen/loadrunner)
4
+ [![Gem Version](https://badge.fury.io/rb/loadrunner.svg)](https://badge.fury.io/rb/loadrunner)
5
+ [![Build Status](https://travis-ci.org/DannyBen/loadrunner.svg?branch=master)](https://travis-ci.org/DannyBen/loadrunner)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/f1aae46eaf6365ea2ec7/maintainability)](https://codeclimate.com/github/DannyBen/loadrunner/maintainability)
7
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/f1aae46eaf6365ea2ec7/test_coverage)](https://codeclimate.com/github/DannyBen/loadrunner/test_coverage)
8
8
 
9
9
  ---
10
10
 
@@ -14,7 +14,7 @@ statuses.
14
14
  It provides these features:
15
15
 
16
16
  - A webserver that responds to GitHub webhook events and can run any
17
- arbitrary script writtn in any language.
17
+ arbitrary script written in any language.
18
18
  - A command line utility for testing your webhook server configuration by
19
19
  sending simulated events.
20
20
  - A command line utility for sending status updates to pull requests.
@@ -35,6 +35,7 @@ Getting Started
35
35
  $ mkdir -p handlers/myrepo
36
36
  $ echo "#\!/usr/bin/env bash" > handlers/myrepo/push
37
37
  $ echo "echo hello > output.txt" >> handlers/myrepo/push
38
+ $ chmod +x handlers/myrepo/push
38
39
 
39
40
  # Start the server
40
41
  $ loadrunner server
@@ -51,4 +52,21 @@ For more options, see the [documentation][1] or run
51
52
  $ loadrunner --help
52
53
 
53
54
 
55
+ Running with Docker
56
+ --------------------------------------------------
57
+
58
+ You can run both the server and the client using Docker.
59
+
60
+ # Server
61
+ $ docker run -p3000:3000 dannyben/loadrunner server
62
+
63
+ # Client
64
+ $ docker run dannyben/loadrunner send http://webhook.server.com/payload repo push
65
+
66
+ If you wish to connect the client to the server you are running through Docker,
67
+ you can do something like this:
68
+
69
+ $ docker run --network host dannyben/loadrunner send http://localhost:3000/payload repo push
70
+
71
+
54
72
  [1]: http://www.rubydoc.info/gems/loadrunner
data/bin/loadrunner CHANGED
@@ -3,7 +3,7 @@
3
3
  require 'loadrunner'
4
4
 
5
5
  begin
6
- LoadRunner::CommandLine.instance.execute ARGV
6
+ LoadRunner::CommandLine.execute ARGV
7
7
  rescue => e
8
8
  STDERR.puts "#{e.class} - #{e.message}"
9
9
  end
@@ -9,7 +9,7 @@ module LoadRunner
9
9
 
10
10
  def initialize(opts={})
11
11
  @secret_token = opts[:secret_token]
12
- @base_url = opts[:base_url] || 'localhost:3000'
12
+ @base_url = opts[:base_url] || 'localhost:3000/payload'
13
13
  self.class.base_uri base_url
14
14
  end
15
15
 
@@ -19,7 +19,7 @@ module LoadRunner
19
19
  # * +ref+: ref ID (for example +ref/heads/branchname+)
20
20
  # * +branch+: branch name
21
21
  # * +tag+: tag name
22
- def send(event=:push, opts={})
22
+ def send_event(event=:push, opts={})
23
23
  payload = build_payload opts
24
24
  send_payload event, payload
25
25
  end
@@ -28,7 +28,7 @@ module LoadRunner
28
28
  def send_payload(event, payload)
29
29
  @payload = payload.is_a?(String) ? payload : payload.to_json
30
30
  headers = headers event
31
- self.class.post "/payload", body: @payload, headers: headers
31
+ self.class.post "", body: @payload, headers: headers
32
32
  end
33
33
 
34
34
  private
@@ -1,41 +1,19 @@
1
- require 'singleton'
2
- require 'docopt'
1
+ require 'super_docopt'
3
2
  require 'colsole'
4
3
 
5
4
  module LoadRunner
6
5
 
7
6
  # Handles the command line interface
8
- class CommandLine
9
- include Singleton
7
+ class CommandLine < SuperDocopt::Base
10
8
  include Colsole
11
9
 
12
- attr_reader :args
13
-
14
- # Gets an array of arguments (e.g. ARGV), executes the command if valid
15
- # and shows usage patterns / help otherwise.
16
- def execute(argv=[])
17
- doc = File.read File.dirname(__FILE__) + '/docopt.txt'
18
- begin
19
- @args = Docopt::docopt(doc, argv: argv, version: VERSION)
20
- handle
21
- rescue Docopt::Exit => e
22
- puts e.message
23
- end
24
- end
25
-
26
- private
27
-
28
- # Called when the arguments match one of the usage patterns. Will
29
- # delegate action to other, more specialized methods.
30
- def handle
31
- return send if args['send']
32
- return status if args['status']
33
- return server if args['server']
34
- end
10
+ version VERSION
11
+ docopt File.expand_path 'docopt.txt', __dir__
12
+ subcommands [{'send' => 'send_event'}, 'status', 'server']
35
13
 
36
- def send
14
+ def send_event
37
15
  client = Client.new client_opts
38
- response = client.send args['EVENT'], payload_opts
16
+ response = client.send_event args['EVENT'], payload_opts
39
17
  show response
40
18
  end
41
19
 
@@ -54,10 +32,12 @@ module LoadRunner
54
32
  }
55
33
 
56
34
  response = api.status args['REPO'], args['SHA'], opts
57
-
35
+
58
36
  show response
59
37
  end
60
38
 
39
+ private
40
+
61
41
  def client_opts
62
42
  {
63
43
  base_url: args['URL'],
@@ -71,7 +51,7 @@ module LoadRunner
71
51
  def payload_opts
72
52
  result = { repo: args['REPO'] }
73
53
 
74
- ref = args['REF']
54
+ ref = args['REF'] || 'master'
75
55
  ref = "refs/tags/#{$1}" if ref =~ /^tag=(.+)/
76
56
  ref = "refs/heads/#{$1}" if ref =~ /^branch=(.+)/
77
57
  ref = "refs/heads/#{ref}" if ref !~ /^refs/
@@ -82,13 +62,19 @@ module LoadRunner
82
62
 
83
63
  # Print the response json to stdout, and the response code to stderr.
84
64
  def show(response)
85
- puts JSON.pretty_generate response
65
+ puts json_generate(response)
86
66
 
87
67
  if response.respond_to? :code
88
68
  code = response.code.to_s
89
69
  color = code =~ /^2\d\d/ ? :txtgrn : :txtred
90
- say! "!#{color}!Response Code: #{code}"
70
+ say "!#{color}!Response Code: #{code}"
91
71
  end
92
72
  end
73
+
74
+ def json_generate(object)
75
+ JSON.pretty_generate(JSON.parse object.to_s)
76
+ rescue
77
+ object.to_s
78
+ end
93
79
  end
94
80
  end
@@ -58,15 +58,18 @@ Options:
58
58
  A short description of the status.
59
59
 
60
60
  Environment Variables:
61
- GITHUB_SECRET_TOKEN=y0urAP1k3y
62
- Set Your GitHub secret token.
61
+ GITHUB_SECRET_TOKEN=y0urk3y
62
+ Set Your GitHub secret token as set in your webhook.
63
+
64
+ GITHUB_ACCESS_TOKEN=y0urAPIk3y
65
+ Set Your GitHub API token (needed only for status updates).
63
66
 
64
67
  Examples:
65
68
  # Simulate push events
66
- loadrunner send localhost:3000 my_repo push master
67
- loadrunner send localhost:3000 my_repo push branch=master
68
- loadrunner send localhost:3000 my_repo push tag=staging
69
- loadrunner send localhost:3000 my_repo push refs/tags/staging
69
+ loadrunner send localhost:3000/payload my_repo push master
70
+ loadrunner send localhost:3000/payload my_repo push branch=master
71
+ loadrunner send localhost:3000/payload my_repo push tag=staging
72
+ loadrunner send localhost:3000/payload my_repo push refs/tags/staging
70
73
 
71
74
  # Start the server
72
75
  loadrunner server
@@ -15,7 +15,7 @@ module LoadRunner
15
15
 
16
16
  signature = request.env['HTTP_X_HUB_SIGNATURE']
17
17
  state = verify_signature payload_body, signature
18
-
18
+
19
19
  halt 401, halt_messages[state] if state != :ok
20
20
 
21
21
  push = ActiveSupport::HashWithIndifferentAccess.new JSON.parse payload_body
@@ -13,7 +13,9 @@ module LoadRunner
13
13
  set :server, :puma
14
14
 
15
15
  configure :development do
16
+ # :nocov: - this is not covered in CI, but is covered in dev
16
17
  register Sinatra::Reloader if defined? Sinatra::Reloader
18
+ # :nocov:
17
19
  end
18
20
 
19
21
  # Since we cannot use any config values in the main body of the class,
@@ -1,3 +1,3 @@
1
1
  module LoadRunner
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/loadrunner.rb CHANGED
@@ -11,3 +11,5 @@ require 'load_runner/server'
11
11
  require 'load_runner/client'
12
12
 
13
13
  require 'load_runner/command_line'
14
+
15
+ require 'byebug' if ENV['BYEBUG']
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loadrunner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-18 00:00:00.000000000 Z
11
+ date: 2018-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: super_docopt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: httparty
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +52,20 @@ dependencies:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
54
  version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sinatra-contrib
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: puma
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -150,20 +178,6 @@ dependencies:
150
178
  - - "~>"
151
179
  - !ruby/object:Gem::Version
152
180
  version: '9.0'
153
- - !ruby/object:Gem::Dependency
154
- name: sinatra-contrib
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - "~>"
158
- - !ruby/object:Gem::Version
159
- version: '2.0'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - "~>"
165
- - !ruby/object:Gem::Version
166
- version: '2.0'
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: rack-test
169
183
  requirement: !ruby/object:Gem::Requirement
@@ -232,7 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
232
246
  version: '0'
233
247
  requirements: []
234
248
  rubyforge_project:
235
- rubygems_version: 2.6.11
249
+ rubygems_version: 2.7.6
236
250
  signing_key:
237
251
  specification_version: 4
238
252
  summary: GitHub Webhook Server and Simulator