jackal-github 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eec50fd5e3f0c4fcabb04c701e0d7227aa0afcf3
4
+ data.tar.gz: e87d0e1e9420ee420993619f4a51e72f030378b9
5
+ SHA512:
6
+ metadata.gz: 55115b081234606af980b53d5e176af0683514841cc416b9128ce9036743488556d7f35ba11235c37b8ddeabe1b89e17ee62d01b9695a32427b99d8adc5240ad
7
+ data.tar.gz: 4a1f2dd0da9e664d7804e9270499a8f8056812b9e0f736042232f139c965a4bda3bfdd8f14254757d4c313a110f84e871cfa3790a12df4e8b6564c9ea3d0e69f
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ # v0.1.0
2
+ * Initial release
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,25 @@
1
+ # Contributing
2
+
3
+ ## Branches
4
+
5
+ ### `master` branch
6
+
7
+ The master branch is the current stable released version.
8
+
9
+ ### `develop` branch
10
+
11
+ The develop branch is the current edge of development.
12
+
13
+ ## Pull requests
14
+
15
+ * https://github.com/carnivore-rb/jackal-github/pulls
16
+
17
+ Please base all pull requests of the `develop` branch. Merges to
18
+ `master` only occur through the `develop` branch. Pull requests
19
+ based on `master` will likely be cherry picked.
20
+
21
+ ## Issues
22
+
23
+ Need to report an issue? Use the github issues:
24
+
25
+ * https://github.com/carnivore-rb/jackal-github/issues
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2015 Chris Roberts
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # Jackal Github
2
+
3
+ Processes incoming payloads from github.
4
+
5
+ ## Usage
6
+
7
+ Configure incoming source using the `:http_paths` source:
8
+
9
+ ```json
10
+ ...
11
+ "sources": {
12
+ "input": {
13
+ "type": "http_paths",
14
+ "args": {
15
+ "port": 9090,
16
+ "path": "/github",
17
+ "method": "post"
18
+ }
19
+ }
20
+ }
21
+ ...
22
+ ```
23
+
24
+ ## Configuration
25
+
26
+ The name provided for the payload defaults to `"github"`. This
27
+ can be overridden in the configuration using the names map,
28
+ which allows names to be provided on a per-event basis:
29
+
30
+ ```json
31
+ ...
32
+ "config": {
33
+ "names": {
34
+ "push": PUSH_NAME,
35
+ "create": CREATE_NAME
36
+ }
37
+ }
38
+ ...
39
+ ```
40
+
41
+ ## Payload
42
+
43
+ The payload generated will contain the contents fo the github
44
+ payload, any query parameters provided, and the headers. It will
45
+ also add in an `event` key to designate what type of event was
46
+ received.
47
+
48
+ ```json
49
+ ...
50
+ "data": {
51
+ "github": {
52
+ "event": "X_GITHUB_EVENT",
53
+ "query": QUERY_PARAMS,
54
+ "headers": HTTP_HEADERS,
55
+ GITHUB_PAYLOAD
56
+ }
57
+ }
58
+ ...
59
+ ```
60
+
61
+ ## Formatters
62
+
63
+ * `Jackal::Github::Formatter::CodeFetcher` Formats payload for code fetcher
64
+
65
+ # Info
66
+
67
+ * Repository: https://github.com/carnivore-rb/jackal-github
68
+ * IRC: Freenode @ #carnivore
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__)) + '/lib/'
2
+ require 'jackal-github/version'
3
+ Gem::Specification.new do |s|
4
+ s.name = 'jackal-github'
5
+ s.version = Jackal::Github::VERSION.version
6
+ s.summary = 'Message processing helper'
7
+ s.author = 'Chris Roberts'
8
+ s.email = 'code@chrisroberts.org'
9
+ s.homepage = 'https://github.com/carnivore-rb/jackal-github'
10
+ s.description = 'GitHub payload event helper'
11
+ s.require_path = 'lib'
12
+ s.license = 'Apache 2.0'
13
+ s.add_runtime_dependency 'jackal'
14
+ s.add_development_dependency 'carnivore-http'
15
+ s.files = Dir['lib/**/*'] + %w(jackal-github.gemspec README.md CHANGELOG.md CONTRIBUTING.md LICENSE)
16
+ end
@@ -0,0 +1,10 @@
1
+ require 'jackal'
2
+
3
+ module Jackal
4
+ module Github
5
+ autoload :Eventer, 'jackal-github/eventer'
6
+ end
7
+ end
8
+
9
+ require 'jackal-github/formatter'
10
+ require 'jackal-github/version'
@@ -0,0 +1,62 @@
1
+ require 'jackal-github'
2
+
3
+ module Jackal
4
+ module Github
5
+ # Process events
6
+ class Eventer < Callback
7
+
8
+ # Validity of message
9
+ #
10
+ # @param message [Carnivore::Message]
11
+ # @return [Truthy, Falsey]
12
+ def valid?(message)
13
+ super do |_|
14
+ message[:message].get(:headers, :x_github_event)
15
+ end
16
+ end
17
+
18
+ # Format payload based on event type recevied
19
+ #
20
+ # @param message [Carnivore::Message]
21
+ def execute(message)
22
+ failure_wrap(message) do |_|
23
+ content = format_payload(message)
24
+ payload = new_payload(name_for_payload(content), content)
25
+ job_completed(:github, payload, message)
26
+ end
27
+ end
28
+
29
+ # Format the github event to store within the payload
30
+ #
31
+ # @param message [Carnivore::Message]
32
+ # @return [Smash]
33
+ def format_payload(message)
34
+ content = Smash.new
35
+ g_payload = message[:message][:body]
36
+ g_headers = message[:message][:headers] || {}
37
+ g_query = message[:message][:query] || {}
38
+ content[:github] = g_payload.merge(
39
+ Smash.new(
40
+ :event => g_headers[:x_github_event],
41
+ :query => g_query,
42
+ :headers => g_headers,
43
+ :url_path => message[:message][:request].path
44
+ )
45
+ )
46
+ content
47
+ end
48
+
49
+ # Provide payload name for given event
50
+ #
51
+ # @param event [String] github event
52
+ # @return [String] payload name
53
+ # @note defaults to `github`
54
+ def name_for_payload(event)
55
+ config.fetch(:names, event,
56
+ config.fetch(:names, :default, :github)
57
+ )
58
+ end
59
+
60
+ end
61
+ end
62
+ end
@@ -0,0 +1 @@
1
+ require 'jackal-github/formatter/code_fetcher'
@@ -0,0 +1,121 @@
1
+ require 'jackal-github'
2
+
3
+ module Jackal
4
+ module Github
5
+ module Formatter
6
+
7
+ class CodeFetcher < Jackal::Formatter
8
+
9
+ # Format payloads from source
10
+ SOURCE = '*'
11
+ # Formats for destination
12
+ DESTINATION = 'code_fetcher'
13
+
14
+ # Format the payload to provide code fetcher information
15
+ #
16
+ # @param payload [Smash]
17
+ # @return [Smash]
18
+ def format(payload)
19
+ if(payload.get(:data, :github))
20
+ payload.set(:data, :code_fetcher, :info, :source, 'github')
21
+ payload.set(:data, :code_fetcher, :info, :owner,
22
+ payload.get(:data, :github, :repository, :owner, :login))
23
+ payload.set(:data, :code_fetcher, :info, :name,
24
+ payload.get(:data, :github, :repository, :name))
25
+ payload.set(:data, :code_fetcher, :info, :private,
26
+ payload.get(:data, :github, :repository, :private))
27
+ payload.set(:data, :code_fetcher, :info, :url,
28
+ payload.get(:data, :github, :repository, :clone_url))
29
+ set_reference_information(payload.get(:data, :github, :event).to_s, payload)
30
+ payload
31
+ end
32
+ end
33
+
34
+ # Set repository reference information into payload if
35
+ # available
36
+ #
37
+ # @param event [String] github event type
38
+ # @param payload [Smash]
39
+ # @return [Smash]
40
+ def set_reference_information(event, payload)
41
+ method_name = "#{event}_reference"
42
+ if(self.respond_to?(method_name, true))
43
+ ref, sha = send(method_name, payload)
44
+ payload.set(:data, :code_fetcher, :info, :reference, ref)
45
+ payload.set(:data, :code_fetcher, :info, :commit_sha, sha)
46
+ end
47
+ payload
48
+ end
49
+
50
+ private
51
+
52
+ # Format for commit comment event
53
+ #
54
+ # @param payload [Smash]
55
+ # @return [Array<String>] [reference, commit_id]
56
+ def commit_comment_reference(payload)
57
+ [payload.get(:data, :github, :comment, :commit_id),
58
+ payload.get(:data, :github, :comment, :commit_id)]
59
+ end
60
+
61
+ # Format for create event
62
+ #
63
+ # @param payload [Smash]
64
+ # @return [Array<String>] [reference, commit_id]
65
+ def create_reference(payload)
66
+ [payload.get(:data, :github, :ref),
67
+ payload.get(:data, :github, :ref)]
68
+ end
69
+ alias_method :delete_reference, :create_reference
70
+
71
+ # Format for deployment event
72
+ #
73
+ # @param payload [Smash]
74
+ # @return [Array<String>] [reference, commit_id]
75
+ def deployment_reference(payload)
76
+ [payload.get(:data, :github, :deployment, :ref),
77
+ payload.get(:data, :github, :deployment, :sha)]
78
+ end
79
+ alias_method :deployment_status_reference, :deployment_reference
80
+
81
+ # Format for pull request event
82
+ #
83
+ # @param payload [Smash]
84
+ # @return [Array<String>] [reference, commit_id]
85
+ def pull_request_reference(payload)
86
+ payload.set(:data, :code_fetcher, :info, :owner,
87
+ payload.get(:data, :github, :pull_request, :head, :repo, :owner, :login))
88
+ payload.set(:data, :code_fetcher, :info, :name,
89
+ payload.get(:data, :github, :pull_request, :head, :repo, :name))
90
+ payload.set(:data, :code_fetcher, :info, :private,
91
+ payload.get(:data, :github, :pull_request, :head, :repo, :private))
92
+ payload.set(:data, :code_fetcher, :info, :url,
93
+ payload.get(:data, :github, :pull_request, :head, :repo, :clone_url))
94
+ [payload.get(:data, :github, :pull_request, :head, :ref),
95
+ payload.get(:data, :github, :pull_request, :head, :sha)]
96
+ end
97
+
98
+ # Format for push event
99
+ #
100
+ # @param payload [Smash]
101
+ # @return [Array<String>] [reference, commit_id]
102
+ def push_reference(payload)
103
+ payload.set(:data, :code_fetcher, :info, :owner,
104
+ payload.get(:data, :github, :repository, :owner, :name))
105
+ [payload.get(:data, :github, :ref),
106
+ payload.get(:data, :github, :head_commit, :id)]
107
+ end
108
+
109
+ # Format for status event
110
+ #
111
+ # @param payload [Smash]
112
+ # @return [Array<String>] [reference, commit_id]
113
+ def status_reference(payload)
114
+ [payload.get(:data, :github, :sha),
115
+ payload.get(:data, :github, :sha)]
116
+ end
117
+
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,5 @@
1
+ module Jackal
2
+ module Github
3
+ VERSION = Gem::Version.new('0.1.0')
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jackal-github
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Roberts
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jackal
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: carnivore-http
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: GitHub payload event helper
42
+ email: code@chrisroberts.org
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - CHANGELOG.md
48
+ - CONTRIBUTING.md
49
+ - LICENSE
50
+ - README.md
51
+ - jackal-github.gemspec
52
+ - lib/jackal-github.rb
53
+ - lib/jackal-github/eventer.rb
54
+ - lib/jackal-github/formatter.rb
55
+ - lib/jackal-github/formatter/code_fetcher.rb
56
+ - lib/jackal-github/version.rb
57
+ homepage: https://github.com/carnivore-rb/jackal-github
58
+ licenses:
59
+ - Apache 2.0
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.2.2
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Message processing helper
81
+ test_files: []
82
+ has_rdoc: