tinybucket 1.0.1 → 1.1.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 (82) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -5
  3. data/README.md +100 -24
  4. data/lib/tinybucket.rb +1 -0
  5. data/lib/tinybucket/api.rb +1 -0
  6. data/lib/tinybucket/api/build_status_api.rb +55 -0
  7. data/lib/tinybucket/api/helper.rb +1 -0
  8. data/lib/tinybucket/api/helper/build_status_helper.rb +35 -0
  9. data/lib/tinybucket/client.rb +28 -45
  10. data/lib/tinybucket/enumerator.rb +4 -3
  11. data/lib/tinybucket/model.rb +2 -1
  12. data/lib/tinybucket/model/base.rb +1 -17
  13. data/lib/tinybucket/model/build_status.rb +55 -0
  14. data/lib/tinybucket/model/commit.rb +32 -15
  15. data/lib/tinybucket/model/concerns.rb +1 -0
  16. data/lib/tinybucket/model/concerns/api_callable.rb +19 -0
  17. data/lib/tinybucket/model/profile.rb +9 -26
  18. data/lib/tinybucket/model/pull_request.rb +18 -28
  19. data/lib/tinybucket/model/repository.rb +29 -76
  20. data/lib/tinybucket/model/team.rb +9 -34
  21. data/lib/tinybucket/parser.rb +1 -0
  22. data/lib/tinybucket/parser/build_status_parser.rb +9 -0
  23. data/lib/tinybucket/resource.rb +70 -0
  24. data/lib/tinybucket/resource/base.rb +29 -0
  25. data/lib/tinybucket/resource/branch_restrictions.rb +45 -0
  26. data/lib/tinybucket/resource/commit/base.rb +12 -0
  27. data/lib/tinybucket/resource/commit/build_statuses.rb +47 -0
  28. data/lib/tinybucket/resource/commit/comments.rb +32 -0
  29. data/lib/tinybucket/resource/commits.rb +33 -0
  30. data/lib/tinybucket/resource/forks.rb +22 -0
  31. data/lib/tinybucket/resource/pull_request/base.rb +18 -0
  32. data/lib/tinybucket/resource/pull_request/comments.rb +30 -0
  33. data/lib/tinybucket/resource/pull_request/commits.rb +17 -0
  34. data/lib/tinybucket/resource/pull_requests.rb +48 -0
  35. data/lib/tinybucket/resource/repos.rb +38 -0
  36. data/lib/tinybucket/resource/team/base.rb +22 -0
  37. data/lib/tinybucket/resource/team/followers.rb +13 -0
  38. data/lib/tinybucket/resource/team/following.rb +13 -0
  39. data/lib/tinybucket/resource/team/members.rb +13 -0
  40. data/lib/tinybucket/resource/team/repos.rb +13 -0
  41. data/lib/tinybucket/resource/user/base.rb +24 -0
  42. data/lib/tinybucket/resource/user/followers.rb +13 -0
  43. data/lib/tinybucket/resource/user/following.rb +13 -0
  44. data/lib/tinybucket/resource/user/repos.rb +13 -0
  45. data/lib/tinybucket/resource/watchers.rb +22 -0
  46. data/lib/tinybucket/version.rb +1 -1
  47. data/spec/fixtures/build_status.json +16 -0
  48. data/spec/fixtures/repositories/test_owner/get.json +1 -1
  49. data/spec/fixtures/repositories/test_owner/test_repo/commit/1/statuses/build/post.json +16 -0
  50. data/spec/fixtures/repositories/test_owner/test_repo/commit/1/statuses/build/test_status/get.json +16 -0
  51. data/spec/fixtures/repositories/test_owner/test_repo/commit/1/statuses/build/test_status/put.json +16 -0
  52. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/comments/get.json +1 -1
  53. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/1/commits/get.json +1 -1
  54. data/spec/fixtures/repositories/test_owner/test_repo/pullrequests/get.json +1 -1
  55. data/spec/fixtures/repositories/test_owner/test_repo/watchers/get.json +1 -1
  56. data/spec/lib/tinybucket/api/build_status_api_spec.rb +65 -0
  57. data/spec/lib/tinybucket/client_spec.rb +8 -4
  58. data/spec/lib/tinybucket/model/build_status_spec.rb +66 -0
  59. data/spec/lib/tinybucket/model/commit_spec.rb +19 -1
  60. data/spec/lib/tinybucket/model/profile_spec.rb +3 -3
  61. data/spec/lib/tinybucket/model/pull_request_spec.rb +3 -15
  62. data/spec/lib/tinybucket/model/repository_spec.rb +14 -20
  63. data/spec/lib/tinybucket/model/team_spec.rb +16 -4
  64. data/spec/lib/tinybucket/resource/branch_restrictions_spec.rb +60 -0
  65. data/spec/lib/tinybucket/resource/commit/build_statuses_spec.rb +50 -0
  66. data/spec/lib/tinybucket/resource/commit/comments_spec.rb +49 -0
  67. data/spec/lib/tinybucket/resource/commits_spec.rb +43 -0
  68. data/spec/lib/tinybucket/resource/forks_spec.rb +36 -0
  69. data/spec/lib/tinybucket/resource/pull_request/comments_spec.rb +41 -0
  70. data/spec/lib/tinybucket/resource/pull_request/commits_spec.rb +41 -0
  71. data/spec/lib/tinybucket/resource/pull_requests_spec.rb +59 -0
  72. data/spec/lib/tinybucket/resource/repos_spec.rb +76 -0
  73. data/spec/lib/tinybucket/resource/team/followers_spec.rb +27 -0
  74. data/spec/lib/tinybucket/resource/team/following_spec.rb +27 -0
  75. data/spec/lib/tinybucket/resource/team/members_spec.rb +27 -0
  76. data/spec/lib/tinybucket/resource/team/repos_spec.rb +27 -0
  77. data/spec/lib/tinybucket/resource/user/followers_spec.rb +27 -0
  78. data/spec/lib/tinybucket/resource/user/following_spec.rb +27 -0
  79. data/spec/lib/tinybucket/resource/user/repos_spec.rb +27 -0
  80. data/spec/lib/tinybucket/resource/watchers_spec.rb +38 -0
  81. data/spec/support/api_response_macros.rb +45 -1
  82. metadata +77 -3
