magnum-payload 0.3.3 → 0.3.4
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 +4 -4
- data/Gemfile +2 -6
- data/LICENSE +2 -1
- data/README.md +5 -18
- data/lib/magnum/payload/base.rb +28 -15
- data/lib/magnum/payload/errors.rb +7 -0
- data/lib/magnum/payload/github.rb +5 -8
- data/lib/magnum/payload/message_parser.rb +4 -6
- data/lib/magnum/payload/version.rb +1 -1
- data/lib/magnum/payload.rb +11 -13
- data/magnum-payload.gemspec +19 -19
- data/spec/payload/base_spec.rb +20 -7
- data/spec/payload/message_parser_spec.rb +23 -24
- data/spec/spec_helper.rb +8 -5
- data/spec/support/test_message_parser.rb +3 -0
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c913ae966a34c495971151a1d01b8f42881d05b1
|
4
|
+
data.tar.gz: a0ae86fa239990cb949c7e6d7402958e6a7e540a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a6cf68affc2203d60975ccc84d004f3be56bdb1188ea8066db34040a70c1897d154ac47f55692603d20f82d7d18051d97e957e02cca70e79951c021806e7024
|
7
|
+
data.tar.gz: feb1211463ab6c41e9ae16382c76cc8c9d315f7536e38a5601b8e813596376bd3ff8353d8e78fb8318656e15315f2205228dc6de825329e1b322eb87072ac6fe
|
data/Gemfile
CHANGED
data/LICENSE
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
Copyright (c) 2013
|
1
|
+
Copyright (c) 2013-2014 Dan Sosedoff, <dan.sosedoff@gmail.com>
|
2
|
+
Copyright (c) 2013-2014 Magnum CI, <support@magnum-ci.com>
|
2
3
|
|
3
4
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
5
|
this software and associated documentation files (the "Software"), to deal in
|
data/README.md
CHANGED
@@ -6,6 +6,8 @@ It accepts any commits payloads and transforms them into identical data structur
|
|
6
6
|
If you need to integrate web-hooks from Github, Bitbucket or Gitlab this is definitely
|
7
7
|
worth checking out. Check examples for details.
|
8
8
|
|
9
|
+
[](https://magnum-ci.com/public/0cb3a398347ebeeb90fb/builds)
|
10
|
+
|
9
11
|
## Supported platforms
|
10
12
|
|
11
13
|
You can integrate with the following providers:
|
@@ -100,23 +102,8 @@ Magnum CI
|
|
100
102
|
|
101
103
|
## License
|
102
104
|
|
103
|
-
MIT License
|
104
|
-
|
105
|
-
Copyright (c) 2013 Magnum CI
|
106
|
-
|
107
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
108
|
-
this software and associated documentation files (the "Software"), to deal in
|
109
|
-
the Software without restriction, including without limitation the rights to
|
110
|
-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
111
|
-
the Software, and to permit persons to whom the Software is furnished to do so,
|
112
|
-
subject to the following conditions
|
105
|
+
The MIT License (MIT)
|
113
106
|
|
114
|
-
|
115
|
-
copies or substantial portions of the Software
|
107
|
+
Copyright (c) 2013-2014 Dan Sosedoff, <dan.sosedoff@gmail.com>
|
116
108
|
|
117
|
-
|
118
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
119
|
-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
120
|
-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
121
|
-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
122
|
-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
109
|
+
Copyright (c) 2013-2014 Magnum CI, <support@magnum-ci.com>
|
data/lib/magnum/payload/base.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "json"
|
2
|
+
require "hashr"
|
3
3
|
|
4
4
|
module Magnum
|
5
5
|
module Payload
|
@@ -7,15 +7,23 @@ module Magnum
|
|
7
7
|
include Magnum::Payload::MessageParser
|
8
8
|
|
9
9
|
attr_reader :raw_data, :data
|
10
|
-
attr_reader :skip, :test
|
11
10
|
|
12
|
-
attr_reader :
|
13
|
-
|
14
|
-
|
11
|
+
attr_reader :skip, # Flag to indicate payload skip
|
12
|
+
:test # Flag to indicate a test payload
|
13
|
+
|
14
|
+
attr_reader :commit, # Commit SHA or ID
|
15
|
+
:branch, # Commit branch name (master)
|
16
|
+
:author, # Commit author name
|
17
|
+
:committer, # Commit committer name
|
18
|
+
:message, # Commit message text
|
19
|
+
:committer_email, # Committer email address
|
20
|
+
:author_email, # Commit author email address
|
21
|
+
:commit_url, # Url to view commit diff
|
22
|
+
:compare_url # URL to view multiple commits diff
|
15
23
|
|
16
24
|
def initialize(payload)
|
17
|
-
|
18
|
-
|
25
|
+
set_defaults
|
26
|
+
|
19
27
|
@raw_data = payload
|
20
28
|
@data = parse_payload(payload)
|
21
29
|
|
@@ -26,13 +34,13 @@ module Magnum
|
|
26
34
|
|
27
35
|
def attributes_hash
|
28
36
|
{
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
37
|
+
"commit" => commit,
|
38
|
+
"branch" => branch,
|
39
|
+
"author" => author,
|
40
|
+
"committer" => committer,
|
41
|
+
"message" => message,
|
42
|
+
"commit_url" => commit_url,
|
43
|
+
"compare_url" => compare_url
|
36
44
|
}
|
37
45
|
end
|
38
46
|
|
@@ -46,6 +54,11 @@ module Magnum
|
|
46
54
|
|
47
55
|
private
|
48
56
|
|
57
|
+
def set_defaults
|
58
|
+
@skip = false # Do not skip
|
59
|
+
@test = false # Do not treat as test payload
|
60
|
+
end
|
61
|
+
|
49
62
|
def parse_payload(payload)
|
50
63
|
if payload.kind_of?(String)
|
51
64
|
Hashr.new(JSON.parse(payload))
|
@@ -19,28 +19,25 @@ module Magnum
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def skip_payload?
|
22
|
-
@skip = true if
|
22
|
+
@skip = true if head_deleted? || last_commit.nil?
|
23
23
|
@skip = true if data.ref =~ /tags/
|
24
24
|
|
25
25
|
@skip
|
26
26
|
end
|
27
27
|
|
28
28
|
# Check if push is forced
|
29
|
-
|
30
|
-
def forced?
|
29
|
+
def forced_push?
|
31
30
|
data.forced == true
|
32
31
|
end
|
33
32
|
|
34
|
-
# Check if head is deleted
|
35
|
-
|
36
|
-
def deleted?
|
33
|
+
# Check if push head is deleted
|
34
|
+
def head_deleted?
|
37
35
|
data.deleted == true
|
38
36
|
end
|
39
37
|
|
40
38
|
# Get last commit in the push
|
41
|
-
# @return [Hashr]
|
42
39
|
def last_commit
|
43
|
-
if
|
40
|
+
if forced_push?
|
44
41
|
data.head_commit
|
45
42
|
else
|
46
43
|
Hashr.new(data.commits.last)
|
@@ -1,11 +1,9 @@
|
|
1
1
|
module Magnum
|
2
|
-
module Payload
|
3
|
-
|
4
|
-
REGEX_SKIP = /\[(ci skip|ci-skip|skip ci|skip-ci)\]/i
|
2
|
+
module Payload::MessageParser
|
3
|
+
REGEX_SKIP = /\[(ci skip|ci-skip|skip ci|skip-ci)\]/i
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
end
|
5
|
+
def skip_message?
|
6
|
+
message.to_s.split("\n").first =~ REGEX_SKIP ? true : false
|
9
7
|
end
|
10
8
|
end
|
11
9
|
end
|
data/lib/magnum/payload.rb
CHANGED
@@ -1,20 +1,18 @@
|
|
1
|
-
require
|
1
|
+
require "magnum/payload/version"
|
2
|
+
require "magnum/payload/errors"
|
2
3
|
|
3
4
|
module Magnum
|
4
5
|
module Payload
|
5
6
|
SOURCES = %w(custom github gitlab gitslice bitbucket beanstalk)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
autoload :
|
11
|
-
autoload :
|
12
|
-
autoload :
|
13
|
-
autoload :
|
14
|
-
autoload :
|
15
|
-
autoload :Bitbucket, 'magnum/payload/bitbucket'
|
16
|
-
autoload :Beanstalk, 'magnum/payload/beanstalk'
|
17
|
-
autoload :MessageParser, 'magnum/payload/message_parser'
|
7
|
+
|
8
|
+
autoload :Base, "magnum/payload/base"
|
9
|
+
autoload :Custom, "magnum/payload/custom"
|
10
|
+
autoload :Github, "magnum/payload/github"
|
11
|
+
autoload :Gitlab, "magnum/payload/gitlab"
|
12
|
+
autoload :Gitslice, "magnum/payload/gitslice"
|
13
|
+
autoload :Bitbucket, "magnum/payload/bitbucket"
|
14
|
+
autoload :Beanstalk, "magnum/payload/beanstalk"
|
15
|
+
autoload :MessageParser, "magnum/payload/message_parser"
|
18
16
|
|
19
17
|
def self.valid_source?(source)
|
20
18
|
SOURCES.include?(source.to_s)
|
data/magnum-payload.gemspec
CHANGED
@@ -1,24 +1,24 @@
|
|
1
|
-
require File.expand_path(
|
1
|
+
require File.expand_path("../lib/magnum/payload/version", __FILE__)
|
2
2
|
|
3
|
-
Gem::Specification.new do |
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "magnum-payload"
|
5
|
+
spec.version = Magnum::Payload::VERSION
|
6
|
+
spec.summary = "Code payload parser"
|
7
|
+
spec.description = "Parse code pushes from multiple code hosting platforms"
|
8
|
+
spec.homepage = "https://github.com/magnumci/magnum-payload"
|
9
|
+
spec.authors = ["Dan Sosedoff"]
|
10
|
+
spec.email = ["dan.sosedoff@gmail.com"]
|
11
|
+
spec.license = "MIT"
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
spec.add_development_dependency "rake", "~> 10"
|
14
|
+
spec.add_development_dependency "rspec", "~> 2.13"
|
15
|
+
spec.add_development_dependency "simplecov", "~> 0.8"
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
spec.add_runtime_dependency "json", ">= 1.8"
|
18
|
+
spec.add_runtime_dependency "hashr", ">= 0"
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
spec.files = `git ls-files`.split("\n")
|
21
|
+
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
+
spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
24
|
end
|
data/spec/payload/base_spec.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Magnum::Payload::Base do
|
4
|
+
let(:base) { described_class }
|
5
|
+
|
4
6
|
before do
|
5
7
|
Magnum::Payload::Base.any_instance.stub(:parse!)
|
6
8
|
end
|
@@ -9,33 +11,33 @@ describe Magnum::Payload::Base do
|
|
9
11
|
it 'assigns raw data attribute' do
|
10
12
|
Magnum::Payload::Base.any_instance.stub(:parse_payload)
|
11
13
|
|
12
|
-
payload =
|
14
|
+
payload = base.new("raw data")
|
13
15
|
payload.raw_data.should eq 'raw data'
|
14
16
|
end
|
15
17
|
|
16
18
|
it 'assigns data attribute' do
|
17
|
-
payload =
|
19
|
+
payload = base.new({'foo' => 'bar'})
|
18
20
|
payload.data.should be_a Hashr
|
19
21
|
end
|
20
22
|
|
21
23
|
it 'accepts a String' do
|
22
|
-
payload =
|
24
|
+
payload = base.new('{"foo":"bar"}')
|
23
25
|
payload.data.should be_a Hashr
|
24
26
|
payload.data.foo.should eq 'bar'
|
25
27
|
end
|
26
28
|
|
27
29
|
it 'accepts a Hash' do
|
28
|
-
payload =
|
30
|
+
payload = base.new({'foo' => 'bar'})
|
29
31
|
payload.data.should be_a Hashr
|
30
32
|
payload.data.foo.should eq('bar')
|
31
33
|
end
|
32
34
|
|
33
35
|
it 'raises error on invalid input type' do
|
34
|
-
expect {
|
36
|
+
expect { base.new(nil) }.to raise_error "String or Hash required"
|
35
37
|
end
|
36
38
|
|
37
39
|
it 'raises error on invalid json' do
|
38
|
-
expect {
|
40
|
+
expect { base.new("invalid json") }.
|
39
41
|
to raise_error Magnum::Payload::ParseError, "Valid JSON required"
|
40
42
|
end
|
41
43
|
end
|
@@ -46,7 +48,18 @@ describe Magnum::Payload::Base do
|
|
46
48
|
end
|
47
49
|
|
48
50
|
it 'should be false' do
|
49
|
-
|
51
|
+
base.new('data').skip.should eq false
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#skip?" do
|
56
|
+
before do
|
57
|
+
Magnum::Payload::Base.any_instance.stub(:parse_payload)
|
58
|
+
Magnum::Payload::Base.any_instance.stub(:skip) { true }
|
59
|
+
end
|
60
|
+
|
61
|
+
it "returns true if skip" do
|
62
|
+
expect(base.new("data").skip?).to be_true
|
50
63
|
end
|
51
64
|
end
|
52
65
|
end
|
@@ -1,44 +1,43 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Magnum::Payload::MessageParser do
|
4
|
-
let(:
|
5
|
-
let(:subject) { klass.new }
|
4
|
+
let(:subject) { TestMessageParser.new }
|
6
5
|
|
7
|
-
describe
|
8
|
-
it
|
9
|
-
subject.stub(:message).and_return(
|
10
|
-
subject.skip_message
|
6
|
+
describe "#skip_message?" do
|
7
|
+
it "returns true when message contains 'ci-skip'" do
|
8
|
+
subject.stub(:message).and_return("Commit message [ci-skip]")
|
9
|
+
expect(subject.skip_message?).to be_true
|
11
10
|
end
|
12
11
|
|
13
|
-
it
|
14
|
-
subject.stub(:message).and_return(
|
15
|
-
subject.skip_message
|
12
|
+
it "returns true when message contains 'ci skip'" do
|
13
|
+
subject.stub(:message).and_return("Commit message [ci skip]")
|
14
|
+
expect(subject.skip_message?).to be_true
|
16
15
|
end
|
17
16
|
|
18
|
-
it
|
19
|
-
subject.stub(:message).and_return(
|
20
|
-
subject.skip_message
|
17
|
+
it "returns true when message contains 'skip ci'" do
|
18
|
+
subject.stub(:message).and_return("Commit message [skip ci]")
|
19
|
+
expect(subject.skip_message?).to be_true
|
21
20
|
end
|
22
21
|
|
23
|
-
it
|
24
|
-
subject.stub(:message).and_return(
|
25
|
-
subject.skip_message
|
22
|
+
it "returns true when message contains 'skip-ci'" do
|
23
|
+
subject.stub(:message).and_return("Commit message [skip-ci]")
|
24
|
+
expect(subject.skip_message?).to be_true
|
26
25
|
end
|
27
26
|
|
28
|
-
it
|
29
|
-
subject.stub(:message).and_return(
|
30
|
-
subject.skip_message
|
27
|
+
it "returns false if no skip points found" do
|
28
|
+
subject.stub(:message).and_return("Commit message")
|
29
|
+
expect(subject.skip_message?).to be_false
|
31
30
|
end
|
32
31
|
|
33
|
-
context
|
34
|
-
it
|
32
|
+
context "with multi-line message" do
|
33
|
+
it "returns true" do
|
35
34
|
subject.stub(:message).and_return("Commit message [skip-ci]\nCommit comments")
|
36
|
-
subject.skip_message
|
35
|
+
expect(subject.skip_message?).to be_true
|
37
36
|
end
|
38
37
|
|
39
|
-
it
|
38
|
+
it "returns false" do
|
40
39
|
subject.stub(:message).and_return("Commit message\nLets skip [ci-skip]")
|
41
|
-
subject.skip_message
|
40
|
+
expect(subject.skip_message?).to be_false
|
42
41
|
end
|
43
42
|
end
|
44
43
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'magnum/payload'
|
4
|
-
require 'simplecov'
|
1
|
+
require "simplecov"
|
5
2
|
|
6
3
|
SimpleCov.start do
|
7
|
-
|
4
|
+
add_filter ".bundle"
|
5
|
+
add_group "Magnum::Payload", "lib/magnum/payload"
|
8
6
|
end
|
9
7
|
|
8
|
+
require "magnum/payload"
|
9
|
+
|
10
|
+
# Include all support files
|
11
|
+
Dir["./spec/support/**/*.rb"].each { |f| require(f) }
|
12
|
+
|
10
13
|
def fixture_path(filename=nil)
|
11
14
|
path = File.expand_path("../fixtures", __FILE__)
|
12
15
|
filename.nil? ? path : File.join(path, filename)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magnum-payload
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Sosedoff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0.
|
47
|
+
version: '0.8'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0.
|
54
|
+
version: '0.8'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: json
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
description:
|
83
|
+
description: Parse code pushes from multiple code hosting platforms
|
84
84
|
email:
|
85
85
|
- dan.sosedoff@gmail.com
|
86
86
|
executables: []
|
@@ -99,6 +99,7 @@ files:
|
|
99
99
|
- lib/magnum/payload/beanstalk.rb
|
100
100
|
- lib/magnum/payload/bitbucket.rb
|
101
101
|
- lib/magnum/payload/custom.rb
|
102
|
+
- lib/magnum/payload/errors.rb
|
102
103
|
- lib/magnum/payload/github.rb
|
103
104
|
- lib/magnum/payload/gitlab.rb
|
104
105
|
- lib/magnum/payload/gitslice.rb
|
@@ -130,6 +131,7 @@ files:
|
|
130
131
|
- spec/payload/message_parser_spec.rb
|
131
132
|
- spec/payload_spec.rb
|
132
133
|
- spec/spec_helper.rb
|
134
|
+
- spec/support/test_message_parser.rb
|
133
135
|
homepage: https://github.com/magnumci/magnum-payload
|
134
136
|
licenses:
|
135
137
|
- MIT
|
@@ -150,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
152
|
version: '0'
|
151
153
|
requirements: []
|
152
154
|
rubyforge_project:
|
153
|
-
rubygems_version: 2.
|
155
|
+
rubygems_version: 2.1.11
|
154
156
|
signing_key:
|
155
157
|
specification_version: 4
|
156
158
|
summary: Code payload parser
|
@@ -180,3 +182,4 @@ test_files:
|
|
180
182
|
- spec/payload/message_parser_spec.rb
|
181
183
|
- spec/payload_spec.rb
|
182
184
|
- spec/spec_helper.rb
|
185
|
+
- spec/support/test_message_parser.rb
|