github_api 0.4.11 → 0.5.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. data/README.md +76 -72
  2. data/features/cassettes/gists/starred.yml +48 -0
  3. data/features/cassettes/pagination/repos/commits/list.yml +193 -0
  4. data/features/cassettes/pagination/repos/commits/next.yml +183 -0
  5. data/features/cassettes/pagination/repos/diff/next.yml +45 -0
  6. data/features/cassettes/pagination/repos/list.yml +176 -0
  7. data/features/cassettes/pagination/repos/list/next.yml +222 -0
  8. data/features/cassettes/pagination/repos/per_page/each_page.yml +45 -0
  9. data/features/cassettes/repos/list.yml +92 -0
  10. data/features/error_codes.feature +1 -1
  11. data/features/gists.feature +12 -3
  12. data/features/gists/comments.feature +3 -3
  13. data/features/github_api.feature +13 -2
  14. data/features/pagination.feature +40 -39
  15. data/features/repos.feature +2 -2
  16. data/features/step_definitions/common_steps.rb +12 -0
  17. data/features/step_definitions/github_api_steps.rb +12 -1
  18. data/lib/github_api.rb +1 -1
  19. data/lib/github_api/api.rb +4 -2
  20. data/lib/github_api/api_factory.rb +11 -5
  21. data/lib/github_api/authorizations.rb +23 -32
  22. data/lib/github_api/client.rb +1 -0
  23. data/lib/github_api/events.rb +38 -38
  24. data/lib/github_api/filter.rb +1 -1
  25. data/lib/github_api/gists.rb +47 -42
  26. data/lib/github_api/gists/comments.rb +77 -84
  27. data/lib/github_api/git_data.rb +25 -6
  28. data/lib/github_api/git_data/blobs.rb +48 -45
  29. data/lib/github_api/git_data/commits.rb +76 -73
  30. data/lib/github_api/git_data/references.rb +137 -118
  31. data/lib/github_api/git_data/tags.rb +74 -70
  32. data/lib/github_api/git_data/trees.rb +88 -85
  33. data/lib/github_api/issues.rb +43 -31
  34. data/lib/github_api/issues/comments.rb +116 -119
  35. data/lib/github_api/issues/events.rb +20 -19
  36. data/lib/github_api/issues/labels.rb +200 -197
  37. data/lib/github_api/issues/milestones.rb +137 -134
  38. data/lib/github_api/orgs.rb +27 -23
  39. data/lib/github_api/orgs/members.rb +105 -108
  40. data/lib/github_api/orgs/teams.rb +236 -237
  41. data/lib/github_api/paged_request.rb +1 -1
  42. data/lib/github_api/pull_requests.rb +40 -42
  43. data/lib/github_api/pull_requests/comments.rb +140 -143
  44. data/lib/github_api/repos.rb +101 -67
  45. data/lib/github_api/repos/collaborators.rb +64 -68
  46. data/lib/github_api/repos/commits.rb +50 -39
  47. data/lib/github_api/repos/downloads.rb +107 -110
  48. data/lib/github_api/repos/forks.rb +38 -39
  49. data/lib/github_api/repos/hooks.rb +161 -167
  50. data/lib/github_api/repos/keys.rb +86 -86
  51. data/lib/github_api/repos/pub_sub_hubbub.rb +99 -87
  52. data/lib/github_api/repos/watching.rb +80 -82
  53. data/lib/github_api/request.rb +5 -9
  54. data/lib/github_api/users.rb +26 -16
  55. data/lib/github_api/users/emails.rb +47 -47
  56. data/lib/github_api/users/followers.rb +85 -86
  57. data/lib/github_api/users/keys.rb +73 -75
  58. data/lib/github_api/validations.rb +25 -0
  59. data/lib/github_api/validations/format.rb +23 -0
  60. data/lib/github_api/validations/presence.rb +25 -0
  61. data/lib/github_api/validations/required.rb +21 -0
  62. data/lib/github_api/validations/token.rb +41 -0
  63. data/lib/github_api/version.rb +3 -3
  64. data/spec/fixtures/repos/commit_comparison.json +112 -0
  65. data/spec/github/api_factory_spec.rb +17 -1
  66. data/spec/github/authorizations_spec.rb +36 -34
  67. data/spec/github/gists/comments_spec.rb +39 -45
  68. data/spec/github/gists_spec.rb +50 -53
  69. data/spec/github/git_data/blobs_spec.rb +27 -20
  70. data/spec/github/git_data/commits_spec.rb +20 -19
  71. data/spec/github/git_data/references_spec.rb +83 -46
  72. data/spec/github/git_data/tags_spec.rb +16 -15
  73. data/spec/github/git_data/trees_spec.rb +20 -19
  74. data/spec/github/git_data_spec.rb +10 -1
  75. data/spec/github/issues/comments_spec.rb +78 -68
  76. data/spec/github/issues/events_spec.rb +42 -34
  77. data/spec/github/issues/labels_spec.rb +89 -101
  78. data/spec/github/issues/milestones_spec.rb +76 -54
  79. data/spec/github/issues_spec.rb +53 -57
  80. data/spec/github/orgs/members_spec.rb +64 -49
  81. data/spec/github/orgs/teams_spec.rb +112 -101
  82. data/spec/github/orgs_spec.rb +41 -31
  83. data/spec/github/paged_request_spec.rb +6 -5
  84. data/spec/github/pull_requests/comments_spec.rb +39 -44
  85. data/spec/github/pull_requests_spec.rb +32 -48
  86. data/spec/github/repos/collaborators_spec.rb +40 -29
  87. data/spec/github/repos/commits_spec.rb +108 -64
  88. data/spec/github/repos/downloads_spec.rb +46 -45
  89. data/spec/github/repos/forks_spec.rb +23 -24
  90. data/spec/github/repos/hooks_spec.rb +69 -71
  91. data/spec/github/repos/keys_spec.rb +39 -34
  92. data/spec/github/repos/pub_sub_hubbub_spec.rb +4 -4
  93. data/spec/github/repos/watching_spec.rb +31 -33
  94. data/spec/github/repos_spec.rb +74 -83
  95. data/spec/github/request_spec.rb +31 -2
  96. data/spec/github/users/emails_spec.rb +19 -17
  97. data/spec/github/users/followers_spec.rb +30 -28
  98. data/spec/github/users/keys_spec.rb +37 -33
  99. data/spec/github/users_spec.rb +124 -125
  100. data/spec/github/validations/format_spec.rb +42 -0
  101. data/spec/github/validations/presence_spec.rb +18 -0
  102. data/spec/github/validations/required_spec.rb +28 -0
  103. data/spec/github/validations/token_spec.rb +19 -0
  104. data/spec/github/validations_spec.rb +23 -0
  105. metadata +33 -10
  106. data/features/cassettes/pagination/repos.yml +0 -177
  107. data/features/cassettes/pagination/repos/next.yml +0 -177
  108. data/lib/github_api/validation.rb +0 -53
  109. data/spec/github/validation_spec.rb +0 -62
