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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d392f76be98d4ea79c1d0d37f39bcfac1cb0766d
4
- data.tar.gz: 921b9928570d5ad2f41a51d3ea3649663a1dd000
3
+ metadata.gz: c913ae966a34c495971151a1d01b8f42881d05b1
4
+ data.tar.gz: a0ae86fa239990cb949c7e6d7402958e6a7e540a
5
5
  SHA512:
6
- metadata.gz: f5add8ecc03c30922eb0e954e4161248cf2e7ad5f3b01b0a66f30db8fe1581dc27fb9d679687b6654b98245e6fe510ee28098bfac5c36b7a50dd20cbeb542ae6
7
- data.tar.gz: 222df38da21cd23ee037ed1116de654b6f9813be103ab854b91686ec09f38d6d0803d52eee9db7ccb44ce6187791270b59e42f8478b5bbd718bc426ac4f36e76
6
+ metadata.gz: 3a6cf68affc2203d60975ccc84d004f3be56bdb1188ea8066db34040a70c1897d154ac47f55692603d20f82d7d18051d97e957e02cca70e79951c021806e7024
7
+ data.tar.gz: feb1211463ab6c41e9ae16382c76cc8c9d315f7536e38a5601b8e813596376bd3ff8353d8e78fb8318656e15315f2205228dc6de825329e1b322eb87072ac6fe
data/Gemfile CHANGED
@@ -1,6 +1,2 @@
1
- source 'https://rubygems.org'
2
- gemspec
3
-
4
- group :test do
5
- gem 'simplecov', :require => false
6
- end
1
+ source "https://rubygems.org"
2
+ gemspec
data/LICENSE CHANGED
@@ -1,4 +1,5 @@
1
- Copyright (c) 2013 Magnum CI, Dan Sosedoff <dan.sosedoff@gmail.com>
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
+ [![build status](https://magnum-ci.com/status/1f87bb33961c21de5940142e86a741f1.png)](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
- The above copyright notice and this permission notice shall be included in all
115
- copies or substantial portions of the Software
107
+ Copyright (c) 2013-2014 Dan Sosedoff, <dan.sosedoff@gmail.com>
116
108
 
117
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
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>
@@ -1,5 +1,5 @@
1
- require 'json'
2
- require 'hashr'
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 :commit, :branch, :author, :committer, :message
13
- attr_reader :committer_email, :author_email
14
- attr_reader :commit_url, :compare_url
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
- @skip = false # Do not skip by default
18
- @test = false # Do not treat as test payload
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
- 'commit' => commit,
30
- 'branch' => branch,
31
- 'author' => author,
32
- 'committer' => committer,
33
- 'message' => message,
34
- 'commit_url' => commit_url,
35
- 'compare_url' => compare_url
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))
@@ -0,0 +1,7 @@
1
+ module Magnum
2
+ module Payload
3
+ class Error < StandardError ; end
4
+ class ParseError < Error ; end
5
+ class PayloadError < Error ; end
6
+ end
7
+ end
@@ -19,28 +19,25 @@ module Magnum
19
19
  end
20
20
 
21
21
  def skip_payload?
22
- @skip = true if deleted? || last_commit.nil?
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
- # @return [Boolean]
30
- def forced?
29
+ def forced_push?
31
30
  data.forced == true
32
31
  end
33
32
 
34
- # Check if head is deleted
35
- # @return [Boolean]
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 forced?
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
- module MessageParser
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
- def skip_message?
7
- message.to_s.split("\n").first =~ REGEX_SKIP ? true : false
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
@@ -1,5 +1,5 @@
1
1
  module Magnum
2
2
  module Payload
3
- VERSION = "0.3.3"
3
+ VERSION = "0.3.4"
4
4
  end
5
5
  end
