brat 0.1.1

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 (101) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.travis.yml +3 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +24 -0
  6. data/README.md +103 -0
  7. data/Rakefile +9 -0
  8. data/bin/brat +7 -0
  9. data/brat.gemspec +26 -0
  10. data/lib/brat.rb +37 -0
  11. data/lib/brat/api.rb +17 -0
  12. data/lib/brat/cli.rb +47 -0
  13. data/lib/brat/cli_helpers.rb +175 -0
  14. data/lib/brat/client.rb +18 -0
  15. data/lib/brat/client/branches.rb +79 -0
  16. data/lib/brat/client/groups.rb +88 -0
  17. data/lib/brat/client/issues.rb +92 -0
  18. data/lib/brat/client/merge_requests.rb +107 -0
  19. data/lib/brat/client/milestones.rb +57 -0
  20. data/lib/brat/client/notes.rb +106 -0
  21. data/lib/brat/client/projects.rb +298 -0
  22. data/lib/brat/client/repositories.rb +78 -0
  23. data/lib/brat/client/snippets.rb +86 -0
  24. data/lib/brat/client/system_hooks.rb +58 -0
  25. data/lib/brat/client/users.rb +123 -0
  26. data/lib/brat/configuration.rb +40 -0
  27. data/lib/brat/error.rb +42 -0
  28. data/lib/brat/help.rb +44 -0
  29. data/lib/brat/objectified_hash.rb +24 -0
  30. data/lib/brat/request.rb +101 -0
  31. data/lib/brat/shell.rb +49 -0
  32. data/lib/brat/version.rb +3 -0
  33. data/spec/brat/cli_spec.rb +80 -0
  34. data/spec/brat/client/branches_spec.rb +103 -0
  35. data/spec/brat/client/groups_spec.rb +111 -0
  36. data/spec/brat/client/issues_spec.rb +122 -0
  37. data/spec/brat/client/merge_requests_spec.rb +124 -0
  38. data/spec/brat/client/milestones_spec.rb +66 -0
  39. data/spec/brat/client/notes_spec.rb +156 -0
  40. data/spec/brat/client/projects_spec.rb +357 -0
  41. data/spec/brat/client/repositories_spec.rb +92 -0
  42. data/spec/brat/client/snippets_spec.rb +85 -0
  43. data/spec/brat/client/system_hooks_spec.rb +69 -0
  44. data/spec/brat/client/users_spec.rb +192 -0
  45. data/spec/brat/objectified_hash_spec.rb +23 -0
  46. data/spec/brat/request_spec.rb +48 -0
  47. data/spec/brat_spec.rb +65 -0
  48. data/spec/fixtures/branch.json +1 -0
  49. data/spec/fixtures/branches.json +1 -0
  50. data/spec/fixtures/comment_merge_request.json +1 -0
  51. data/spec/fixtures/create_branch.json +1 -0
  52. data/spec/fixtures/create_merge_request.json +1 -0
  53. data/spec/fixtures/error_already_exists.json +1 -0
  54. data/spec/fixtures/group.json +60 -0
  55. data/spec/fixtures/group_create.json +1 -0
  56. data/spec/fixtures/group_member.json +1 -0
  57. data/spec/fixtures/group_member_delete.json +1 -0
  58. data/spec/fixtures/group_members.json +1 -0
  59. data/spec/fixtures/groups.json +2 -0
  60. data/spec/fixtures/issue.json +1 -0
  61. data/spec/fixtures/issues.json +1 -0
  62. data/spec/fixtures/key.json +1 -0
  63. data/spec/fixtures/keys.json +1 -0
  64. data/spec/fixtures/merge_request.json +1 -0
  65. data/spec/fixtures/merge_request_comments.json +1 -0
  66. data/spec/fixtures/merge_requests.json +1 -0
  67. data/spec/fixtures/milestone.json +1 -0
  68. data/spec/fixtures/milestones.json +1 -0
  69. data/spec/fixtures/note.json +1 -0
  70. data/spec/fixtures/notes.json +1 -0
  71. data/spec/fixtures/project.json +1 -0
  72. data/spec/fixtures/project_commit.json +13 -0
  73. data/spec/fixtures/project_commit_diff.json +10 -0
  74. data/spec/fixtures/project_commits.json +1 -0
  75. data/spec/fixtures/project_delete_key.json +8 -0
  76. data/spec/fixtures/project_events.json +1 -0
  77. data/spec/fixtures/project_for_user.json +1 -0
  78. data/spec/fixtures/project_fork_link.json +1 -0
  79. data/spec/fixtures/project_hook.json +1 -0
  80. data/spec/fixtures/project_hooks.json +1 -0
  81. data/spec/fixtures/project_issues.json +1 -0
  82. data/spec/fixtures/project_key.json +6 -0
  83. data/spec/fixtures/project_keys.json +6 -0
  84. data/spec/fixtures/project_tags.json +1 -0
  85. data/spec/fixtures/projects.json +1 -0
  86. data/spec/fixtures/protect_branch.json +1 -0
  87. data/spec/fixtures/session.json +1 -0
  88. data/spec/fixtures/snippet.json +1 -0
  89. data/spec/fixtures/snippets.json +1 -0
  90. data/spec/fixtures/system_hook.json +1 -0
  91. data/spec/fixtures/system_hook_test.json +1 -0
  92. data/spec/fixtures/system_hooks.json +1 -0
  93. data/spec/fixtures/tag.json +1 -0
  94. data/spec/fixtures/team_member.json +1 -0
  95. data/spec/fixtures/team_members.json +1 -0
  96. data/spec/fixtures/unprotect_branch.json +1 -0
  97. data/spec/fixtures/update_merge_request.json +1 -0
  98. data/spec/fixtures/user.json +1 -0
  99. data/spec/fixtures/users.json +1 -0
  100. data/spec/spec_helper.rb +74 -0
  101. metadata +281 -0
