loadrunner 0.3.1 → 0.4.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
2
  SHA256:
3
- metadata.gz: 3102e254b9713df61278cc81259d547f73d20015f83ee2f0ea1bb6f2399aa3c3
4
- data.tar.gz: 714019cdae31109069f3d615dc21a18685317eb21edafeff91ab0ff58e8bd80d
3
+ metadata.gz: d79a3a28613d0ed9bb71220d16f44796bdf2e4b4b20eeb2c463df46ac8b10837
4
+ data.tar.gz: 82a2d95737162857f764a7ab87745fcc504fb8544066ec3037c7b1985a2e1891
5
5
  SHA512:
6
- metadata.gz: 0547d09f0b585f3456dcdc1acc65ffc5b410108715db8a240870d6ce5b787660cfc04de3e854a58df6bd5c33292031f4373fb37564c2954fdd2851e9ceec5375
7
- data.tar.gz: 10d21050595e15ecd56216bea4aeaa908ac17dbf9f0dfda0be7750e37adf1bfb5346778fb4a6696dc59b80f4d969946a7032dc3650cd279e28e1356c32a2b2e8
6
+ metadata.gz: 61a9ca38c6a7a2622d30e5e089fe4b442d6c74355f11592310945da3298241349328787c18758a303956e1477779216a367a3c438049c01be21ccaafd89acbc7
7
+ data.tar.gz: d47d260866de2fb6909142b9887563ef0826b8598fa7879454807f8d2c43edd1db2191d07a35370e2d13c98cbaa53edb970fb02d4fd2c8019f571b08fe0d6781
data/README.md CHANGED
@@ -35,21 +35,18 @@ $ gem install loadrunner
35
35
  Getting Started
36
36
  --------------------------------------------------
37
37
 
38
- ```shell
39
- # Create a sample hook handler
40
- $ mkdir -p handlers/myrepo
41
- $ echo '#!/usr/bin/env bash' > handlers/myrepo/push
42
- $ echo 'echo hello > output.txt' >> handlers/myrepo/push
43
- $ chmod +x handlers/myrepo/push
44
-
45
- # Start the server
46
- $ loadrunner server
47
-
48
- # In another terminal, send a sample webhook event
49
- $ loadrunner event localhost:3000 myrepo push master
50
-
51
- # Verify the handler was executed
52
- $ cat output.txt
38
+ 1. Download the [handlers](handlers) directory from this repository, as an
39
+ exmaple. This directory contains several handler examples.
40
+ 2. Make sure that all files within that folder are executables.
41
+ 3. Start the server (from the `handlers` **parent** directory):
42
+ `loadrunner server`
43
+ 4. In another terminal, send a sample webhook event:
44
+ `loadrunner event localhost:3000/payload myrepo push master
45
+
46
+ The server should respond with a detailed JSON response, specifying what
47
+ handlers were executed (`executed_handlers`) and what handlers *could have
48
+ been* executed, if they were defined in the handlers folder
49
+ (`matching_handlers`).
53
50
  ```
54
51
 
55
52
 
@@ -64,15 +61,19 @@ $ loadrunner --help
64
61
  Building Handlers
65
62
  --------------------------------------------------
66
63
 
67
- When running the server, it will look for handlers in the `./handlers`
68
- directory, using one of these format:
64
+ When running the server, it will look for handlers (executable scripts) in
65
+ the `./handlers` directory, using one of these format:
69
66
 
67
+ handlers/global
68
+ handlers/<repo name>/global
70
69
  handlers/<repo name>/<event type>
71
70
  handlers/<repo name>/<event type>@branch=<branch name>
72
71
  handlers/<repo name>/<event type>@tag=<branch name>
73
72
 
74
73
  For example:
75
74
 
75
+ handlers/global
76
+ handlers/myrepo/global
76
77
  handlers/myrepo/push
77
78
  handlers/myrepo/push@branch=master
78
79
  handlers/myrepo/push@tag=release
@@ -88,12 +89,12 @@ executables.
88
89
 
89
90
  These environment variables are available to your handlers:
90
91
 
91
- - `REPO`
92
- - `EVENT`
93
- - `BRANCH`
94
- - `REF`
95
- - `TAG`
96
- - `PAYLOAD` - the entire JSON string as received from GitHub, or the client.
92
+ - `LOADRUNNER_REPO`
93
+ - `LOADRUNNER_EVENT`
94
+ - `LOADRUNNER_BRANCH`
95
+ - `LOADRUNNER_REF`
96
+ - `LOADRUNNER_TAG`
97
+ - `LOADRUNNER_PAYLOAD` - the entire JSON string as received from GitHub, or the client.
97
98
 
98
99
 
99
100
 
@@ -3,9 +3,10 @@ module LoadRunner
3
3
  # Executes event handlers
4
4
  class Runner
5
5
  attr_reader :opts
6
- attr_accessor :response
6
+ attr_accessor :response, :handlers_dir
7
7
 
8
8
  def initialize(opts)
9
+ @handlers_dir = 'handlers'
9
10
  @opts = opts
10
11
  end
11
12
 
@@ -13,12 +14,12 @@ module LoadRunner
13
14
  # populates the `#response` object, and returns true on success.