@@ -1,20 +1,18 @@
1
- require 'magnum/payload/version'
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
- class ParseError < StandardError ; end
8
- class PayloadError < StandardError ; end
9
-
10
- autoload :Base, 'magnum/payload/base'
11
- autoload :Custom, 'magnum/payload/custom'
12
- autoload :Github, 'magnum/payload/github'
13
- autoload :Gitlab, 'magnum/payload/gitlab'
14
- autoload :Gitslice, 'magnum/payload/gitslice'
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)
@@ -1,24 +1,24 @@
1
- require File.expand_path('../lib/magnum/payload/version', __FILE__)
1
+ require File.expand_path("../lib/magnum/payload/version", __FILE__)
2
2
 
3
- Gem::Specification.new do |s|
4
- s.name = "magnum-payload"
5
- s.version = Magnum::Payload::VERSION
6
- s.summary = "Code payload parser"
7
- s.description = "Allows to parse code payloads from Github, Bitbucket and many more"
8
- s.homepage = "https://github.com/magnumci/magnum-payload"
9
- s.authors = ["Dan Sosedoff"]
10
- s.email = ["dan.sosedoff@gmail.com"]
11
- s.license = 'MIT'
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
- s.add_development_dependency 'rake', '~> 10'
14
- s.add_development_dependency 'rspec', '~> 2.13'
15
- s.add_development_dependency 'simplecov', '~> 0.7'
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
- s.add_runtime_dependency 'json', '>= 1.8'
18
- s.add_runtime_dependency 'hashr', '>= 0'
17
+ spec.add_runtime_dependency "json", ">= 1.8"
18
+ spec.add_runtime_dependency "hashr", ">= 0"
19
19
 
20
- s.files = `git ls-files`.split("\n")
21
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
- s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
23
- s.require_paths = ["lib"]
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
@@ -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 = Magnum::Payload::Base.new("raw data")
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 = Magnum::Payload::Base.new({'foo' => 'bar'})
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 = Magnum::Payload::Base.new('{"foo":"bar"}')
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 = Magnum::Payload::Base.new({'foo' => 'bar'})
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 { Magnum::Payload::Base.new(nil) }.to raise_error "String or Hash required"
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 { Magnum::Payload::Base.new("invalid json") }.
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
- Magnum::Payload::Base.new('data').skip.should eq false
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 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe Magnum::Payload::MessageParser do
4
- let(:klass) { class Klass ; include Magnum::Payload::MessageParser ; end }
5
- let(:subject) { klass.new }
4
+ let(:subject) { TestMessageParser.new }
6
5
 
7
- describe '#skip_message?' do
8
- it 'returns true when message contains "ci-skip"' do
9
- subject.stub(:message).and_return('Commit message [ci-skip]')
10
- subject.skip_message?.should eq true
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 'returns true when message contains "ci skip"' do
14
- subject.stub(:message).and_return('Commit message [ci skip]')
15
- subject.skip_message?.should eq true
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 'returns true when message contains "skip ci"' do
19
- subject.stub(:message).and_return('Commit message [skip ci]')
20
- subject.skip_message?.should eq true
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 'returns true when message contains "skip-ci"' do
24
- subject.stub(:message).and_return('Commit message [skip-ci]')
25
- subject.skip_message?.should eq true
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 'returns false if no skip points found' do
29
- subject.stub(:message).and_return('Commit message')
30
- subject.skip_message?.should eq false
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 'with multi-line message' do
34
- it 'returns true' do
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?.should eq true
35
+ expect(subject.skip_message?).to be_true
37
36
  end
38
37
 
39
- it 'returns false' do
38
+ it "returns false" do
40
39
  subject.stub(:message).and_return("Commit message\nLets skip [ci-skip]")
41
- subject.skip_message?.should eq false
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
- $:.unshift File.expand_path("../..", __FILE__)
2
-
3
- require 'magnum/payload'
4
- require 'simplecov'
1
+ require "simplecov"
5
2
 
6
3
  SimpleCov.start do
7
- add_group 'Magnum::Payload', 'lib/magnum/payload'
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)
@@ -0,0 +1,3 @@
1
+ class TestMessageParser
2
+ include Magnum::Payload::MessageParser
3
+ end
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.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: 2013-09-20 00:00:00.000000000 Z
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.7'
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.7'
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: Allows to parse code payloads from Github, Bitbucket and many more
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.0.3
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