@@ -31,64 +31,39 @@ module Tinybucket
31
31
  # Get this team's members.
32
32
  #
33
33
  # @param options [Hash]
34
- # @return [Tinybucket::Enumerator] an enumerator to enumerate members
35
- # as {Tinybucket::Model::Team} instance.
34
+ # @return [Tinybucket::Resource::Team::Members]
36
35
  def members(options = {})
37
- enumerator(
38
- team_api,
39
- :members,
40
- username,
41
- options
42
- ) { |m| block_given? ? yield(m) : m }
36
+ Tinybucket::Resource::Team::Members.new(username, options)
43
37
  end
44
38
 
45
39
  # Get this team's followers.
46
40
  #
47
41
  # @param options [Hash]
48
- # @return [Tinybucket::Enumerator] an enumerator to enumerate followers
49
- # as {Tinybucket::Model::Team} instance.
42
+ # @return [Tinybucket::Resource::Team::Followers]
50
43
  def followers(options = {})
51
- enumerator(
52
- team_api,
53
- :followers,
54
- username,
55
- options
56
- ) { |m| block_given? ? yield(m) : m }
44
+ Tinybucket::Resource::Team::Followers.new(username, options)
57
45
  end
58
46
 
59
47
  # Get users which this team is following.
60
48
  #
61
49
  # @param options [Hash]
62
- # @return [Tinybucket::Enumerator] an enumerator to enumerate followings
63
- # as {Tinybucket::Model::Team} instance.
50
+ # @return [Tinybucket::Resource::Team::Following]
64
51
  def following(options = {})
65
- enumerator(
66
- team_api,
67
- :following,
68
- username,
69
- options
70
- ) { |m| block_given? ? yield(m) : m }
52
+ Tinybucket::Resource::Team::Following.new(username, options)
71
53
  end
72
54
 
73
55
  # Get this team's repositories.
74
56
  #
75
57
  # @param options [Hash]
76
- # @return [Tinybucket::Enumerator] an enumerator to enumerate repositories
77
- # as {Tinybucket::Model::Repository} instance.
58
+ # @return [Tinybucket::Resource::Team::Repos]
78
59
  def repos(options = {})
79
- enumerator(
80
- team_api,
81
- :repos,
82
- username,
83
- options
84
- ) { |m| block_given? ? yield(m) : m }
60
+ Tinybucket::Resource::Team::Repos.new(username, options)
85
61
  end
86
62
 
87
63
  private
88
64
 
89
65
  def team_api
90
- return @team if @team
91
- @team = create_instance('Team')
66
+ create_api('Team')
92
67
  end
93
68
 
94
69
  def load_model
@@ -6,6 +6,7 @@ module Tinybucket
6
6
  :BaseParser,
7
7
  :BranchRestrictionParser,
8
8
  :BranchRestrictionsParser,
9
+ :BuildStatusParser,
9
10
  :CommitParser,
