magnum-payload 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +24 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +6 -0
  5. data/LICENSE +18 -0
  6. data/README.md +107 -0
  7. data/Rakefile +10 -0
  8. data/lib/magnum/payload/base.rb +62 -0
  9. data/lib/magnum/payload/beanstalk.rb +43 -0
  10. data/lib/magnum/payload/bitbucket.rb +53 -0
  11. data/lib/magnum/payload/custom.rb +19 -0
  12. data/lib/magnum/payload/github.rb +50 -0
  13. data/lib/magnum/payload/gitlab.rb +38 -0
  14. data/lib/magnum/payload/gitslice.rb +21 -0
  15. data/lib/magnum/payload/message_parser.rb +11 -0
  16. data/lib/magnum/payload/version.rb +5 -0
  17. data/lib/magnum/payload.rb +24 -0
  18. data/magnum-payload.gemspec +23 -0
  19. data/spec/fixtures/beanstalk/git.json +28 -0
  20. data/spec/fixtures/beanstalk/hg.json +27 -0
  21. data/spec/fixtures/beanstalk/svn.json +15 -0
  22. data/spec/fixtures/bitbucket/git.json +48 -0
  23. data/spec/fixtures/bitbucket/hg.json +48 -0
  24. data/spec/fixtures/github/deleted.json +39 -0
  25. data/spec/fixtures/github/forced.json +58 -0
  26. data/spec/fixtures/github/new_branch.json +77 -0
  27. data/spec/fixtures/github/new_tag.json +58 -0
  28. data/spec/fixtures/github.json +113 -0
  29. data/spec/fixtures/gitlab/commits.json +34 -0
  30. data/spec/fixtures/gitlab/create_branch.json +15 -0
  31. data/spec/fixtures/gitlab/delete_branch.json +15 -0
  32. data/spec/fixtures/gitslice.json +9 -0
  33. data/spec/payload/base_spec.rb +52 -0
  34. data/spec/payload/beanstalk_spec.rb +114 -0
  35. data/spec/payload/bitbucket_spec.rb +94 -0
  36. data/spec/payload/github_spec.rb +74 -0
  37. data/spec/payload/gitlab_spec.rb +53 -0
  38. data/spec/payload/gitslice_spec.rb +33 -0
  39. data/spec/payload/message_parser_spec.rb +45 -0
  40. data/spec/payload_spec.rb +35 -0
  41. data/spec/spec_helper.rb +17 -0
  42. metadata +177 -0
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ describe Magnum::Payload::Github do
4
+ describe '#parse!' do
5
+ let(:data) { fixture('github.json') }
6
+ let(:payload) { Magnum::Payload::Github.new(data) }
7
+
8
+ it 'sets commit sha' do
9
+ payload.commit.should eq '9d227f327e725164c3266be74cf5c00678edad13'
10
+ end
11
+
12
+ it 'sets commit branch' do
13
+ payload.branch.should eq 'master'
14
+ end
15
+
16
+ it 'sets commit message' do
17
+ payload.message.should eq 'Remove jruby from test matrix'
18
+ end
19
+
20
+ it 'sets author' do
21
+ payload.committer.should eq 'Dan Sosedoff'
22
+ payload.committer_email.should eq 'dan.sosedoff@gmail.com'
23
+ end
24
+
25
+ it 'sets committer' do
26
+ payload.author.should eq 'Dan Sosedoff'
27
+ payload.author_email.should eq 'dan.sosedoff@gmail.com'
28
+ end
29
+
30
+ it 'sets commit view url' do
31
+ payload.commit_url.should eq 'https://github.com/sosedoff/lxc-ruby/commit/9d227f327e725164c3266be74cf5c00678edad13'
32
+ end
33
+
34
+ it 'sets commit compare url' do
35
+ payload.compare_url.should eq 'https://github.com/sosedoff/lxc-ruby/compare/0e46f019e391...9d227f327e72'
36
+ end
37
+
38
+ context 'when push is forced' do
39
+ let(:data) { fixture 'github/forced.json' }
40
+
41
+ it 'parses head commit' do
42
+ payload.commit.should eq 'e7508c4c70d2c5afc1e6c2f3a42ecc098f435103'
43
+ end
44
+ end
45
+
46
+ context 'for deleted branch' do
47
+ let(:data) { fixture 'github/deleted.json' }
48
+
49
+ it 'marks payload as skipped' do
50
+ payload.skip.should be_true
51
+ end
52
+ end
53
+
54
+ context 'for new branch' do
55
+ let(:data) { fixture 'github/new_branch.json' }
56
+
57
+ it 'sets commit sha' do
58
+ payload.commit.should eq 'd9cc46f9e7e6aa65df696d8d1efe86de755b46ae'
59
+ end
60
+
61
+ it 'sets branch' do
62
+ payload.branch.should eq 'hello'
63
+ end
64
+ end
65
+
66
+ context 'for new tag' do
67
+ let(:data) { fixture 'github/new_tag.json' }
68
+
69
+ it 'marks payload as skipped' do
70
+ payload.skip.should be_true
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe Magnum::Payload::Gitlab do
4
+ let(:data) { fixture('gitlab/commits.json') }
5
+ let(:payload) { Magnum::Payload::Gitlab.new(data) }
6
+
7
+ describe '#parse!' do
8
+ it 'sets commit SHA' do
9
+ payload.commit.should eq 'a96a0df33262e2d2fd1b20162553aae6750f8c00'
10
+ end
11
+
12
+ it 'sets commit branch' do
13
+ payload.branch.should eq 'master'
14
+ end
15
+
16
+ it 'sets commit message' do
17
+ payload.message.should eq 'Commit 2'
18
+ end
19
+
20
+ it 'sets author and committer' do
21
+ payload.committer.should eq 'Dan Sosedoff'
22
+ payload.author.should eq 'Dan Sosedoff'
23
+ end
24
+
25
+ it 'sets commit view url' do
26
+ payload.commit_url.should eq 'https://gitlab.com/sosedoff/bar/commit/a96a0df33262e2d2fd1b20162553aae6750f8c00'
27
+ end
28
+
29
+ it 'does not set compare url' do
30
+ payload.compare_url.should eq nil
31
+ end
32
+
33
+ context 'on new branch' do
34
+ let(:data) { fixture('gitlab/create_branch.json') }
35
+
36
+ it 'sets commit SHA' do
37
+ payload.commit.should eq '0188ef243dd8083a4d4761766342b523d521247d'
38
+ end
39
+
40
+ it 'sets branch to foobar' do
41
+ payload.branch.should eq 'foobar'
42
+ end
43
+ end
44
+
45
+ context 'on deleted branch' do
46
+ let(:data) { fixture('gitlab/delete_branch.json') }
47
+
48
+ it 'sets skip to true ' do
49
+ payload.skip.should eq true
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe Magnum::Payload::Gitslice do
4
+ let(:data) { fixture('gitslice.json') }
5
+ let(:payload) { Magnum::Payload::Gitslice.new(data) }
6
+
7
+ describe '#parse!' do
8
+ it 'sets commit SHA' do
9
+ payload.commit.should eq('177d757ad97214f4546fb999e0be0783360e614e')
10
+ end
11
+
12
+ it 'sets commit branch' do
13
+ payload.branch.should eq('source-type')
14
+ end
15
+
16
+ it 'sets commit message' do
17
+ payload.message.should eq('Add initial 404 page')
18
+ end
19
+
20
+ it 'sets author and committer' do
21
+ payload.committer.should eq('Dan Sosedoff')
22
+ payload.author.should eq('Dan Sosedoff')
23
+ end
24
+
25
+ it 'sets commit view url' do
26
+ payload.commit_url.should eq('http://gitslice.com/magnum-ci/commit/177d757ad97214f4546fb999e0be0783360e614e')
27
+ end
28
+
29
+ it 'sets compare url' do
30
+ payload.compare_url.should eq('http://gitslice.com/magnum-ci/compare/b0445d963b7e3efaf47610ef710acc0ba3067a39...177d757ad97214f4546fb999e0be0783360e614e')
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Magnum::Payload::MessageParser do
4
+ let(:klass) { class Klass ; include Magnum::Payload::MessageParser ; end }
5
+ let(:subject) { klass.new }
6
+
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
11
+ end
12
+
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
16
+ end
17
+
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
21
+ end
22
+
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
26
+ end
27
+
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
31
+ end
32
+
33
+ context 'with multi-line message' do
34
+ it 'returns true' do
35
+ subject.stub(:message).and_return("Commit message [skip-ci]\nCommit comments")
36
+ subject.skip_message?.should eq true
37
+ end
38
+
39
+ it 'returns false' do
40
+ subject.stub(:message).and_return("Commit message\nLets skip [ci-skip]")
41
+ subject.skip_message?.should eq false
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Magnum::Payload do
4
+ describe '.parse' do
5
+ it 'returns payload instance for github' do
6
+ payload = Magnum::Payload.parse('github', fixture('github.json'))
7
+ expect(payload).to be_a Magnum::Payload::Github
8
+ end
9
+
10
+ it 'returns payload instance for gitslice' do
11
+ payload = Magnum::Payload.parse('gitslice', fixture('gitslice.json'))
12
+ expect(payload).to be_a Magnum::Payload::Gitslice
13
+ end
14
+
15
+ it 'returns payload instance for gitlab' do
16
+ payload = Magnum::Payload.parse('gitlab', fixture('gitlab/commits.json'))
17
+ expect(payload).to be_a Magnum::Payload::Gitlab
18
+ end
19
+
20
+ it 'returns payload instance for bitbucket' do
21
+ payload = Magnum::Payload.parse('bitbucket', fixture('bitbucket/git.json'))
22
+ expect(payload).to be_a Magnum::Payload::Bitbucket
23
+ end
24
+
25
+ it 'returns payload instance for beanstalk' do
26
+ payload = Magnum::Payload.parse('beanstalk', fixture('beanstalk/git.json'))
27
+ expect(payload).to be_a Magnum::Payload::Beanstalk
28
+ end
29
+
30
+ it 'raises error if source is invalid' do
31
+ expect { Magnum::Payload.parse('foobar', 'bar') }.
32
+ to raise_error Magnum::Payload::PayloadError, 'Invalid payload type: foobar'
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,17 @@
1
+ $:.unshift File.expand_path("../..", __FILE__)
2
+
3
+ require 'magnum/payload'
4
+ require 'simplecov'
5
+
6
+ SimpleCov.start do
7
+ add_group 'Magnum::Payload', 'lib/magnum/payload'
8
+ end
9
+
10
+ def fixture_path(filename=nil)
11
+ path = File.expand_path("../fixtures", __FILE__)
12
+ filename.nil? ? path : File.join(path, filename)
13
+ end
14
+
15
+ def fixture(file)
16
+ File.read(File.join(fixture_path, file))
17
+ end
metadata ADDED
@@ -0,0 +1,177 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: magnum-payload
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Dan Sosedoff
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '2.13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '2.13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '0.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '0.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '1.8'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '1.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: hashr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Allows to parse code payloads from Github, Bitbucket and many more
84
+ email:
85
+ - dan.sosedoff@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .rspec
92
+ - Gemfile
93
+ - LICENSE
94
+ - README.md
95
+ - Rakefile
96
+ - lib/magnum/payload.rb
97
+ - lib/magnum/payload/base.rb
98
+ - lib/magnum/payload/beanstalk.rb
99
+ - lib/magnum/payload/bitbucket.rb
100
+ - lib/magnum/payload/custom.rb
101
+ - lib/magnum/payload/github.rb
102
+ - lib/magnum/payload/gitlab.rb
103
+ - lib/magnum/payload/gitslice.rb
104
+ - lib/magnum/payload/message_parser.rb
105
+ - lib/magnum/payload/version.rb
106
+ - magnum-payload.gemspec
107
+ - spec/fixtures/beanstalk/git.json
108
+ - spec/fixtures/beanstalk/hg.json
109
+ - spec/fixtures/beanstalk/svn.json
110
+ - spec/fixtures/bitbucket/git.json
111
+ - spec/fixtures/bitbucket/hg.json
112
+ - spec/fixtures/github.json
113
+ - spec/fixtures/github/deleted.json
114
+ - spec/fixtures/github/forced.json
115
+ - spec/fixtures/github/new_branch.json
116
+ - spec/fixtures/github/new_tag.json
117
+ - spec/fixtures/gitlab/commits.json
118
+ - spec/fixtures/gitlab/create_branch.json
119
+ - spec/fixtures/gitlab/delete_branch.json
120
+ - spec/fixtures/gitslice.json
121
+ - spec/payload/base_spec.rb
122
+ - spec/payload/beanstalk_spec.rb
123
+ - spec/payload/bitbucket_spec.rb
124
+ - spec/payload/github_spec.rb
125
+ - spec/payload/gitlab_spec.rb
126
+ - spec/payload/gitslice_spec.rb
127
+ - spec/payload/message_parser_spec.rb
128
+ - spec/payload_spec.rb
129
+ - spec/spec_helper.rb
130
+ homepage: https://github.com/magnumci/magnum-payload
131
+ licenses: []
132
+ metadata: {}
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ! '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.0.3
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: Code payload parser
153
+ test_files:
154
+ - spec/fixtures/beanstalk/git.json
155
+ - spec/fixtures/beanstalk/hg.json
156
+ - spec/fixtures/beanstalk/svn.json
157
+ - spec/fixtures/bitbucket/git.json
158
+ - spec/fixtures/bitbucket/hg.json
159
+ - spec/fixtures/github.json
160
+ - spec/fixtures/github/deleted.json
161
+ - spec/fixtures/github/forced.json
162
+ - spec/fixtures/github/new_branch.json
163
+ - spec/fixtures/github/new_tag.json
164
+ - spec/fixtures/gitlab/commits.json
165
+ - spec/fixtures/gitlab/create_branch.json
166
+ - spec/fixtures/gitlab/delete_branch.json
167
+ - spec/fixtures/gitslice.json
168
+ - spec/payload/base_spec.rb
169
+ - spec/payload/beanstalk_spec.rb
170
+ - spec/payload/bitbucket_spec.rb
171
+ - spec/payload/github_spec.rb
172
+ - spec/payload/gitlab_spec.rb
173
+ - spec/payload/gitslice_spec.rb
174
+ - spec/payload/message_parser_spec.rb
175
+ - spec/payload_spec.rb
176
+ - spec/spec_helper.rb
177
+ has_rdoc: