loadrunner 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: e03188ae2b98426dceaa6986c04cc177fd52756d7842440b17567912a6076959
4
- data.tar.gz: 534fe583d3b7ade5df62bc79ebc46fc8083eb515f157e054dbede9619d3e8152
3
+ metadata.gz: f956c6c96502b4a447c61d0ba22965de6384a5388979160538eadf19554a60a1
4
+ data.tar.gz: d34ffbdb98ecf2c288655456ac527ef56ebf87cbaa8d6c8849cfc3acca33e656
5
5
  SHA512:
6
- metadata.gz: baa121b508967453f6fa27c758e07791de8fdadec5380b422b1ecf407eb85ed5a07f4e3b5148be9ca3c960f7fea0ad88d2380d0a8a527b61c9f0cb4e09616d8e
7
- data.tar.gz: f6cda33832faf0e4ec94102e68fbb16eb6882050bb7c6145d271e97899d5711a925a238db7db7d1111560a09ff0d4fb663f4df08de7106ee75d927f7c59ab713
6
+ metadata.gz: cfc5af284ca6ad9dd20a8c24debce0d774653a30dfbcdce33f8afbda5fb192a9afc8e2e22045dab4c12cb5f598f1f22bf32d2a58b509d00ffb5b73190d807f4d
7
+ data.tar.gz: 5f62450212ac311be7baad8ee8c55729d6f026e351766e5e252977655453a6b8a034321991dd1e3bde1fddeb80801cd54e6551a4515e78441f1c74c44313fd30
data/README.md CHANGED
@@ -69,4 +69,4 @@ you can do something like this:
69
69
  $ docker run --network host dannyben/loadrunner send http://localhost:3000/payload repo push
70
70
 
71
71
 
72
- [1]: http://www.rubydoc.info/gems/loadrunner
72
+ [1]: http://www.rubydoc.info/gems/loadrunner
@@ -1,15 +1,17 @@
1
1
  require 'httparty'
2
+ require 'uri'
2
3
 
3
4
  module LoadRunner
4
5
 
5
6
  # Send simulated GitHub events to any webhook server
6
7
  class Client
7
8
  include HTTParty
8
- attr_accessor :secret_token, :base_url, :payload
9
+ attr_accessor :secret_token, :base_url, :payload, :encoding
9
10
 
10
11
  def initialize(opts={})
11
12
  @secret_token = opts[:secret_token]
12
13
  @base_url = opts[:base_url] || 'localhost:3000/payload'
14
+ @encoding = opts[:encoding] || :json
13
15
  self.class.base_uri base_url
14
16
  end
15
17
 
@@ -27,8 +29,8 @@ module LoadRunner
27
29
  # Send a simulated event. Payload can be a hash or a JSON string.
28
30
  def send_payload(event, payload)
29
31
  @payload = payload.is_a?(String) ? payload : payload.to_json
30
- headers = headers event
31
- self.class.post "", body: @payload, headers: headers
32
+ @payload = URI.encode_www_form(payload: @payload) if encoding == :form
33
+ self.class.post "", body: @payload, headers: headers(event)
32
34
  end
33
35
 
34
36
  private
@@ -37,6 +39,7 @@ module LoadRunner
37
39
  {}.tap do |header|
38
40
  header['X_GITHUB_EVENT'] = event.to_s if event
39
41
  header['X_HUB_SIGNATURE'] = signature if secret_token
42
+ header['Content-Type'] = content_type[encoding]
40
43
  end
41
44
  end
42
45
 
@@ -71,5 +74,12 @@ module LoadRunner
71
74
  end
72
75
  end
73
76
 
77
+ def content_type
78
+ {
79
+ json: 'application/json',
80
+ form: 'application/x-www-form-urlencoded',
81
+ }
82
+ end
83
+
74
84
  end
75
85
  end
@@ -41,7 +41,8 @@ module LoadRunner
41
41
  def client_opts
42
42
  {
43
43
  base_url: args['URL'],
44
- secret_token: ENV['GITHUB_SECRET_TOKEN']
44
+ secret_token: ENV['GITHUB_SECRET_TOKEN'],
45
+ encoding: args['--form'] ? :form : :json
45
46
  }
46
47
  end
47
48
 
@@ -2,7 +2,7 @@ LoadRunner
2
2
 
3
3
  Usage:
4
4
  loadrunner server [--port N --bind IP]
5
- loadrunner send URL REPO EVENT [REF]
5
+ loadrunner send URL REPO EVENT [REF --form]
6
6
  loadrunner status REPO SHA STATE [--context TEXT --desc TEXT --url URL]
7
7
  loadrunner (-h|--help|--version)
8
8
 
@@ -18,8 +18,9 @@ Commands:
18
18
 
19
19
  Parameters:
20
20
  URL
21
- The URL of the webhook server. This server should have a /payload
22
- endpoint that responds to POST requests.
21
+ The URL of the webhook endpoint. This path should responds
22
+ to POST requests. If you are sending an event to a loadrunner server,
23
+ send it to the /payload endpoint (e.g. localhost:3000/payload).
23
24
 
24
25
  REPO
25
26
  The name of the repository. This can be either the short name
@@ -57,6 +58,9 @@ Options:
57
58
  --desc TEXT
58
59
  A short description of the status.
59
60
 
61
+ --form
62
+ Send request as x-www-form-urlencoded instead of sending JSON.
63
+
60
64
  Environment Variables:
61
65
  GITHUB_SECRET_TOKEN=y0urk3y
62
66
  Set Your GitHub secret token as set in your webhook.
@@ -68,7 +72,7 @@ Examples:
68
72
  # Simulate push events
69
73
  loadrunner send localhost:3000/payload my_repo push master
70
74
  loadrunner send localhost:3000/payload my_repo push branch=master
71
- loadrunner send localhost:3000/payload my_repo push tag=staging
75
+ loadrunner send localhost:3000/payload my_repo push tag=staging --form
72
76
  loadrunner send localhost:3000/payload my_repo push refs/tags/staging
73
77
 
74
78
  # Start the server
@@ -18,7 +18,12 @@ module LoadRunner
18
18
 
19
19
  halt 401, halt_messages[state] if state != :ok
20
20
 
21
- push = ActiveSupport::HashWithIndifferentAccess.new JSON.parse payload_body
21
+ if request.content_type == 'application/json'
22
+ json_string = payload_body
23
+ else
24
+ json_string = URI.decode_www_form(payload_body).to_h["payload"]
25
+ end
26
+ push = ActiveSupport::HashWithIndifferentAccess.new JSON.parse json_string
22
27
 
23
28
  opts = {}
24
29
  opts[:repo] = push.dig(:repository, :name)
@@ -1,3 +1,3 @@
1
1
  module LoadRunner
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loadrunner
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
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-23 00:00:00.000000000 Z
11
+ date: 2018-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: super_docopt