10
11
  :CommitsParser,
11
12
  :CommentParser,
@@ -0,0 +1,9 @@
1
+ module Tinybucket
2
+ module Parser
3
+ class BuildStatusParser < BaseParser
4
+ def convert(json)
5
+ Tinybucket::Model::BuildStatus.new(json)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,70 @@
1
+ module Tinybucket
2
+ module Resource
3
+ extend ActiveSupport::Autoload
4
+
5
+ [
6
+ :Base,
7
+ :BranchRestrictions,
8
+ :Commits,
9
+ :Forks,
10
+ :OwnersRepos,
11
+ :PublicRepos,
12
+ :PullRequests,
13
+ :Repos,
14
+ :Watchers
15
+ ].each do |klass_name|
16
+ autoload klass_name
17
+ end
18
+
19
+ module Team
20
+ extend ActiveSupport::Autoload
21
+
22
+ [
23
+ :Base,
24
+ :Followers,
25
+ :Following,
26
+ :Members,
27
+ :Repos
28
+ ].each do |klass_name|
29
+ autoload klass_name
30
+ end
31
+ end
32
+
33
+ module User
34
+ extend ActiveSupport::Autoload
35
+
36
+ [
37
+ :Base,
38
+ :Followers,
39
+ :Following,
40
+ :Repos
41
+ ].each do |klass_name|
42
+ autoload klass_name
43
+ end
44
+ end
45
+
46
+ module PullRequest
47
+ extend ActiveSupport::Autoload
48
+
49
+ [
50
+ :Base,
51
+ :Commits,
52
+ :Comments
53
+ ].each do |klass_name|
54
+ autoload klass_name
55
+ end
56
+ end
57
+
58
+ module Commit
59
+ extend ActiveSupport::Autoload
60
+
61
+ [
62
+ :Base,
63
+ :BuildStatuses,
64
+ :Comments
65
+ ].each do |klass_name|
66
+ autoload klass_name
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,29 @@
1
+ module Tinybucket
2
+ module Resource
3
+ class Base
4
+ include Tinybucket::Model::Concerns::ApiCallable
5
+
6
+ protected
7
+
8
+ def method_missing(method, *args)
9
+ enum = enumerator
10
+ return super unless enum.respond_to?(method)
11
+
12
+ enum.send(method, *args) do |m|
13
+ block_given? ? yield(m) : m
14
+ end
15
+ end
16
+
17
+ def create_enumerator(api_client, method, *args, &block)
18
+ iter = Tinybucket::Iterator.new(api_client, method, *args)
19
+ Tinybucket::Enumerator.new(iter, block)
20
+ end
21
+
22
+ def inject_repo_keys(model, repo_keys)
23
+ return model unless model.respond_to?(:repo_keys=)
24
+
25
+ model.tap { |m| m.repo_keys = repo_keys }
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,45 @@
1
+ module Tinybucket
2
+ module Resource
3
+ class BranchRestrictions < Base
4
+ # Constructor
5
+ #
6
+ # @param repo [Tinybucket::Model::Repository]
7
+ # @param options [Hash]
8
+ def initialize(repo, options)
9
+ @repo = repo
10
+ @args = [options]
11
+ end
12
+
13
+ # Create new BranchRestriction on the repository.
14
+ #
15
+ # @param _options [Hash]
16
+ # @return [Tinybucket::Model::BranchRestriction]
17
+ def create(_options)
18
+ raise NotImplementedError
19
+ end
20
+
21
+ # Find the BranchRestriction on the repository.
22
+ #
23
+ # @param restriction_id [String]
24
+ # @param options [Hash]
25
+ # @return [Tinybucket::Model::BranchRestriction]
26
+ def find(restriction_id, options = {})
27
+ restrictions_api.find(restriction_id, options).tap do |m|
28
+ inject_repo_keys(m, @repo.repo_keys)
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def restrictions_api
35
+ create_api('BranchRestrictions', @repo.repo_keys)
36
+ end
37
+
38
+ def enumerator
39
+ create_enumerator(restrictions_api, :list, *@args) do |m|
40
+ inject_repo_keys(m, @repo.repo_keys)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,12 @@
1
+ module Tinybucket
2
+ module Resource
3
+ module Commit
4
+ class Base < Tinybucket::Resource::Base
5
+ def initialize(commit, options)
6
+ @commit = commit
7
+ @args = [options]
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,47 @@
1
+ module Tinybucket
2
+ module Resource
3
+ module Commit
4
+ class BuildStatuses < Tinybucket::Resource::Commit::Base
5
+ # Get the build status for the commit
6
+ #
7
+ # @param key [String]
8
+ # @param options [Hash]
9
+ # @option options [String] :state
10
+ # @option options [String] :key
11
+ # @option options [String] :name
12
+ # @option options [String] :url
13
+ # @option options [String] :description
14
+ # @return [Tinybucket::Model::BuildStatus]
15
+ def find(key, options = {})
16
+ build_status_api.find(@commit.hash, key, options).tap do |m|
17
+ m.revision = @commit.hash
18
+ m.repo_keys = @commit.repo_keys
19
+ end
20
+ end
21
+
22
+ # Create a build status for the commit
23
+ #
24
+ # @param key [String]
25
+ # @param options [Hash]
26
+ # @return [Tinybucket::Model::BuildStatus]
27
+ def create(key, options)
28
+ build_status_api.post(@commit.hash, key, options).tap do |m|
29
+ m.revision = @commit.hash
30
+ m.repo_keys = @commit.repo_keys
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def build_status_api
37
+ create_api('BuildStatus', @commit.repo_keys)
38
+ end
39
+
40
+ # FIXME: raise NoMethodError on method_missing.
41
+ def enumerator
42
+ nil
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,32 @@
1
+ module Tinybucket
2
+ module Resource
3
+ module Commit
4
+ class Comments < Tinybucket::Resource::Commit::Base
5
+ # Get the specific commit comment which associate with the commit.
6
+ #
7
+ # @param comment_id [String]
8
+ # @param options [Hash]
9
+ # @return [Tinybucket::Model::Comment]
10
+ def find(comment_id, options = {})
11
+ comments_api.find(comment_id, options).tap do |m|
12
+ m.repo_keys = @commit.repo_keys
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def comments_api
19
+ create_api('Comments', @commit.repo_keys).tap do |api|
20
+ api.commented_to = @commit
21
+ end
22
+ end
23
+
24
+ def enumerator
25
+ create_enumerator(comments_api, :list, *@args) do |m|
26
+ inject_repo_keys(m, @commit.repo_keys)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,33 @@
1
+ module Tinybucket
2
+ module Resource
3
+ class Commits < Base
4
+ def initialize(repo, options)
5
+ @repo = repo
6
+ @args = [options]
7
+ end
8
+
9
+ # Find the commit
10
+ #
11
+ # @param revision [String]
12
+ # @param options [Hash]
13
+ # @return [Tinybucket::Model::Commit]
14
+ def find(revision, options = {})
15
+ commits_api.find(revision, options).tap do |m|
16
+ inject_repo_keys(m, @repo.repo_keys)
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def commits_api
23
+ create_api('Commits', @repo.repo_keys)
24
+ end
25
+
26
+ def enumerator
27
+ create_enumerator(commits_api, :list, *@args) do |m|
28
+ inject_repo_keys(m, @repo.repo_keys)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,22 @@
1
+ module Tinybucket
2
+ module Resource
3
+ class Forks < Base
4
+ def initialize(repo, options)
5
+ @repo = repo
6
+ @args = [options]
7
+ end
8
+
9
+ private
10
+
11
+ def repo_api
12
+ create_api('Repo', @repo.repo_keys)
13
+ end
14
+
15
+ def enumerator
16
+ create_enumerator(repo_api, :forks, *@args) do |m|
17
+ inject_repo_keys(m, @repo.repo_keys)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ module Tinybucket
2
+ module Resource
3
+ module PullRequest
4
+ class Base < Tinybucket::Resource::Base
5
+ def initialize(pull_request, options)
6
+ @pull_request = pull_request
7
+ @args = [options]
8
+ end
9
+
10
+ protected
11
+
12
+ def pull_request_api
13
+ create_api('PullRequests', @pull_request.repo_keys)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,30 @@
1
+ module Tinybucket
2
+ module Resource
3
+ module PullRequest
4
+ class Comments < Tinybucket::Resource::PullRequest::Base
5
+ # Get the specific comment on the pull request.
6
+ #
7
+ # @param comment_id [String]
8
+ # @param options [Hash]
9
+ # @return [Tinybucket::Model::Comment]
10
+ def find(comment_id, options)
11
+ comment_api.find(comment_id, options)
12
+ end
13
+
14
+ private
15
+
16
+ def comment_api
17
+ create_api('Comments', @pull_request.repo_keys).tap do |api|
18
+ api.commented_to = @pull_request
19
+ end
20
+ end
21
+
22
+ def enumerator
23
+ create_enumerator(comment_api, :list, *@args) do |m|
24
+ inject_repo_keys(m, @pull_request.repo_keys)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end