magnum-payload 0.3.0

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.
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,58 @@
1
+ {
2
+ "before": "0000000000000000000000000000000000000000",
3
+ "after": "95a5abc129d8db566805233d18b927ed06773fde",
4
+ "created": true,
5
+ "commits": [],
6
+ "compare": "https://github.com/sosedoff/net-ssh-session/compare/v0.1.5",
7
+ "deleted": false,
8
+ "forced": true,
9
+ "ref": "refs/tags/v0.1.5",
10
+ "head_commit": {
11
+ "message": "Version bump: 0.1.5",
12
+ "author": {
13
+ "username": "sosedoff",
14
+ "name": "Dan Sosedoff",
15
+ "email": "dan.sosedoff@gmail.com"
16
+ },
17
+ "added": [],
18
+ "modified": ["lib/net-ssh-session/version.rb"],
19
+ "removed": [],
20
+ "id": "a9bf1e971bc42e35b58583d1d395b789912dc608",
21
+ "timestamp": "2013-04-13T15:33:00-07:00",
22
+ "distinct": true,
23
+ "url": "https://github.com/sosedoff/net-ssh-session/commit/a9bf1e971bc42e35b58583d1d395b789912dc608",
24
+ "committer": {
25
+ "username": "sosedoff",
26
+ "name": "Dan Sosedoff",
27
+ "email": "dan.sosedoff@gmail.com"
28
+ }
29
+ },
30
+ "pusher": {
31
+ "name": "sosedoff",
32
+ "email": "dan.sosedoff@gmail.com"
33
+ },
34
+ "repository": {
35
+ "has_downloads": true,
36
+ "size": 252,
37
+ "watchers": 6,
38
+ "stargazers": 6,
39
+ "has_wiki": true,
40
+ "pushed_at": 1365892380,
41
+ "master_branch": "master",
42
+ "owner": {
43
+ "name": "sosedoff",
44
+ "email": "dan.sosedoff@gmail.com"
45
+ },
46
+ "fork": false,
47
+ "id": 6552072,
48
+ "open_issues": 0,
49
+ "has_issues": true,
50
+ "name": "net-ssh-session",
51
+ "language": "Ruby",
52
+ "created_at": 1352151005,
53
+ "description": "Shell session for Net::SSH connections",
54
+ "private": false,
55
+ "url": "https://github.com/sosedoff/net-ssh-session",
56
+ "forks": 0
57
+ }
58
+ }
@@ -0,0 +1,113 @@
1
+ {
2
+ "after": "9d227f327e725164c3266be74cf5c00678edad13",
3
+ "before": "0e46f019e391e5f7dc09cb2aaf364be346e36793",
4
+ "commits": [{
5
+ "added": [],
6
+ "author": {
7
+ "email": "dan.sosedoff@gmail.com",
8
+ "name": "Dan Sosedoff",
9
+ "username": "sosedoff"
10
+ },
11
+ "committer": {
12
+ "email": "dan.sosedoff@gmail.com",
13
+ "name": "Dan Sosedoff",
14
+ "username": "sosedoff"
15
+ },
16
+ "distinct": true,
17
+ "id": "a7b32aed43bf4942090e310899e554d0e31b9757",
18
+ "message": "Update travis build config",
19
+ "modified": [".travis.yml"],
20
+ "removed": [],
21
+ "timestamp": "2012-11-16T10:27:05-08:00",
22
+ "url": "https://github.com/sosedoff/lxc-ruby/commit/a7b32aed43bf4942090e310899e554d0e31b9757"
23
+ }, {
24
+ "added": [],
25
+ "author": {
26
+ "email": "dan.sosedoff@gmail.com",
27
+ "name": "Dan Sosedoff",
28
+ "username": "sosedoff"
29
+ },
30
+ "committer": {
31
+ "email": "dan.sosedoff@gmail.com",
32
+ "name": "Dan Sosedoff",
33
+ "username": "sosedoff"
34
+ },
35
+ "distinct": true,
36
+ "id": "2f6036026ef382cd7f5a9cc2fd6c2d6598525d55",
37
+ "message": "Change gem name",
38
+ "modified": ["lxc.gemspec"],
39
+ "removed": [],
40
+ "timestamp": "2012-11-16T10:30:15-08:00",
41
+ "url": "https://github.com/sosedoff/lxc-ruby/commit/2f6036026ef382cd7f5a9cc2fd6c2d6598525d55"
42
+ }, {
43
+ "added": [],
44
+ "author": {
45
+ "email": "dan.sosedoff@gmail.com",
46
+ "name": "Dan Sosedoff",
47
+ "username": "sosedoff"
48
+ },
49
+ "committer": {
50
+ "email": "dan.sosedoff@gmail.com",
51
+ "name": "Dan Sosedoff",
52
+ "username": "sosedoff"
53
+ },
54
+ "distinct": true,
55
+ "id": "9d227f327e725164c3266be74cf5c00678edad13",
56
+ "message": "Remove jruby from test matrix",
57
+ "modified": [".travis.yml"],
58
+ "removed": [],
59
+ "timestamp": "2012-11-16T10:37:50-08:00",
60
+ "url": "https://github.com/sosedoff/lxc-ruby/commit/9d227f327e725164c3266be74cf5c00678edad13"
61
+ }],
62
+ "compare": "https://github.com/sosedoff/lxc-ruby/compare/0e46f019e391...9d227f327e72",
63
+ "created": false,
64
+ "deleted": false,
65
+ "forced": false,
66
+ "head_commit": {
67
+ "added": [],
68
+ "author": {
69
+ "email": "dan.sosedoff@gmail.com",
70
+ "name": "Dan Sosedoff",
71
+ "username": "sosedoff"
72
+ },
73
+ "committer": {
74
+ "email": "dan.sosedoff@gmail.com",
75
+ "name": "Dan Sosedoff",
76
+ "username": "sosedoff"
77
+ },
78
+ "distinct": true,
79
+ "id": "9d227f327e725164c3266be74cf5c00678edad13",
80
+ "message": "Remove jruby from test matrix",
81
+ "modified": [".travis.yml"],
82
+ "removed": [],
83
+ "timestamp": "2012-11-16T10:37:50-08:00",
84
+ "url": "https://github.com/sosedoff/lxc-ruby/commit/9d227f327e725164c3266be74cf5c00678edad13"
85
+ },
86
+ "pusher": {
87
+ "name": "none"
88
+ },
89
+ "ref": "refs/heads/master",
90
+ "repository": {
91
+ "created_at": "2012-05-25T18:17:04-07:00",
92
+ "description": "Ruby wrapper for LXC cli tools",
93
+ "fork": false,
94
+ "forks": 6,
95
+ "has_downloads": true,
96
+ "has_issues": true,
97
+ "has_wiki": true,
98
+ "id": 4451730,
99
+ "language": "Ruby",
100
+ "name": "lxc-ruby",
101
+ "open_issues": 0,
102
+ "owner": {
103
+ "email": "dan.sosedoff@gmail.com",
104
+ "name": "sosedoff"
105
+ },
106
+ "private": false,
107
+ "pushed_at": "2012-11-16T10:38:31-08:00",
108
+ "size": 204,
109
+ "stargazers": 27,
110
+ "url": "https://github.com/sosedoff/lxc-ruby",
111
+ "watchers": 27
112
+ }
113
+ }
@@ -0,0 +1,34 @@
1
+ {
2
+ "after": "a96a0df33262e2d2fd1b20162553aae6750f8c00",
3
+ "before": "0188ef243dd8083a4d4761766342b523d521247d",
4
+ "commits": [{
5
+ "author": {
6
+ "email": "dan.sosedoff@gmail.com",
7
+ "name": "Dan Sosedoff"
8
+ },
9
+ "id": "bce85c7015af8ff5e50bab160f8bd1aa9b2738e1",
10
+ "message": "Commit 1",
11
+ "timestamp": "2013-03-22T19:44:53+00:00",
12
+ "url": "https://gitlab.com/sosedoff/bar/commit/bce85c7015af8ff5e50bab160f8bd1aa9b2738e1"
13
+ }, {
14
+ "author": {
15
+ "email": "dan.sosedoff@gmail.com",
16
+ "name": "Dan Sosedoff"
17
+ },
18
+ "id": "a96a0df33262e2d2fd1b20162553aae6750f8c00",
19
+ "message": "Commit 2",
20
+ "timestamp": "2013-03-22T19:44:56+00:00",
21
+ "url": "https://gitlab.com/sosedoff/bar/commit/a96a0df33262e2d2fd1b20162553aae6750f8c00"
22
+ }
23
+ ],
24
+ "ref": "refs/heads/master",
25
+ "repository": {
26
+ "description": null,
27
+ "homepage": "https://gitlab.com/sosedoff/bar",
28
+ "name": "bar",
29
+ "url": "git@gitlab.com:sosedoff/bar.git"
30
+ },
31
+ "total_commits_count": 2,
32
+ "user_id": 3686,
33
+ "user_name": "Dan Sosedoff"
34
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "after": "0188ef243dd8083a4d4761766342b523d521247d",
3
+ "before": "0000000000000000000000000000000000000000",
4
+ "commits": [],
5
+ "ref": "refs/heads/foobar",
6
+ "repository": {
7
+ "description": null,
8
+ "homepage": "https://gitlab.com/sosedoff/bar",
9
+ "name": "bar",
10
+ "url": "git@gitlab.com:sosedoff/bar.git"
11
+ },
12
+ "total_commits_count": 0,
13
+ "user_id": 3686,
14
+ "user_name": "Dan Sosedoff"
15
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "after": "0000000000000000000000000000000000000000",
3
+ "before": "a99dce54125b4b8a4afbddbb1881f32cf93d3d3b",
4
+ "commits": [],
5
+ "ref": "refs/heads/new-branch",
6
+ "repository": {
7
+ "description": null,
8
+ "homepage": "https://gitlab.com/sosedoff/bar",
9
+ "name": "bar",
10
+ "url": "git@gitlab.com:sosedoff/bar.git"
11
+ },
12
+ "total_commits_count": 0,
13
+ "user_id": 3686,
14
+ "user_name": "Dan Sosedoff"
15
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "commit": "177d757ad97214f4546fb999e0be0783360e614e",
3
+ "message": "Add initial 404 page",
4
+ "author": "Dan Sosedoff",
5
+ "committer": "Dan Sosedoff",
6
+ "branch": "source-type",
7
+ "commit_url": "http://gitslice.com/magnum-ci/commit/177d757ad97214f4546fb999e0be0783360e614e",
8
+ "compare_url": "http://gitslice.com/magnum-ci/compare/b0445d963b7e3efaf47610ef710acc0ba3067a39...177d757ad97214f4546fb999e0be0783360e614e"
9
+ }
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe Magnum::Payload::Base do
4
+ before do
5
+ Magnum::Payload::Base.any_instance.stub(:parse!)
6
+ end
7
+
8
+ describe '#new' do
9
+ it 'assigns raw data attribute' do
10
+ Magnum::Payload::Base.any_instance.stub(:parse_payload)
11
+
12
+ payload = Magnum::Payload::Base.new("raw data")
13
+ payload.raw_data.should eq 'raw data'
14
+ end
15
+
16
+ it 'assigns data attribute' do
17
+ payload = Magnum::Payload::Base.new({'foo' => 'bar'})
18
+ payload.data.should be_a Hashr
19
+ end
20
+
21
+ it 'accepts a String' do
22
+ payload = Magnum::Payload::Base.new('{"foo":"bar"}')
23
+ payload.data.should be_a Hashr
24
+ payload.data.foo.should eq 'bar'
25
+ end
26
+
27
+ it 'accepts a Hash' do
28
+ payload = Magnum::Payload::Base.new({'foo' => 'bar'})
29
+ payload.data.should be_a Hashr
30
+ payload.data.foo.should eq('bar')
31
+ end
32
+
33
+ it 'raises error on invalid input type' do
34
+ expect { Magnum::Payload::Base.new(nil) }.to raise_error "String or Hash required"
35
+ end
36
+
37
+ it 'raises error on invalid json' do
38
+ expect { Magnum::Payload::Base.new("invalid json") }.
39
+ to raise_error Magnum::Payload::ParseError, "Valid JSON required"
40
+ end
41
+ end
42
+
43
+ describe '#skip' do
44
+ before do
45
+ Magnum::Payload::Base.any_instance.stub(:parse_payload)
46
+ end
47
+
48
+ it 'should be false' do
49
+ Magnum::Payload::Base.new('data').skip.should eq false
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,114 @@
1
+ require 'spec_helper'
2
+
3
+ describe Magnum::Payload::Beanstalk do
4
+ let(:payload) { Magnum::Payload::Beanstalk.new(data) }
5
+
6
+ describe '#parse!' do
7
+ context 'with git payload' do
8
+ let(:data) { fixture('beanstalk/git.json') }
9
+
10
+ it 'sets commit SHA' do
11
+ payload.commit.should eq '1111111111111111111111111111111111111111'
12
+ end
13
+
14
+ it 'sets commit branch' do
15
+ payload.branch.should eq 'master'
16
+ end
17
+
18
+ it 'sets commit message' do
19
+ payload.message.should eq 'Fake commit message'
20
+ end
21
+
22
+ it 'sets author and committer' do
23
+ payload.author.should eq 'Mr Jones'
24
+ payload.author_email.should eq 'john.jones@gmail.com'
25
+ end
26
+
27
+ it 'sets commit view url' do
28
+ payload.commit_url.should eq 'http://sosedoff.beanstalkapp.com/xml-sitemap/changesets/1111111111111111111111111111111111111111'
29
+ end
30
+
31
+ it 'sets compare url' do
32
+ payload.compare_url.should eq nil
33
+ end
34
+
35
+ context 'when fake' do
36
+ let(:data) { fixture('beanstalk/git.json') }
37
+
38
+ it 'sets skip to true' do
39
+ payload.skip.should eq true
40
+ end
41
+
42
+ it 'sets test to true' do
43
+ payload.test.should eq true
44
+ end
45
+ end
46
+ end
47
+
48
+ context 'with svn payload' do
49
+ let(:data) { fixture('beanstalk/svn.json') }
50
+
51
+ it 'sets commit number' do
52
+ payload.commit.should eq 1
53
+ end
54
+
55
+ it 'sets commit message' do
56
+ payload.message.should eq 'Creating initial repository structure'
57
+ end
58
+
59
+ it 'sets branch to master' do
60
+ payload.branch.should eq 'master'
61
+ end
62
+
63
+ it 'sets author and committer' do
64
+ payload.author.should eq 'admin'
65
+ payload.committer.should eq 'admin'
66
+ end
67
+
68
+ it 'sets commit view url' do
69
+ payload.commit_url.should_not eq nil
70
+ end
71
+ end
72
+
73
+ context 'with mercurial payload' do
74
+ let(:data) { fixture('beanstalk/hg.json') }
75
+
76
+ it 'sets commit SHA' do
77
+ payload.commit.should eq '1111111111111111111111111111111111111111'
78
+ end
79
+
80
+ it 'sets commit branch' do
81
+ payload.branch.should eq 'default'
82
+ end
83
+
84
+ it 'sets commit message' do
85
+ payload.message.should eq 'Fake commit message'
86
+ end
87
+
88
+ it 'sets author and committer' do
89
+ payload.author.should eq 'Mr Jones'
90
+ payload.author_email.should eq 'john.jones@gmail.com'
91
+ end
92
+
93
+ it 'sets commit view url' do
94
+ payload.commit_url.should eq 'http://sosedoff.beanstalkapp.com/beanstalk-hg1/changesets/1111111111111111111111111111111111111111'
95
+ end
96
+
97
+ it 'sets compare url' do
98
+ payload.compare_url.should eq nil
99
+ end
100
+
101
+ context 'when fake' do
102
+ let(:data) { fixture('beanstalk/hg.json') }
103
+
104
+ it 'sets skip to true' do
105
+ payload.skip.should eq true
106
+ end
107
+
108
+ it 'sets test to true' do
109
+ payload.test.should eq true
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+
3
+ describe Magnum::Payload::Bitbucket do
4
+ let(:data) { fixture('bitbucket/git.json') }
5
+ let(:payload) { Magnum::Payload::Bitbucket.new(data) }
6
+
7
+ describe '#parse!' do
8
+ context 'with git payload' do
9
+ let(:data) { fixture('bitbucket/git.json') }
10
+
11
+ it 'sets commit SHA' do
12
+ payload.commit.should eq 'f15566c42759198fd32a70963d2509f3f8309586'
13
+ end
14
+
15
+ it 'sets commit branch' do
16
+ payload.branch.should eq 'master'
17
+ end
18
+
19
+ it 'sets commit message' do
20
+ payload.message.should eq 'Commit Sat Jan 19 18:42:40 CST 2013'
21
+ end
22
+
23
+ it 'sets author and committer' do
24
+ payload.committer.should be_nil
25
+ payload.committer_email.should be_nil
26
+
27
+ payload.author.should eq 'Dan Sosedoff'
28
+ payload.author_email.should eq 'dan.sosedoff@gmail.com'
29
+ end
30
+
31
+ it 'sets commit view url' do
32
+ payload.commit_url.should eq 'https://bitbucket.org/sosedoff/test1/commits/f15566c42759198fd32a70963d2509f3f8309586'
33
+ end
34
+
35
+ it 'sets compare url' do
36
+ payload.compare_url.should eq 'https://bitbucket.org/sosedoff/test1/compare/e15c6013c0f6232153e53b003b97da51d338da3a..f15566c42759198fd32a70963d2509f3f8309586'
37
+ end
38
+ end
39
+
40
+ context 'with mercurial payload' do
41
+ let(:data) { fixture('bitbucket/hg.json') }
42
+
43
+ it 'sets commit SHA' do
44
+ payload.commit.should eq 4
45
+ end
46
+
47
+ it 'sets commit branch' do
48
+ payload.branch.should eq 'default'
49
+ end
50
+
51
+ it 'sets commit message' do
52
+ payload.message.should eq 'Commit 2'
53
+ end
54
+
55
+ it 'sets author and committer' do
56
+ payload.committer.should be_nil
57
+ payload.committer_email.should be_nil
58
+
59
+ payload.author.should eq 'Dan Sosedoff'
60
+ payload.author_email.should eq 'dan.sosedoff@gmail.com'
61
+ end
62
+
63
+ it 'sets commit view url' do
64
+ payload.commit_url.should eq 'https://bitbucket.org/sosedoff/mercurial-test/commits/4'
65
+ end
66
+
67
+ it 'sets compare url' do
68
+ payload.compare_url.should eq 'https://bitbucket.org/sosedoff/mercurial-test/compare/3..4'
69
+ end
70
+ end
71
+ end
72
+
73
+ describe '#site_url' do
74
+ it 'returns website url without a path' do
75
+ payload.site_url.should eq 'https://bitbucket.org'
76
+ end
77
+ end
78
+
79
+ describe '#repo_url' do
80
+ it 'return relative repository path' do
81
+ payload.repo_url.should eq '/sosedoff/test1/'
82
+ end
83
+ end
84
+
85
+ describe '#make_url' do
86
+ it 'returns a full url to the repository' do
87
+ payload.make_url.should eq 'https://bitbucket.org/sosedoff/test1/'
88
+ end
89
+
90
+ it 'returns a full url to the repository action' do
91
+ payload.make_url('commits/1234').should eq 'https://bitbucket.org/sosedoff/test1/commits/1234'
92
+ end
93
+ end
94
+ end