@@ -0,0 +1,92 @@
1
+ require 'spec_helper'
2
+
3
+ describe Brat::Client do
4
+ it { should respond_to :repo_tags }
5
+ it { should respond_to :repo_create_tag }
6
+ it { should respond_to :repo_branches }
7
+ it { should respond_to :repo_branch }
8
+ it { should respond_to :repo_commits }
9
+ it { should respond_to :repo_commit }
10
+ it { should respond_to :repo_commit_diff }
11
+
12
+ describe ".tags" do
13
+ before do
14
+ stub_get("/projects/3/repository/tags", "project_tags")
15
+ @tags = Brat.tags(3)
16
+ end
17
+
18
+ it "should get the correct resource" do
19
+ expect(a_get("/projects/3/repository/tags")).to have_been_made
20
+ end
21
+
22
+ it "should return an array of repository tags" do
23
+ expect(@tags).to be_an Array
24
+ expect(@tags.first.name).to eq("v2.8.2")
25
+ end
26
+ end
27
+
28
+ describe ".create_tag" do
29
+ before do
30
+ stub_post("/projects/3/repository/tags", "tag")
31
+ @tag = Brat.create_tag(3, 'v1.0.0', '2695effb5807a22ff3d138d593fd856244e155e7')
32
+ end
33
+
34
+ it "should get the correct resource" do
35
+ expect(a_post("/projects/3/repository/tags")).to have_been_made
36
+ end
37
+
38
+ it "should return information about a new repository tag" do
39
+ expect(@tag.name).to eq("v1.0.0")
40
+ end
41
+ end
42
+
43
+ describe ".commits" do
44
+ before do
45
+ stub_get("/projects/3/repository/commits", "project_commits").
46
+ with(:query => {:ref_name => "api"})
47
+ @commits = Brat.commits(3, :ref_name => "api")
48
+ end
49
+
50
+ it "should get the correct resource" do
51
+ expect(a_get("/projects/3/repository/commits").
52
+ with(:query => {:ref_name => "api"})).to have_been_made
53
+ end
54
+
55
+ it "should return an array of repository commits" do
56
+ expect(@commits).to be_an Array
57
+ expect(@commits.first.id).to eq("f7dd067490fe57505f7226c3b54d3127d2f7fd46")
58
+ end
59
+ end
60
+
61
+ describe ".commit" do
62
+ before do
63
+ stub_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6", "project_commit")
64
+ @commit = Brat.commit(3, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
65
+ end
66
+
67
+ it "should get the correct resource" do
68
+ expect(a_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6"))
69
+ .to have_been_made
70
+ end
71
+
72
+ it "should return a repository commit" do
73
+ expect(@commit.id).to eq("6104942438c14ec7bd21c6cd5bd995272b3faff6")
74
+ end
75
+ end
76
+
77
+ describe ".commit_diff" do
78
+ before do
79
+ stub_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/diff", "project_commit_diff")
80
+ @diff = Brat.commit_diff(3, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
81
+ end
82
+
83
+ it "should get the correct resource" do
84
+ expect(a_get("/projects/3/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/diff"))
85
+ .to have_been_made
86
+ end
87
+
88
+ it "should return a diff of a commit" do
89
+ expect(@diff.new_path).to eq("doc/update/5.4-to-6.0.md")
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe Brat::Client do
4
+ describe ".snippets" do
5
+ before do
6
+ stub_get("/projects/3/snippets", "snippets")
7
+ @snippets = Brat.snippets(3)
8
+ end
9
+
10
+ it "should get the correct resource" do
11
+ expect(a_get("/projects/3/snippets")).to have_been_made
12
+ end
13
+
14
+ it "should return an array of project's snippets" do
15
+ expect(@snippets).to be_an Array
16
+ expect(@snippets.first.file_name).to eq("mailer_test.rb")
17
+ end
18
+ end
19
+
20
+ describe ".snippet" do
21
+ before do
22
+ stub_get("/projects/3/snippets/1", "snippet")
23
+ @snippet = Brat.snippet(3, 1)
24
+ end
25
+
26
+ it "should get the correct resource" do
27
+ expect(a_get("/projects/3/snippets/1")).to have_been_made
28
+ end
29
+
30
+ it "should return information about a snippet" do
31
+ expect(@snippet.file_name).to eq("mailer_test.rb")
32
+ expect(@snippet.author.name).to eq("John Smith")
33
+ end
34
+ end
35
+
36
+ describe ".create_snippet" do
37
+ before do
38
+ stub_post("/projects/3/snippets", "snippet")
39
+ @snippet = Brat.create_snippet(3, {:title => 'API', :file_name => 'api.rb', :code => 'code'})
40
+ end
41
+
42
+ it "should get the correct resource" do
43
+ body = {:title => 'API', :file_name => 'api.rb', :code => 'code'}
44
+ expect(a_post("/projects/3/snippets").with(:body => body)).to have_been_made
45
+ end
46
+
47
+ it "should return information about a new snippet" do
48
+ expect(@snippet.file_name).to eq("mailer_test.rb")
49
+ expect(@snippet.author.name).to eq("John Smith")
50
+ end
51
+ end
52
+
53
+ describe ".edit_snippet" do
54
+ before do
55
+ stub_put("/projects/3/snippets/1", "snippet")
56
+ @snippet = Brat.edit_snippet(3, 1, :file_name => 'mailer_test.rb')
57
+ end
58
+
59
+ it "should get the correct resource" do
60
+ expect(a_put("/projects/3/snippets/1").
61
+ with(:body => {:file_name => 'mailer_test.rb'})).to have_been_made
62
+ end
63
+
64
+ it "should return information about an edited snippet" do
65
+ expect(@snippet.file_name).to eq("mailer_test.rb")
66
+ expect(@snippet.author.name).to eq("John Smith")
67
+ end
68
+ end
69
+
70
+ describe ".delete_snippet" do
71
+ before do
72
+ stub_delete("/projects/3/snippets/1", "snippet")
73
+ @snippet = Brat.delete_snippet(3, 1)
74
+ end
75
+
76
+ it "should get the correct resource" do
77
+ expect(a_delete("/projects/3/snippets/1")).to have_been_made
78
+ end
79
+
80
+ it "should return information about a deleted snippet" do
81
+ expect(@snippet.file_name).to eq("mailer_test.rb")
82
+ expect(@snippet.author.name).to eq("John Smith")
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe Brat::Client do
4
+ it { should respond_to :system_hooks }
5
+ it { should respond_to :add_system_hook }
6
+ it { should respond_to :system_hook }
7
+ it { should respond_to :delete_system_hook }
8
+
9
+ describe ".hooks" do
10
+ before do
11
+ stub_get("/hooks", "system_hooks")
12
+ @hooks = Brat.hooks
13
+ end
14
+
15
+ it "should get the correct resource" do
16
+ expect(a_get("/hooks")).to have_been_made
17
+ end
18
+
19
+ it "should return an array of system hooks" do
20
+ expect(@hooks).to be_an Array
21
+ expect(@hooks.first.url).to eq("http://example.com/hook")
22
+ end
23
+ end
24
+
25
+ describe ".add_hook" do
26
+ before do
27
+ stub_post("/hooks", "system_hook")
28
+ @hook = Brat.add_hook("http://example.com/hook")
29
+ end
30
+
31
+ it "should get the correct resource" do
32
+ expect(a_post("/hooks")).to have_been_made
33
+ end
34
+
35
+ it "should return information about a added system hook" do
36
+ expect(@hook.url).to eq("http://example.com/hook")
37
+ end
38
+ end
39
+
40
+ describe ".hook" do
41
+ before do
42
+ stub_get("/hooks/3", "system_hook_test")
43
+ @hook = Brat.hook(3)
44
+ end
45
+ it "should get the correct resource" do
46
+ expect(a_get("/hooks/3")).to have_been_made
47
+ end
48
+
49
+ it "should return information about a added system hook" do
50
+ expect(@hook.event_name).to eq("project_create")
51
+ expect(@hook.project_id).to eq(1)
52
+ end
53
+ end
54
+
55
+ describe ".delete_hook" do
56
+ before do
57
+ stub_delete("/hooks/3", "system_hook")
58
+ @hook = Brat.delete_hook(3)
59
+ end
60
+
61
+ it "should get the correct resource" do
62
+ expect(a_delete("/hooks/3")).to have_been_made
63
+ end
64
+
65
+ it "should return information about a deleted system hook" do
66
+ expect(@hook.url).to eq("http://example.com/hook")
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,192 @@
1
+ require 'spec_helper'
2
+
3
+ describe Brat::Client do
4
+ describe ".users" do
5
+ before do
6
+ stub_get("/users", "users")
7
+ @users = Brat.users
8
+ end
9
+
10
+ it "should get the correct resource" do
11
+ expect(a_get("/users")).to have_been_made
12
+ end
13
+
14
+ it "should return an array of users" do
15
+ expect(@users).to be_an Array
16
+ expect(@users.first.email).to eq("john@example.com")
17
+ end
18
+ end
19
+
20
+ describe ".user" do
21
+ context "with user ID passed" do
22
+ before do
23
+ stub_get("/users/1", "user")
24
+ @user = Brat.user(1)
25
+ end
26
+
27
+ it "should get the correct resource" do
28
+ expect(a_get("/users/1")).to have_been_made
29
+ end
30
+
31
+ it "should return information about a user" do
32
+ expect(@user.email).to eq("john@example.com")
33
+ end
34
+ end
35
+
36
+ context "without user ID passed" do
37
+ before do
38
+ stub_get("/user", "user")
39
+ @user = Brat.user
40
+ end
41
+
42
+ it "should get the correct resource" do
43
+ expect(a_get("/user")).to have_been_made
44
+ end
45
+
46
+ it "should return information about an authorized user" do
47
+ expect(@user.email).to eq("john@example.com")
48
+ end
49
+ end
50
+ end
51
+
52
+ describe ".create_user" do
53
+ context "when successful request" do
54
+ before do
55
+ stub_post("/users", "user")
56
+ @user = Brat.create_user("email", "pass")
57
+ end
58
+
59
+ it "should get the correct resource" do
60
+ body = {:email => "email", :password => "pass", :name => "email"}
61
+ expect(a_post("/users").with(:body => body)).to have_been_made
62
+ end
63
+
64
+ it "should return information about a created user" do
65
+ expect(@user.email).to eq("john@example.com")
66
+ end
67
+ end
68
+
69
+ context "when bad request" do
70
+ it "should throw an exception" do
71
+ stub_post("/users", "error_already_exists", 409)
72
+ expect {
73
+ Brat.create_user("email", "pass")
74
+ }.to raise_error(Brat::Error::Conflict, "Server responded with code 409, message: 409 Already exists. Request URI: #{Brat.endpoint}/users")
75
+ end
76
+ end
77
+ end
78
+
79
+ describe ".edit_user" do
80
+ before do
81
+ @options = { :name => "Roberto" }
82
+ stub_put("/users/1", "user").with(:body => @options)
83
+ @user = Brat.edit_user(1, @options)
84
+ end
85
+
86
+ it "should get the correct resource" do
87
+ expect(a_put("/users/1").with(:body => @options)).to have_been_made
88
+ end
89
+ end
90
+
91
+ describe ".session" do
92
+ after do
93
+ Brat.endpoint = 'https://api.example.com'
94
+ Brat.private_token = 'secret'
95
+ end
96
+
97
+ before do
98
+ stub_request(:post, "#{Brat.endpoint}/session").
99
+ to_return(:body => load_fixture('session'), :status => 200)
100
+ @session = Brat.session("email", "pass")
101
+ end
102
+
103
+ context "when endpoint is not set" do
104
+ it "should raise Error::MissingCredentials" do
105
+ Brat.endpoint = nil
106
+ expect {
107
+ Brat.session("email", "pass")
108
+ }.to raise_error(Brat::Error::MissingCredentials, 'Please set an endpoint to API')
109
+ end
110
+ end
111
+
112
+ context "when private_token is not set" do
113
+ it "should not raise Error::MissingCredentials" do
114
+ Brat.private_token = nil
115
+ expect { Brat.session("email", "pass") }.to_not raise_error
116
+ end
117
+ end
118
+
119
+ context "when endpoint is set" do
120
+ it "should get the correct resource" do
121
+ expect(a_request(:post, "#{Brat.endpoint}/session")).to have_been_made
122
+ end
123
+
124
+ it "should return information about a created session" do
125
+ expect(@session.email).to eq("john@example.com")
126
+ expect(@session.private_token).to eq("qEsq1pt6HJPaNciie3MG")
127
+ end
128
+ end
129
+ end
130
+
131
+ describe ".ssh_keys" do
132
+ before do
133
+ stub_get("/user/keys", "keys")
134
+ @keys = Brat.ssh_keys
135
+ end
136
+
137
+ it "should get the correct resource" do
138
+ expect(a_get("/user/keys")).to have_been_made
139
+ end
140
+
141
+ it "should return an array of SSH keys" do
142
+ expect(@keys).to be_an Array
143
+ expect(@keys.first.title).to eq("narkoz@helium")
144
+ end
145
+ end
146
+
147
+ describe ".ssh_key" do
148
+ before do
149
+ stub_get("/user/keys/1", "key")
150
+ @key = Brat.ssh_key(1)
151
+ end
152
+
153
+ it "should get the correct resource" do
154
+ expect(a_get("/user/keys/1")).to have_been_made
155
+ end
156
+
157
+ it "should return information about an SSH key" do
158
+ expect(@key.title).to eq("narkoz@helium")
159
+ end
160
+ end
161
+
162
+ describe ".create_ssh_key" do
163
+ before do
164
+ stub_post("/user/keys", "key")
165
+ @key = Brat.create_ssh_key("title", "body")
166
+ end
167
+
168
+ it "should get the correct resource" do
169
+ body = {:title => "title", :key => "body"}
170
+ expect(a_post("/user/keys").with(:body => body)).to have_been_made
171
+ end
172
+
173
+ it "should return information about a created SSH key" do
174
+ expect(@key.title).to eq("narkoz@helium")
175
+ end
176
+ end
177
+
178
+ describe ".delete_ssh_key" do
179
+ before do
180
+ stub_delete("/user/keys/1", "key")
181
+ @key = Brat.delete_ssh_key(1)
182
+ end
183
+
184
+ it "should get the correct resource" do
185
+ expect(a_delete("/user/keys/1")).to have_been_made
186
+ end
187
+
188
+ it "should return information about a deleted SSH key" do
189
+ expect(@key.title).to eq("narkoz@helium")
190
+ end
191
+ end
192
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Brat::ObjectifiedHash do
4
+ before do
5
+ @hash = {a: 1, b: 2}
6
+ @oh = Brat::ObjectifiedHash.new @hash
7
+ end
8
+
9
+ it "should objectify hash" do
10
+ expect(@oh.a).to eq(@hash[:a])
11
+ expect(@oh.b).to eq(@hash[:b])
12
+ end
13
+
14
+ describe "#to_hash" do
15
+ it "should return an original hash" do
16
+ expect(@oh.to_hash).to eq(@hash)
17
+ end
18
+
19
+ it "should have an alias #to_h" do
20
+ expect(@oh.respond_to?(:to_h)).to be_truthy
21
+ end
22
+ end
23
+ end