14
15
  def execute
15
16
  set_environment_vars
16
-
17
+
17
18
  @response = opts.dup
18
19
  handlers = locate_handlers
20
+ @response[:matching_handlers] = matching_handlers
19
21
 
20
22
  if handlers.empty?
21
- @response[:matching_handlers] = matching_handlers
22
23
  @response[:error] = "Could not find any handler to process this webhook. Please implement one of the 'matching_handlers'."
23
24
  return false
24
25
  else
@@ -28,14 +29,6 @@ module LoadRunner
28
29
  end
29
30
  end
30
31
 
31
- def handlers_dir
32
- @handlers_dir ||= 'handlers'
33
- end
34
-
35
- def handlers_dir=(path)
36
- @handlers_dir = path
37
- end
38
-
39
32
  private
40
33
 
41
34
  # Find all handlers that fit the payload meta data.
@@ -65,12 +58,16 @@ module LoadRunner
65
58
  # Set all payload meta data as environment variables so that the
66
59
  # handler can use them.
67
60
  def set_environment_vars
68
- opts.each { |key, value| ENV[key.to_s.upcase] = value }
61
+ opts.each { |key, value| ENV["LOADRUNNER_#{key.to_s.upcase}"] = value }
69
62
  end
70
63
 
71
64
  def matching_handlers
72
65
  base = "#{handlers_dir}/#{opts[:repo]}/#{opts[:event]}"
73
- handlers = ["#{base}"]
66
+ handlers = [
67
+ "#{handlers_dir}/global",
68
+ "#{handlers_dir}/#{opts[:repo]}/global",
69
+ "#{base}"
70
+ ]
74
71
 
75
72
  handlers.tap do |h|
76
73
  h << "#{base}@branch=#{opts[:branch]}" if opts[:branch]
@@ -28,8 +28,9 @@ module LoadRunner
28
28
  opts = {}
29
29
  opts[:repo] = payload.dig(:repository, :name)
30
30
  opts[:event] = request.env['HTTP_X_GITHUB_EVENT']
31
- opts[:branch] = payload[:ref].sub('refs/heads/', '') if payload[:ref] =~ /refs\/heads/
32
- opts[:tag] = payload[:ref].sub('refs/tags/', '') if payload[:ref] =~ /refs\/tags/
31
+ opts[:ref] = payload[:ref]
32
+ opts[:branch] = payload[:ref] =~ /refs\/heads/ ? payload[:ref].sub('refs/heads/', '') : nil
33
+ opts[:tag] = payload[:ref] =~ /refs\/tags/ ? payload[:ref].sub('refs/tags/', '') : nil
33
34
  opts[:payload] = json_string
34
35
 
35
36
  runner = Runner.new opts
@@ -1,3 +1,3 @@
1
1
  module LoadRunner
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
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.3.1
4
+ version: 0.4.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: 2018-06-21 00:00:00.000000000 Z
11
+ date: 2018-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: super_docopt