magnum-payload 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +13 -4
- data/lib/magnum/payload/bitbucket.rb +4 -0
- data/lib/magnum/payload/version.rb +1 -1
- data/lib/magnum/payload.rb +10 -2
- data/spec/fixtures/bitbucket/git_no_commits.json +16 -0
- data/spec/payload/bitbucket_spec.rb +9 -0
- data/spec/payload_spec.rb +15 -0
- metadata +13 -29
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a93c18d82f5039aabc7a14c75291693117f92b6d
|
4
|
+
data.tar.gz: 9f6d4a32fe5b2b047e4f178bf172ff7c056f0c86
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b8f22f02913bb97c4f030ad0da10d95476c01d595aa952c2426ec873fe5aaab786232fa3e48c7fe786b951b0e393a773bd4ef8b6cca028e447f2b956b204c436
|
7
|
+
data.tar.gz: 5ff86b1468c19eae47943c59b52d56f464443e4254237affa3fbd2cb5e13f44bf3ade649b629631b6aac203043e3ba666e74692e504df0be3894cd6c5ab622f9
|
data/README.md
CHANGED
@@ -38,9 +38,9 @@ Example:
|
|
38
38
|
require 'magnum/payload'
|
39
39
|
|
40
40
|
# Shorthand method to parse payload
|
41
|
-
Magnum::Payload.parse('github', 'JSON
|
42
|
-
Magnum::Payload.parse('bitbucket', 'JSON
|
43
|
-
Magnum::Payload.parse('gitlab', 'JSON
|
41
|
+
Magnum::Payload.parse('github', 'JSON') # => Magnum::Payload::Github
|
42
|
+
Magnum::Payload.parse('bitbucket', 'JSON') # => Magnum::Payload::Bitbucket
|
43
|
+
Magnum::Payload.parse('gitlab', 'JSON') # => Magnum::Payload::Gitlab
|
44
44
|
|
45
45
|
# Or directly initialize a class
|
46
46
|
payload = Magnum::Payload::Github.new('JSON data')
|
@@ -89,11 +89,20 @@ To execute test suite run:
|
|
89
89
|
rake test
|
90
90
|
```
|
91
91
|
|
92
|
+
## Contact
|
93
|
+
|
94
|
+
Magnum CI
|
95
|
+
|
96
|
+
- [https://magnum-ci.com](https://magnum-ci.com)
|
97
|
+
- [https://github.com/magnumci](https://github.com/magnumci)
|
98
|
+
- [https://twitter.com/ci_magnum](https://twitter.com/ci_magnum)
|
99
|
+
- [support@magnum-ci.com](mailto:support@magnum-ci.com)
|
100
|
+
|
92
101
|
## License
|
93
102
|
|
94
103
|
MIT License
|
95
104
|
|
96
|
-
Copyright (c) 2013 Magnum CI
|
105
|
+
Copyright (c) 2013 Magnum CI
|
97
106
|
|
98
107
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
99
108
|
this software and associated documentation files (the "Software"), to deal in
|
@@ -1,6 +1,10 @@
|
|
1
1
|
module Magnum
|
2
2
|
class Payload::Bitbucket < Payload::Base
|
3
3
|
def parse!
|
4
|
+
if data.commits.nil? || data.commits.empty?
|
5
|
+
raise Magnum::Payload::PayloadError, "Payload has no commits"
|
6
|
+
end
|
7
|
+
|
4
8
|
commit = Hashr.new(data.commits.last)
|
5
9
|
|
6
10
|
branch = commit.branch || commit.branches.first || 'none'
|
data/lib/magnum/payload.rb
CHANGED
@@ -2,6 +2,8 @@ require 'magnum/payload/version'
|
|
2
2
|
|
3
3
|
module Magnum
|
4
4
|
module Payload
|
5
|
+
SOURCES = %w(custom github gitlab gitslice bitbucket beanstalk)
|
6
|
+
|
5
7
|
class ParseError < StandardError ; end
|
6
8
|
class PayloadError < StandardError ; end
|
7
9
|
|
@@ -14,11 +16,17 @@ module Magnum
|
|
14
16
|
autoload :Beanstalk, 'magnum/payload/beanstalk'
|
15
17
|
autoload :MessageParser, 'magnum/payload/message_parser'
|
16
18
|
|
19
|
+
def self.valid_source?(source)
|
20
|
+
SOURCES.include?(source.to_s)
|
21
|
+
end
|
22
|
+
|
17
23
|
def self.parse(source, payload)
|
24
|
+
unless valid_source?(source)
|
25
|
+
raise PayloadError, "Invalid payload type: #{source}"
|
26
|
+
end
|
27
|
+
|
18
28
|
klass = Magnum::Payload.const_get(source.to_s.capitalize)
|
19
29
|
klass.new(payload)
|
20
|
-
rescue NameError
|
21
|
-
raise PayloadError, "Invalid payload type: #{source}"
|
22
30
|
end
|
23
31
|
end
|
24
32
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
{
|
2
|
+
"repository": {
|
3
|
+
"website": "http://www.mysite.com/",
|
4
|
+
"fork": false,
|
5
|
+
"name": "repository",
|
6
|
+
"scm": "git",
|
7
|
+
"owner": "username",
|
8
|
+
"absolute_url": "/username/repository/",
|
9
|
+
"slug": "minestore",
|
10
|
+
"is_private": true
|
11
|
+
},
|
12
|
+
"truncated": false,
|
13
|
+
"commits": [],
|
14
|
+
"canon_url": "https://bitbucket.org",
|
15
|
+
"user": "username"
|
16
|
+
}
|
@@ -35,6 +35,15 @@ describe Magnum::Payload::Bitbucket do
|
|
35
35
|
it 'sets compare url' do
|
36
36
|
payload.compare_url.should eq 'https://bitbucket.org/sosedoff/test1/compare/e15c6013c0f6232153e53b003b97da51d338da3a..f15566c42759198fd32a70963d2509f3f8309586'
|
37
37
|
end
|
38
|
+
|
39
|
+
context "that does not have commits" do
|
40
|
+
let(:data) { fixture("bitbucket/git_no_commits.json") }
|
41
|
+
|
42
|
+
it "raises PayloadError exception" do
|
43
|
+
expect { Magnum::Payload::Bitbucket.new(data) }.
|
44
|
+
to raise_error Magnum::Payload::PayloadError, "Payload has no commits"
|
45
|
+
end
|
46
|
+
end
|
38
47
|
end
|
39
48
|
|
40
49
|
context 'with mercurial payload' do
|
data/spec/payload_spec.rb
CHANGED
@@ -1,6 +1,21 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Magnum::Payload do
|
4
|
+
describe ".valid_source?" do
|
5
|
+
it "returns true if valid" do
|
6
|
+
expect(Magnum::Payload.valid_source?("github")).to eq true
|
7
|
+
expect(Magnum::Payload.valid_source?("gitlab")).to eq true
|
8
|
+
expect(Magnum::Payload.valid_source?("gitslice")).to eq true
|
9
|
+
expect(Magnum::Payload.valid_source?("bitbucket")).to eq true
|
10
|
+
expect(Magnum::Payload.valid_source?("beanstalk")).to eq true
|
11
|
+
expect(Magnum::Payload.valid_source?("custom")).to eq true
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns false if not valid" do
|
15
|
+
expect(Magnum::Payload.valid_source?("foobar")).to eq false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
4
19
|
describe '.parse' do
|
5
20
|
it 'returns payload instance for github' do
|
6
21
|
payload = Magnum::Payload.parse('github', fixture('github.json'))
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magnum-payload
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Dan Sosedoff
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-08-24 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rake
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ~>
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ~>
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -46,7 +41,6 @@ dependencies:
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: simplecov
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - ~>
|
52
46
|
- !ruby/object:Gem::Version
|
@@ -54,7 +48,6 @@ dependencies:
|
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - ~>
|
60
53
|
- !ruby/object:Gem::Version
|
@@ -62,33 +55,29 @@ dependencies:
|
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: json
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - '>='
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '1.8'
|
70
62
|
type: :runtime
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - '>='
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '1.8'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: hashr
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - '>='
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '0'
|
86
76
|
type: :runtime
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - '>='
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0'
|
94
83
|
description: Allows to parse code payloads from Github, Bitbucket and many more
|
@@ -120,6 +109,7 @@ files:
|
|
120
109
|
- spec/fixtures/beanstalk/hg.json
|
121
110
|
- spec/fixtures/beanstalk/svn.json
|
122
111
|
- spec/fixtures/bitbucket/git.json
|
112
|
+
- spec/fixtures/bitbucket/git_no_commits.json
|
123
113
|
- spec/fixtures/bitbucket/hg.json
|
124
114
|
- spec/fixtures/github.json
|
125
115
|
- spec/fixtures/github/deleted.json
|
@@ -142,39 +132,33 @@ files:
|
|
142
132
|
homepage: https://github.com/magnumci/magnum-payload
|
143
133
|
licenses:
|
144
134
|
- MIT
|
135
|
+
metadata: {}
|
145
136
|
post_install_message:
|
146
137
|
rdoc_options: []
|
147
138
|
require_paths:
|
148
139
|
- lib
|
149
140
|
required_ruby_version: !ruby/object:Gem::Requirement
|
150
|
-
none: false
|
151
141
|
requirements:
|
152
|
-
- -
|
142
|
+
- - '>='
|
153
143
|
- !ruby/object:Gem::Version
|
154
144
|
version: '0'
|
155
|
-
segments:
|
156
|
-
- 0
|
157
|
-
hash: 3727367032317050001
|
158
145
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
|
-
none: false
|
160
146
|
requirements:
|
161
|
-
- -
|
147
|
+
- - '>='
|
162
148
|
- !ruby/object:Gem::Version
|
163
149
|
version: '0'
|
164
|
-
segments:
|
165
|
-
- 0
|
166
|
-
hash: 3727367032317050001
|
167
150
|
requirements: []
|
168
151
|
rubyforge_project:
|
169
|
-
rubygems_version:
|
152
|
+
rubygems_version: 2.0.5
|
170
153
|
signing_key:
|
171
|
-
specification_version:
|
154
|
+
specification_version: 4
|
172
155
|
summary: Code payload parser
|
173
156
|
test_files:
|
174
157
|
- spec/fixtures/beanstalk/git.json
|
175
158
|
- spec/fixtures/beanstalk/hg.json
|
176
159
|
- spec/fixtures/beanstalk/svn.json
|
177
160
|
- spec/fixtures/bitbucket/git.json
|
161
|
+
- spec/fixtures/bitbucket/git_no_commits.json
|
178
162
|
- spec/fixtures/bitbucket/hg.json
|
179
163
|
- spec/fixtures/github.json
|
180
164
|
- spec/fixtures/github/deleted.json
|