@@ -1,126 +1,145 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Github
4
- class GitData
5
- module References
6
-
7
- VALID_REF_PARAM_NAMES = %w[ ref sha force ].freeze
8
-
9
- VALID_REF_PARAM_VALUES = {
10
- 'ref' => %r{^refs\/\w+\/\w+(\/\w+)*} # test fully qualified reference
11
- }
12
-
13
- # Get all references
14
- #
15
- # This will return an array of all the references on the system,
16
- # including things like notes and stashes if they exist on the server.
17
- # Anything in the namespace, not just <tt>heads</tt> and <tt>tags</tt>,
18
- # though that would be the most common.
19
- #
20
- # = Examples
21
- # @github = Github.new
22
- # @github.git_data.references 'user-name', 'repo-name'
23
- #
24
- # @github.git_data.references 'user-name', 'repo-name', 'tags'
25
- #
26
- def references(user_name, repo_name, ref=nil, params={})
27
- _update_user_repo_params(user_name, repo_name)
28
- _validate_user_repo_params(user, repo) unless user? && repo?
29
- _normalize_params_keys(params)
30
-
31
- response = if ref
32
- _validate_reference ref
33
- get("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
34
- else
35
- get("/repos/#{user}/#{repo}/git/refs", params)
36
- end
37
- return response unless block_given?
38
- response.each { |el| yield el }
39
- end
40
- alias :list_references :references
41
- alias :get_all_references :references
42
-
43
- # Get a reference
44
- #
45
- # The ref in the URL must be formatted as <tt>heads/branch</tt>,
46
- # not just branch. For example, the call to get the data for a
47
- # branch named <tt>sc/featureA</tt> would be formatted as
48
- # <tt>heads/sc/featureA</tt>
49
- #
50
- # = Examples
51
- # @github = Github.new
52
- # @github.git_data.reference 'user-name', 'repo-name', 'reference'
53
- #
54
- def reference(user_name, repo_name, ref, params={})
55
- _update_user_repo_params(user_name, repo_name)
56
- _validate_user_repo_params(user, repo) unless user? && repo?
57
-
58
- _validate_presence_of ref
4
+ class GitData::References < API
5
+
6
+ VALID_REF_PARAM_NAMES = %w[ ref sha force ].freeze
7
+
8
+ VALID_REF_PARAM_VALUES = {
9
+ 'ref' => %r{^refs\/\w+\/\w+(\/\w+)*} # test fully qualified reference
10
+ }
11
+
12
+ # Creates new GitData::References API
13
+ def initialize(options = {})
14
+ super(options)
15
+ end
16
+
17
+ # Get all references
18
+ #
19
+ # This will return an array of all the references on the system,
20
+ # including things like notes and stashes if they exist on the server.
21
+ # Anything in the namespace, not just <tt>heads</tt> and <tt>tags</tt>,
22
+ # though that would be the most common.
23
+ #
24
+ # = Examples
25
+ # github = Github.new
26
+ # github.git_data.references.list 'user-name', 'repo-name'
27
+ #
28
+ # github.git_data.references.list 'user-name', 'repo-name', 'tags'
29
+ #
30
+ def list(user_name, repo_name, ref=nil, params={})
31
+ _update_user_repo_params(user_name, repo_name)
32
+ _validate_user_repo_params(user, repo) unless user? && repo?
33
+ _normalize_params_keys(params)
34
+
35
+ response = if ref
59
36
  _validate_reference ref
60
- _normalize_params_keys params
61
-
62
- get("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
63
- end
64
- alias :get_reference :reference
65
-
66
-
67
- # Create a reference
68
- #
69
- # = Inputs
70
- # * <tt>:ref</tt> - String of the name of the fully qualified reference (ie: refs/heads/master). If it doesn’t start with ‘refs’ and have at least two slashes, it will be rejected.
71
- # * <tt>:sha</tt> - String of the SHA1 value to set this reference to
72
- #
73
- # = Examples
74
- # @github = Github.new
75
- # @github.git_data.create_reference 'user-name', 'repo-name',
76
- # "ref" => "refs/heads/master",
77
- # "sha" => "827efc6d56897b048c772eb4087f854f46256132"
78
- #
79
- def create_reference(user_name, repo_name, params={})
80
- _update_user_repo_params(user_name, repo_name)
81
- _validate_user_repo_params(user, repo) unless user? && repo?
82
-
83
- _normalize_params_keys params
84
- _filter_params_keys VALID_REF_PARAM_NAMES, params
85
- _validate_reference params['ref']
86
- _validate_inputs(%w[ ref sha ], params)
87
-
88
- post("/repos/#{user}/#{repo}/git/refs", params)
37
+ get_request("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
38
+ else
39
+ get_request("/repos/#{user}/#{repo}/git/refs", params)
89
40
  end
90
-
91
- # Update a reference
92
- #
93
- # = Inputs
94
- # * <tt>:sha</tt> - String of the SHA1 value to set this reference to
95
- # * <tt>:force</tt> - Boolean indicating whether to force the update or to make sure the update is a fast-forward update. The default is <tt>false</tt>, so leaving this out or setting it to false will make sure you’re not overwriting work.
96
- #
97
- # = Examples
98
- # @github = Github.new
99
- # @github.git_data.create_reference 'user-name', 'repo-name',
100
- # "sha" => "827efc6d56897b048c772eb4087f854f46256132",
101
- # "force" => true
102
- #
103
- def update_reference(user_name, repo_name, ref, params={})
104
- _update_user_repo_params(user_name, repo_name)
105
- _validate_user_repo_params(user, repo) unless user? && repo?
106
-
107
- _validate_presence_of ref
108
- _validate_reference ref
109
- _normalize_params_keys(params)
110
- _filter_params_keys(VALID_REF_PARAM_NAMES, params)
111
- _validate_inputs(%w[ sha ], params)
112
-
113
- patch("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
114
- end
115
-
116
- private
117
-
118
- def _validate_reference ref
119
- unless VALID_REF_PARAM_VALUES['ref'] =~ "refs/#{ref}"
120
- raise ArgumentError, "Provided 'reference' is invalid"
121
- end
41
+ return response unless block_given?
42
+ response.each { |el| yield el }
43
+ end
44
+ alias :all :list
45
+
46
+ # Get a reference
47
+ #
48
+ # The ref in the URL must be formatted as <tt>heads/branch</tt>,
49
+ # not just branch. For example, the call to get the data for a
50
+ # branch named <tt>sc/featureA</tt> would be formatted as
51
+ # <tt>heads/sc/featureA</tt>
52
+ #
53
+ # = Examples
54
+ # github = Github.new
55
+ # github.git_data.references.get 'user-name', 'repo-name', 'reference'
56
+ #
57
+ def get(user_name, repo_name, ref, params={})
58
+ _update_user_repo_params(user_name, repo_name)
59
+ _validate_user_repo_params(user, repo) unless user? && repo?
60
+
61
+ _validate_presence_of ref
62
+ _validate_reference ref
63
+ _normalize_params_keys params
64
+
65
+ get_request("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
66
+ end
67
+ alias :find :get
68
+
69
+
70
+ # Create a reference
71
+ #
72
+ # = Inputs
73
+ # * <tt>:ref</tt> - String of the name of the fully qualified reference (ie: refs/heads/master). If it doesn’t start with ‘refs’ and have at least two slashes, it will be rejected.
74
+ # * <tt>:sha</tt> - String of the SHA1 value to set this reference to
75
+ #
76
+ # = Examples
77
+ # github = Github.new
78
+ # github.git_data.references.create 'user-name', 'repo-name',
79
+ # "ref" => "refs/heads/master",
80
+ # "sha" => "827efc6d56897b048c772eb4087f854f46256132"
81
+ #
82
+ def create(user_name, repo_name, params={})
83
+ _update_user_repo_params(user_name, repo_name)
84
+ _validate_user_repo_params(user, repo) unless user? && repo?
85
+
86
+ _normalize_params_keys params
87
+ _filter_params_keys VALID_REF_PARAM_NAMES, params
88
+ _validate_reference params['ref']
89
+ _validate_inputs(%w[ ref sha ], params)
90
+
91
+ post_request("/repos/#{user}/#{repo}/git/refs", params)
92
+ end
93
+
94
+ # Update a reference
95
+ #
96
+ # = Inputs
97
+ # * <tt>:sha</tt> - String of the SHA1 value to set this reference to
98
+ # * <tt>:force</tt> - Boolean indicating whether to force the update or to make sure the update is a fast-forward update. The default is <tt>false</tt>, so leaving this out or setting it to false will make sure you’re not overwriting work.
99
+ #
100
+ # = Examples
101
+ # github = Github.new
102
+ # github.git_data.references.update 'user-name', 'repo-name',
103
+ # "sha" => "827efc6d56897b048c772eb4087f854f46256132",
104
+ # "force" => true
105
+ #
106
+ def update(user_name, repo_name, ref, params={})
107
+ _update_user_repo_params(user_name, repo_name)
108
+ _validate_user_repo_params(user, repo) unless user? && repo?
109
+
110
+ _validate_presence_of ref
111
+ _validate_reference ref
112
+ _normalize_params_keys(params)
113
+ _filter_params_keys(VALID_REF_PARAM_NAMES, params)
114
+ _validate_inputs(%w[ sha ], params)
115
+
116
+ patch_request("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
117
+ end
118
+
119
+ # Delete a reference
120
+ #
121
+ # = Examples
122
+ # github = Github.new
123
+ # github.git_data.references.delete 'user-name', 'repo-name',
124
+ # "ref" => "refs/heads/master",
125
+ #
126
+ def delete(user_name, repo_name, ref, params={})
127
+ _update_user_repo_params(user_name, repo_name)
128
+ _validate_user_repo_params(user, repo) unless user? && repo?
129
+ _normalize_params_keys params
130
+ _validate_presence_of ref
131
+
132
+ delete_request("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
133
+ end
134
+ alias :remove :delete
135
+
136
+ private
137
+
138
+ def _validate_reference ref
139
+ unless VALID_REF_PARAM_VALUES['ref'] =~ "refs/#{ref}"
140
+ raise ArgumentError, "Provided 'reference' is invalid"
122
141
  end
142
+ end
123
143
 
124
- end # References
125
- end # GitData
144
+ end # GitData::References
126
145
  end # Github
@@ -1,82 +1,86 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Github
4
- class GitData
5
- # This tags api only deals with tag objects - so only annotated tags, not lightweight tags.
6
- module Tags
4
+ class GitData::Tags < API
5
+ # This tags api only deals with tag objects -
6
+ # so only annotated tags, not lightweight tags.
7
7
 
8
- VALID_TAG_PARAM_NAMES = %w[
9
- tag
10
- message
11
- object
12
- type
13
- name
14
- email
15
- date
16
- sha
17
- url
18
- tagger
19
- ].freeze
8
+ VALID_TAG_PARAM_NAMES = %w[
9
+ tag
10
+ message
11
+ object
12
+ type
13
+ name
14
+ email
15
+ date
16
+ sha
17
+ url
18
+ tagger
19
+ ].freeze
20
20
 
21
- VALID_TAG_PARAM_VALUES = {
22
- 'type' => %w[ blob tree commit ]
23
- }
21
+ VALID_TAG_PARAM_VALUES = {
22
+ 'type' => %w[ blob tree commit ]
23
+ }
24
24
 
25
- # Get a tag
26
- #
27
- # = Examples
28
- # @github = Github.new
29
- # @github.git_data.tag 'user-name', 'repo-name', 'sha'
30
- #
31
- def tag(user_name, repo_name, sha, params={})
32
- _update_user_repo_params(user_name, repo_name)
33
- _validate_user_repo_params(user, repo) unless user? && repo?
34
- _validate_presence_of sha
35
- _normalize_params_keys(params)
25
+ # Creates new GitData::Tags API
26
+ def initialize(options = {})
27
+ super(options)
28
+ end
36
29
 
37
- get("/repos/#{user}/#{repo}/git/tags/#{sha}", params)
38
- end
39
- alias :get_tag :tag
30
+ # Get a tag
31
+ #
32
+ # = Examples
33
+ # github = Github.new
34
+ # github.git_data.tags.get 'user-name', 'repo-name', 'sha'
35
+ #
36
+ def get(user_name, repo_name, sha, params={})
37
+ _update_user_repo_params(user_name, repo_name)
38
+ _validate_user_repo_params(user, repo) unless user? && repo?
39
+ _validate_presence_of sha
40
+ _normalize_params_keys(params)
40
41
 
41
- # Create a tag object
42
- # Note that creating a tag object does not create the reference that
43
- # makes a tag in Git. If you want to create an annotated tag in Git,
44
- # you have to do this call to create the tag object, and then create
45
- # the <tt>refs/tags/[tag]</tt> reference. If you want to create a lightweight tag, you simply have to create the reference - this call would be unnecessary.
46
- #
47
- # = Parameters
48
- # * <tt>:tag</tt> - String of the tag
49
- # * <tt>:message</tt> - String of the tag message
50
- # * <tt>:object</tt> - String of the SHA of the git object this is tagging
51
- # * <tt>:type</tt> - String of the type of the object we're tagging. Normally this is a <tt>commit</tt> but it can also be a <tt>tree</tt> or a <tt>blob</tt>
52
- # * tagger.name:: String of the name of the author of the tag
53
- # * tagger.email:: String of the email of the author of the tag
54
- # * tagger.date:: Timestamp of when this object was tagged
55
- #
56
- # = Examples
57
- # @github = Github.new
58
- # @github.git_data.create_tag 'user-name', 'repo-name',
59
- # "tag" => "v0.0.1",
60
- # "message" => "initial version\n",
61
- # "type": "commit",
62
- # "object": "c3d0be41ecbe669545ee3e94d31ed9a4bc91ee3c",
63
- # "tagger" => {
64
- # "name" => "Scott Chacon",
65
- # "email" => "schacon@gmail.com",
66
- # "date" => "2011-06-17T14:53:3"
67
- # }
68
- #
69
- def create_tag(user_name, repo_name, params={})
70
- _update_user_repo_params(user_name, repo_name)
71
- _validate_user_repo_params(user, repo) unless user? && repo?
72
- _normalize_params_keys(params)
42
+ get_request("/repos/#{user}/#{repo}/git/tags/#{sha}", params)
43
+ end
44
+ alias :find :get
73
45
 
74
- _filter_params_keys(VALID_TAG_PARAM_NAMES, params)
75
- _validate_params_values(VALID_TAG_PARAM_VALUES, params)
46
+ # Create a tag object
47
+ # Note that creating a tag object does not create the reference that
48
+ # makes a tag in Git. If you want to create an annotated tag in Git,
49
+ # you have to do this call to create the tag object, and then create
50
+ # the <tt>refs/tags/[tag]</tt> reference. If you want to create a lightweight tag, you simply have to create the reference - this call would be unnecessary.
51
+ #
52
+ # = Parameters
53
+ # * <tt>:tag</tt> - String of the tag
54
+ # * <tt>:message</tt> - String of the tag message
55
+ # * <tt>:object</tt> - String of the SHA of the git object this is tagging
56
+ # * <tt>:type</tt> - String of the type of the object we're tagging. Normally this is a <tt>commit</tt> but it can also be a <tt>tree</tt> or a <tt>blob</tt>
57
+ # * tagger.name:: String of the name of the author of the tag
58
+ # * tagger.email:: String of the email of the author of the tag
59
+ # * tagger.date:: Timestamp of when this object was tagged
60
+ #
61
+ # = Examples
62
+ # github = Github.new
63
+ # github.git_data.tags.create 'user-name', 'repo-name',
64
+ # "tag" => "v0.0.1",
65
+ # "message" => "initial version\n",
66
+ # "type": "commit",
67
+ # "object": "c3d0be41ecbe669545ee3e94d31ed9a4bc91ee3c",
68
+ # "tagger" => {
69
+ # "name" => "Scott Chacon",
70
+ # "email" => "schacon@gmail.com",
71
+ # "date" => "2011-06-17T14:53:3"
72
+ # }
73
+ #
74
+ def create(user_name, repo_name, params={})
75
+ _update_user_repo_params(user_name, repo_name)
76
+ _validate_user_repo_params(user, repo) unless user? && repo?
77
+ _normalize_params_keys(params)
76
78
 
77
- post("/repos/#{user}/#{repo}/git/tags", params)
78
- end
79
+ _filter_params_keys(VALID_TAG_PARAM_NAMES, params)
80
+ _validate_params_values(VALID_TAG_PARAM_VALUES, params)
79
81
 
80
- end # Tags
81
- end # GitData
82
+ post_request("/repos/#{user}/#{repo}/git/tags", params)
83
+ end
84
+
85
+ end # GitData::Tags
82
86
  end # Github
@@ -1,99 +1,102 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Github
4
- class GitData
5
- module Trees
4
+ class GitData::Trees < API
6
5
 
7
- VALID_TREE_PARAM_NAMES = %w[
8
- base_tree
9
- tree
10
- path
11
- mode
12
- type
13
- sha
14
- content
15
- url
16
- ].freeze
6
+ VALID_TREE_PARAM_NAMES = %w[
7
+ base_tree
8
+ tree
9
+ path
10
+ mode
11
+ type
12
+ sha
13
+ content
14
+ url
15
+ ].freeze
17
16
 
18
- VALID_TREE_PARAM_VALUES = {
19
- 'mode' => %w[ 100644 100755 040000 160000 120000 ],
20
- 'type' => %w[ blob tree commit ]
21
- }
17
+ VALID_TREE_PARAM_VALUES = {
18
+ 'mode' => %w[ 100644 100755 040000 160000 120000 ],
19
+ 'type' => %w[ blob tree commit ]
20
+ }
22
21
 
23
- # Get a tree
24
- #
25
- # = Examples
26
- # @github = Github.new
27
- # @github.git_data.tree 'user-name', 'repo-name', 'sha'
28
- # @github.git_data.tree 'user-name', 'repo-name', 'sha' do |file|
29
- # file.path
30
- # end
31
- #
32
- # Get a tree recursively
33
- #
34
- # = Examples
35
- # @github = Github.new
36
- # @github.git_data.tree 'user-name', 'repo-name', 'sha', 'recursive' => true
37
- #
38
- def tree(user_name, repo_name, sha, params={})
39
- _update_user_repo_params(user_name, repo_name)
40
- _validate_user_repo_params(user, repo) unless user? && repo?
41
- _validate_presence_of sha
42
- _normalize_params_keys(params)
22
+ # Creates new GitData::Trees API
23
+ def initialize(options = {})
24
+ super(options)
25
+ end
43
26
 
44
- response = if params['recursive']
45
- params['recursive'] = 1
46
- get("/repos/#{user}/#{repo}/git/trees/#{sha}", params)
47
- else
48
- get("/repos/#{user}/#{repo}/git/trees/#{sha.to_s}", params)
49
- end
50
- return response unless block_given?
51
- response.tree.each { |el| yield el }
27
+ # Get a tree
28
+ #
29
+ # = Examples
30
+ # github = Github.new
31
+ # github.git_data.trees.get 'user-name', 'repo-name', 'sha'
32
+ # github.git_data.trees.get 'user-name', 'repo-name', 'sha' do |file|
33
+ # file.path
34
+ # end
35
+ #
36
+ # Get a tree recursively
37
+ #
38
+ # = Examples
39
+ # github = Github.new
40
+ # github.git_data.trees.get 'user-name', 'repo-name', 'sha', 'recursive' => true
41
+ #
42
+ def get(user_name, repo_name, sha, params={})
43
+ _update_user_repo_params(user_name, repo_name)
44
+ _validate_user_repo_params(user, repo) unless user? && repo?
45
+ _validate_presence_of sha
46
+ _normalize_params_keys(params)
47
+
48
+ response = if params['recursive']
49
+ params['recursive'] = 1
50
+ get_request("/repos/#{user}/#{repo}/git/trees/#{sha}", params)
51
+ else
52
+ get_request("/repos/#{user}/#{repo}/git/trees/#{sha.to_s}", params)
52
53
  end
53
- alias :get_tree :tree
54
+ return response unless block_given?
55
+ response.tree.each { |el| yield el }
56
+ end
57
+ alias :find :get
54
58
 
55
- # Create a tree
56
- #
57
- # The tree creation API will take nested entries as well.
58
- # If both a tree and a nested path modifying that tree are specified,
59
- # it will overwrite the contents of that tree with the new path contents
60
- # and write a new tree out.
61
- #
62
- # = Parameters
63
- # * <tt>:base_tree</tt> - optional string of the SHA1 of the tree you want to update with new data
64
- # * <tt>:tree</tt> - array of hash objects(of <tt>:path</tt>, <tt>:mode</tt>, <tt>:type</tt> and <tt>sha</tt>)
65
- # * tree.path:: String of the file referenced in the tree
66
- # * tree.mode:: String of the file mode - one of <tt>100644</tt> for file(blob), <tt>100755</tt> for executable (blob), <tt>040000</tt> for subdirectory (tree), <tt>160000</tt> for submodule (commit) or <tt>120000</tt> for a blob that specifies the path of a symlink
67
- # * tree.type:: String of <tt>blob</tt>, <tt>tree</tt>, <tt>commit</tt>
68
- # * tree.sha:: String of SHA1 checksum ID of the object in the tree
69
- # * tree.content:: String of content you want this file to have - GitHub will write this blob out and use the SHA for this entry. Use either this or <tt>tree.sha</tt>
70
- #
71
- # = Examples
72
- # @github = Github.new
73
- # @github.git_data.create_tree 'user-name', 'repo-name',
74
- # "tree" => [
75
- # {
76
- # "path" => "file.rb",
77
- # "mode" => "100644",
78
- # "type" => "blob",
79
- # "sha" => "44b4fc6d56897b048c772eb4087f854f46256132"
80
- # },
81
- # ...
82
- # ]
83
- #
84
- def create_tree(user_name, repo_name, params={})
85
- _update_user_repo_params(user_name, repo_name)
86
- _validate_user_repo_params(user, repo) unless user? && repo?
87
- _normalize_params_keys(params)
59
+ # Create a tree
60
+ #
61
+ # The tree creation API will take nested entries as well.
62
+ # If both a tree and a nested path modifying that tree are specified,
63
+ # it will overwrite the contents of that tree with the new path contents
64
+ # and write a new tree out.
65
+ #
66
+ # = Parameters
67
+ # * <tt>:base_tree</tt> - optional string of the SHA1 of the tree you want to update with new data
68
+ # * <tt>:tree</tt> - array of hash objects(of <tt>:path</tt>, <tt>:mode</tt>, <tt>:type</tt> and <tt>sha</tt>)
69
+ # * tree.path:: String of the file referenced in the tree
70
+ # * tree.mode:: String of the file mode - one of <tt>100644</tt> for file(blob), <tt>100755</tt> for executable (blob), <tt>040000</tt> for subdirectory (tree), <tt>160000</tt> for submodule (commit) or <tt>120000</tt> for a blob that specifies the path of a symlink
71
+ # * tree.type:: String of <tt>blob</tt>, <tt>tree</tt>, <tt>commit</tt>
72
+ # * tree.sha:: String of SHA1 checksum ID of the object in the tree
73
+ # * tree.content:: String of content you want this file to have - GitHub will write this blob out and use the SHA for this entry. Use either this or <tt>tree.sha</tt>
74
+ #
75
+ # = Examples
76
+ # github = Github.new
77
+ # github.git_data.trees.create 'user-name', 'repo-name',
78
+ # "tree" => [
79
+ # {
80
+ # "path" => "file.rb",
81
+ # "mode" => "100644",
82
+ # "type" => "blob",
83
+ # "sha" => "44b4fc6d56897b048c772eb4087f854f46256132"
84
+ # },
85
+ # ...
86
+ # ]
87
+ #
88
+ def create(user_name, repo_name, params={})
89
+ _update_user_repo_params(user_name, repo_name)
90
+ _validate_user_repo_params(user, repo) unless user? && repo?
91
+ _normalize_params_keys(params)
88
92
 
89
- _validate_inputs(%w[ tree ], params)
93
+ _validate_inputs(%w[ tree ], params)
90
94
 
91
- _filter_params_keys(VALID_TREE_PARAM_NAMES, params['tree'])
92
- _validate_params_values(VALID_TREE_PARAM_VALUES, params['tree'])
95
+ _filter_params_keys(VALID_TREE_PARAM_NAMES, params['tree'])
96
+ _validate_params_values(VALID_TREE_PARAM_VALUES, params['tree'])
93
97
 
94
- post("/repos/#{user}/#{repo}/git/trees", params)
95
- end
98
+ post_request("/repos/#{user}/#{repo}/git/trees", params)
99
+ end
96
100
 
97
- end # Trees
98
- end # GitData
101
+ end # GitData::Trees
99
102
  end # Github