github_api 0.4.11 → 0.5.0.rc1

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 (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
@@ -8,9 +8,6 @@ module Github
8
8
  :Members => 'members',
9
9
  :Teams => 'teams'
10
10
 
11
- include Github::Orgs::Members
12
- include Github::Orgs::Teams
13
-
14
11
  VALID_ORG_PARAM_NAMES = %w[
15
12
  billing_email
16
13
  company
@@ -24,44 +21,52 @@ module Github
24
21
  super(options)
25
22
  end
26
23
 
24
+ # Access to Orgs::Members API
25
+ def members
26
+ @members ||= ApiFactory.new 'Orgs::Members'
27
+ end
28
+
29
+ # Access to Orgs::Teams API
30
+ def teams
31
+ @teams ||= ApiFactory.new 'Orgs::Teams'
32
+ end
33
+
27
34
  # List all public organizations for a user.
28
35
  #
29
36
  # = Examples
30
- # @github = Github.new :user => 'user-name'
31
- # @github.orgs.orgs
37
+ # github = Github.new :user => 'user-name'
38
+ # github.orgs.list
32
39
  #
33
40
  # List public and private organizations for the authenticated user.
34
41
  #
35
- # @github = Github.new :oauth_token => '..'
36
- # @github.orgs.orgs 'github'
42
+ # github = Github.new :oauth_token => '..'
43
+ # github.orgs.list 'github'
37
44
  #
38
- def orgs(user_name=nil, params={})
45
+ def list(user_name=nil, params={})
39
46
  _update_user_repo_params(user_name)
40
47
  _normalize_params_keys(params)
41
48
 
42
49
  response = if user?
43
- get("/users/#{user}/orgs", params)
50
+ get_request("/users/#{user}/orgs", params)
44
51
  else
45
- get("/user/orgs", params)
52
+ get_request("/user/orgs", params)
46
53
  end
47
54
  return response unless block_given?
48
55
  response.each { |el| yield el }
49
56
  end
50
- alias :list_orgs :orgs
51
- alias :list_organizations :orgs
57
+ alias :all :list
52
58
 
53
59
  # Get properties for a single organization
54
60
  #
55
61
  # = Examples
56
- # @github = Github.new
57
- # @github.orgs.org 'github'
62
+ # github = Github.new
63
+ # github.orgs.get 'github'
58
64
  #
59
- def org(org_name, params={})
65
+ def get(org_name, params={})
60
66
  _validate_presence_of org_name
61
- get("/orgs/#{org_name}", params)
67
+ get_request("/orgs/#{org_name}", params)
62
68
  end
63
- alias :get_org :org
64
- alias :organisation :org
69
+ alias :find :get
65
70
 
66
71
  # Edit organization
67
72
  #
@@ -73,8 +78,8 @@ module Github
73
78
  # <tt>:name</tt> - Optional string
74
79
  #
75
80
  # = Examples
76
- # @github = Github.new :oauth_token => '...'
77
- # @github.orgs.edit_org 'github',
81
+ # github = Github.new :oauth_token => '...'
82
+ # github.orgs.edit 'github',
78
83
  # "billing_email" => "support@github.com",
79
84
  # "blog" => "https://github.com/blog",
80
85
  # "company" => "GitHub",
@@ -82,14 +87,13 @@ module Github
82
87
  # "location" => "San Francisco",
83
88
  # "name" => "github"
84
89
  #
85
- def edit_org(org_name, params={})
90
+ def edit(org_name, params={})
86
91
  _validate_presence_of org_name
87
92
  _normalize_params_keys(params)
88
93
  _filter_params_keys(VALID_ORG_PARAM_NAMES, params)
89
94
 
90
- patch("/orgs/#{org_name}", params)
95
+ patch_request("/orgs/#{org_name}", params)
91
96
  end
92
- alias :edit_organization :edit_org
93
97
 
94
98
  end # Orgs
95
99
  end # Github
@@ -1,120 +1,117 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Github
4
- class Orgs
5
- module Members
4
+ class Orgs::Members < API
6
5
 
7
- # List members
8
- #
9
- # List all users who are members of an organization. A member is a user
10
- # that belongs to at least 1 team in the organization.
11
- # If the authenticated user is also a member of this organization then
12
- # both concealed and public members will be returned.
13
- # Otherwise only public members are returned.
14
- #
15
- # = Examples
16
- # @github = Github.new
17
- # @github.orgs.members 'org-name'
18
- # @github.orgs.members 'org-name' { |memb| ... }
19
- #
20
- def members(org_name, params={})
21
- _validate_presence_of org_name
22
- _normalize_params_keys(params)
23
- response = get("/orgs/#{org_name}/members", params)
24
- return response unless block_given?
25
- response.each { |el| yield el }
26
- end
27
- alias :list_members :members
6
+ # List members
7
+ #
8
+ # List all users who are members of an organization. A member is a user
9
+ # that belongs to at least 1 team in the organization.
10
+ # If the authenticated user is also a member of this organization then
11
+ # both concealed and public members will be returned.
12
+ # Otherwise only public members are returned.
13
+ #
14
+ # = Examples
15
+ # github = Github.new
16
+ # github.orgs.members.list 'org-name'
17
+ # github.orgs.members.list 'org-name' { |memb| ... }
18
+ #
19
+ def list(org_name, params={})
20
+ _validate_presence_of org_name
21
+ _normalize_params_keys(params)
22
+ response = get_request("/orgs/#{org_name}/members", params)
23
+ return response unless block_given?
24
+ response.each { |el| yield el }
25
+ end
26
+ alias :all :list
28
27
 
29
- # Check if user is a member of an organization
30
- #
31
- # = Examples
32
- # @github = Github.new
33
- # @github.orgs.member? 'org-name', 'member-name'
34
- #
35
- def member?(org_name, member_name, params={})
36
- _validate_presence_of org_name, member_name
37
- _normalize_params_keys(params)
38
- get("/orgs/#{org_name}/members/#{member_name}", params)
39
- true
40
- rescue Github::Error::NotFound
41
- false
42
- end
43
- alias :is_member? :member?
28
+ # Check if user is a member of an organization
29
+ #
30
+ # = Examples
31
+ # github = Github.new
32
+ # github.orgs.members.member? 'org-name', 'member-name'
33
+ #
34
+ def member?(org_name, member_name, params={})
35
+ _validate_presence_of org_name, member_name
36
+ _normalize_params_keys(params)
37
+ get_request("/orgs/#{org_name}/members/#{member_name}", params)
38
+ true
39
+ rescue Github::Error::NotFound
40
+ false
41
+ end
44
42
 
45
- # Remove a member
46
- # Removing a user from this list will remove them from all teams and
47
- # they will no longer have any access to the organization’s repositories.
48
- #
49
- # = Examples
50
- # @github = Github.new
51
- # @github.orgs.delete_member 'org-name', 'member-name'
52
- #
53
- def delete_member(org_name, member_name, params={})
54
- _validate_presence_of org_name, member_name
55
- _normalize_params_keys(params)
56
- delete("/orgs/#{org_name}/members/#{member_name}", params)
57
- end
58
- alias :remove_member :delete_member
43
+ # Remove a member
44
+ # Removing a user from this list will remove them from all teams and
45
+ # they will no longer have any access to the organization’s repositories.
46
+ #
47
+ # = Examples
48
+ # github = Github.new
49
+ # github.orgs.members.remove 'org-name', 'member-name'
50
+ #
51
+ def delete(org_name, member_name, params={})
52
+ _validate_presence_of org_name, member_name
53
+ _normalize_params_keys(params)
54
+ delete_request("/orgs/#{org_name}/members/#{member_name}", params)
55
+ end
56
+ alias :remove :delete
59
57
 
60
- # List public members
61
- # Members of an organization can choose to have their membership publicized or not.
62
- # = Examples
63
- # @github = Github.new
64
- # @github.orgs.public_members 'org-name'
65
- # @github.orgs.public_members 'org-name' { |memb| ... }
66
- #
67
- def public_members(org_name, params={})
68
- _validate_presence_of org_name
69
- _normalize_params_keys(params)
70
- response = get("/orgs/#{org_name}/public_members", params)
71
- return response unless block_given?
72
- response.each { |el| yield el }
73
- end
74
- alias :list_public_members :public_members
58
+ # List public members
59
+ # Members of an organization can choose to have their membership publicized or not.
60
+ # = Examples
61
+ # github = Github.new
62
+ # github.orgs.members.list_public 'org-name'
63
+ # github.orgs.members.list_public 'org-name' { |memb| ... }
64
+ #
65
+ def list_public(org_name, params={})
66
+ _validate_presence_of org_name
67
+ _normalize_params_keys(params)
68
+ response = get_request("/orgs/#{org_name}/public_members", params)
69
+ return response unless block_given?
70
+ response.each { |el| yield el }
71
+ end
72
+ alias :public_members :list_public
75
73
 
76
- # Get if a user is a public member of an organization
77
- #
78
- # = Examples
79
- # @github = Github.new
80
- # @github.orgs.public_member? 'org-name', 'member-name'
81
- #
82
- def public_member?(org_name, member_name, params={})
83
- _validate_presence_of org_name, member_name
84
- _normalize_params_keys(params)
85
- get("/orgs/#{org_name}/public_members/#{member_name}", params)
86
- true
87
- rescue Github::Error::NotFound
88
- false
89
- end
74
+ # Get if a user is a public member of an organization
75
+ #
76
+ # = Examples
77
+ # github = Github.new
78
+ # github.orgs.members.public_member? 'org-name', 'member-name'
79
+ #
80
+ def public_member?(org_name, member_name, params={})
81
+ _validate_presence_of org_name, member_name
82
+ _normalize_params_keys(params)
83
+ get_request("/orgs/#{org_name}/public_members/#{member_name}", params)
84
+ true
85
+ rescue Github::Error::NotFound
86
+ false
87
+ end
90
88
 
91
- # Publicize a user’s membership
92
- #
93
- # = Examples
94
- # @github = Github.new :oauth_token => '...'
95
- # @github.orgs.publicize 'org-name', 'member-name'
96
- #
97
- def publicize(org_name, member_name, params={})
98
- _validate_presence_of org_name, member_name
99
- _normalize_params_keys(params)
100
- put("/orgs/#{org_name}/public_members/#{member_name}", params)
101
- end
102
- alias :make_public :publicize
103
- alias :publicize_membership :publicize
89
+ # Publicize a user’s membership
90
+ #
91
+ # = Examples
92
+ # github = Github.new :oauth_token => '...'
93
+ # github.orgs.members.publicize 'org-name', 'member-name'
94
+ #
95
+ def publicize(org_name, member_name, params={})
96
+ _validate_presence_of org_name, member_name
97
+ _normalize_params_keys(params)
98
+ put_request("/orgs/#{org_name}/public_members/#{member_name}", params)
99
+ end
100
+ alias :make_public :publicize
101
+ alias :publicize_membership :publicize
104
102
 
105
- # Conceal a user’s membership
106
- #
107
- # = Examples
108
- # @github = Github.new :oauth_token => '...'
109
- # @github.orgs.conceal 'org-name', 'member-name'
110
- #
111
- def conceal(org_name, member_name, params={})
112
- _validate_presence_of org_name, member_name
113
- _normalize_params_keys(params)
114
- delete("/orgs/#{org_name}/public_members/#{member_name}", params)
115
- end
116
- alias :conceal_membership :conceal
103
+ # Conceal a user’s membership
104
+ #
105
+ # = Examples
106
+ # github = Github.new :oauth_token => '...'
107
+ # github.orgs.members.conceal 'org-name', 'member-name'
108
+ #
109
+ def conceal(org_name, member_name, params={})
110
+ _validate_presence_of org_name, member_name
111
+ _normalize_params_keys(params)
112
+ delete_request("/orgs/#{org_name}/public_members/#{member_name}", params)
113
+ end
114
+ alias :conceal_membership :conceal
117
115
 
118
- end # Members
119
- end # Orgs
116
+ end # Orgs::Members
120
117
  end # Github
@@ -1,244 +1,243 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Github
4
- class Orgs
4
+ class Orgs::Teams < API
5
5
  # All actions against teams require at a minimum an authenticated user
6
6
  # who is a member of the owner’s team in the :org being managed.
7
7
  # Api calls that require explicit permissions are noted.
8
- module Teams
9
-
10
- VALID_TEAM_PARAM_NAMES = %w[ name repo_names permission ].freeze
11
- VALID_TEAM_PARAM_VALUES = {
12
- 'permission' => %w[ pull push admin ].freeze
13
- }
14
-
15
- # List teams
16
- #
17
- # = Examples
18
- # @github = Github.new :oauth_token => '...'
19
- # @github.orgs.teams 'org-name'
20
- #
21
- def teams(org_name, params={})
22
- _validate_presence_of org_name
23
- _normalize_params_keys(params)
24
-
25
- response = get("/orgs/#{org_name}/teams", params)
26
- return response unless block_given?
27
- response.each { |el| yield el }
28
- end
29
- alias :list_teams :teams
30
-
31
- # Get a team
32
- #
33
- # = Examples
34
- # @github = Github.new :oauth_token => '...'
35
- # @github.orgs.team 'team-name'
36
- #
37
- def team(team_name, params={})
38
- _validate_presence_of team_name
39
- _normalize_params_keys(params)
40
-
41
- get("/teams/#{team_name}", params)
42
- end
43
- alias :get_team :team
44
-
45
- # Create a team
46
- #
47
- # In order to create a team, the authenticated user must be an owner of<tt>:org</tt>.
48
- # = Inputs
49
- # <tt>:name</tt> - Required string
50
- # <tt>:repo_names</tt> - Optional array of strings
51
- # <tt>:permission</tt> - Optional string
52
- # * <tt>pull</tt> - team members can pull, but not push or administor this repositories. Default
53
- # * <tt>push</tt> - team members can pull and push, but not administor this repositores.
54
- # * <tt>admin</tt> - team members can pull, push and administor these repositories.
55
- #
56
- # = Examples
57
- # @github = Github.new :oauth_token => '...'
58
- # @github.orgs.create_team 'org-name',
59
- # "name" => "new team",
60
- # "permission" => "push",
61
- # "repo_names" => [
62
- # "github/dotfiles"
63
- # ]
64
- #
65
- def create_team(org_name, params={})
66
- _validate_presence_of org_name
67
- _normalize_params_keys(params)
68
- _filter_params_keys(VALID_TEAM_PARAM_NAMES, params)
69
- _validate_params_values(VALID_TEAM_PARAM_VALUES, params)
70
- _validate_inputs(%w[ name ], params)
71
-
72
- post("/orgs/#{org_name}/teams", params)
73
- end
74
-
75
- # Edit a team
76
- # In order to edit a team, the authenticated user must be an owner of the org that the team is associated with.
77
- #
78
- # = Inputs
79
- # <tt>:name</tt> - Required string
80
- # <tt>:permission</tt> - Optional string
81
- # * <tt>pull</tt> - team members can pull, but not push or administor this repositories. Default
82
- # * <tt>push</tt> - team members can pull and push, but not administor this repositores.
83
- # * <tt>admin</tt> - team members can pull, push and administor these repositories.
84
- #
85
- # = Examples
86
- # @github = Github.new :oauth_token => '...'
87
- # @github.orgs.edit_team 'team-name',
88
- # "name" => "new team name",
89
- # "permission" => "push"
90
- #
91
- def edit_team(team_name, params={})
92
- _validate_presence_of team_name
93
- _normalize_params_keys(params)
94
-
95
- _filter_params_keys(VALID_TEAM_PARAM_NAMES, params)
96
- _validate_params_values(VALID_TEAM_PARAM_VALUES, params)
97
- _validate_inputs(%w[ name ], params)
98
-
99
- patch("/teams/#{team_name}", params)
100
- end
101
-
102
- # Delete a team
103
- # In order to delete a team, the authenticated user must be an owner of the org that the team is associated with
104
- #
105
- # = Examples
106
- # @github = Github.new :oauth_token => '...'
107
- # @github.orgs.delete_team 'team-name'
108
- #
109
- def delete_team(team_name, params={})
110
- _validate_presence_of team_name
111
- _normalize_params_keys(params)
112
- delete("/teams/#{team_name}", params)
113
- end
114
-
115
- # List team members
116
- # In order to list members in a team, the authenticated user must be a member of the team.
117
- #
118
- # = Examples
119
- # @github = Github.new :oauth_token => '...'
120
- # @github.orgs.team_members 'team-name'
121
- # @github.orgs.team_members 'team-name' { |member| ... }
122
- #
123
- def team_members(team_name, params={})
124
- _validate_presence_of team_name
125
- _normalize_params_keys(params)
126
-
127
- response = get("/teams/#{team_name}/members", params)
128
- return response unless block_given?
129
- response.each { |el| yield el }
130
- end
131
- alias :list_team_members :team_members
132
-
133
- # Check if a user is a member of a team
134
- #
135
- # = Examples
136
- # @github = Github.new :oauth_token => '...'
137
- # @github.orgs.team_member? 'team-name', 'user-name'
138
- #
139
- def team_member?(team_name, member_name, params={})
140
- _validate_presence_of team_name, member_name
141
- _normalize_params_keys(params)
142
- get("/teams/#{team_name}/members/#{member_name}", params)
143
- true
144
- rescue Github::Error::NotFound
145
- false
146
- end
147
-
148
- # Add a team member
149
- # In order to add a user to a team, the authenticated user must have ‘admin’ permissions to the team or be an owner of the org that the team is associated with.
150
- #
151
- # = Examples
152
- # @github = Github.new :oauth_token => '...'
153
- # @github.orgs.add_team_member 'team-name', 'user-name'
154
- #
155
- def add_team_member(team_name, member_name, params={})
156
- _validate_presence_of team_name, member_name
157
- _normalize_params_keys(params)
158
- put("/teams/#{team_name}/members/#{member_name}", params)
159
- end
160
- alias :add_member :add_team_member
161
-
162
- # Remove a team member
163
- # In order to remove a user from a team, the authenticated user must
164
- # have ‘admin’ permissions to the team or be an owner of the org that
165
- # the team is associated with.
166
- # note: This does not delete the user, it just remove them from the team.
167
- #
168
- # = Examples
169
- # @github = Github.new :oauth_token => '...'
170
- # @github.orgs.remove_team_member 'team-name', 'member-name'
171
- #
172
- def remove_team_member(team_name, member_name, params={})
173
- _validate_presence_of team_name, member_name
174
- _normalize_params_keys(params)
175
- delete("/teams/#{team_name}/members/#{member_name}", params)
176
- end
177
- alias :remove_member :remove_team_member
178
-
179
- # List team repositories
180
- #
181
- # = Examples
182
- # @github = Github.new :oauth_token => '...'
183
- # @github.orgs.team_repos 'team-name'
184
- #
185
- def team_repos(team_name, params={})
186
- _validate_presence_of team_name
187
- _normalize_params_keys(params)
188
-
189
- response = get("/teams/#{team_name}/repos", params)
190
- return response unless block_given?
191
- response.each { |el| yield el }
192
- end
193
- alias :team_repositories :team_repos
194
-
195
- # Check if a repository belongs to a team
196
- #
197
- # = Examples
198
- # @github = Github.new :oauth_token => '...'
199
- # @github.orgs.team_repo? 'team-name', 'user-name', 'repo-name'
200
- #
201
- def team_repo?(team_name, user_name, repo_name, params={})
202
- _validate_presence_of team_name, user_name, repo_name
203
- _normalize_params_keys(params)
204
- get("/teams/#{team_name}/repos/#{user_name}/#{repo_name}", params)
205
- true
206
- rescue Github::Error::NotFound
207
- false
208
- end
209
- alias :team_repository? :team_repo?
210
-
211
- # Add a team repository
212
- # In order to add a repo to a team, the authenticated user must be
213
- # an owner of the org that the team is associated with.
214
- #
215
- # = Examples
216
- # @github = Github.new :oauth_token => '...'
217
- # @github.orgs.add_team_repo 'team-name', 'user-name', 'repo-name'
218
- #
219
- def add_team_repo(team_name, user_name, repo_name, params={})
220
- _validate_presence_of team_name, user_name, repo_name
221
- _normalize_params_keys(params)
222
- put("/teams/#{team_name}/repos/#{user_name}/#{repo_name}", params)
223
- end
224
- alias :add_team_repository :add_team_repo
225
-
226
- # Remove a team repository
227
- # In order to add a repo to a team, the authenticated user must be
228
- # an owner of the org that the team is associated with.
229
- # note: This does not delete the repo, it just removes it from the team.
230
- #
231
- # = Examples
232
- # @github = Github.new :oauth_token => '...'
233
- # @github.orgs.remove_team_repo 'team-name', 'user-name', 'repo-name'
234
- #
235
- def remove_team_repo(team_name, user_name, repo_name, params={})
236
- _validate_presence_of team_name, user_name, repo_name
237
- _normalize_params_keys(params)
238
- delete("/teams/#{team_name}/repos/#{user_name}/#{repo_name}", params)
239
- end
240
- alias :remove_team_repository :remove_team_repo
241
-
242
- end # Teams
243
- end # Orgs
8
+
9
+ VALID_TEAM_PARAM_NAMES = %w[ name repo_names permission ].freeze
10
+ VALID_TEAM_PARAM_VALUES = {
11
+ 'permission' => %w[ pull push admin ].freeze
12
+ }
13
+
14
+ # List teams
15
+ #
16
+ # = Examples
17
+ # github = Github.new :oauth_token => '...'
18
+ # github.orgs.teams.list 'org-name'
19
+ #
20
+ def list(org_name, params={})
21
+ _validate_presence_of org_name
22
+ _normalize_params_keys(params)
23
+
24
+ response = get_request("/orgs/#{org_name}/teams", params)
25
+ return response unless block_given?
26
+ response.each { |el| yield el }
27
+ end
28
+ alias :all :list
29
+
30
+ # Get a team
31
+ #
32
+ # = Examples
33
+ # github = Github.new :oauth_token => '...'
34
+ # github.orgs.teams.get 'team-name'
35
+ #
36
+ def get(team_name, params={})
37
+ _validate_presence_of team_name
38
+ _normalize_params_keys(params)
39
+
40
+ get_request("/teams/#{team_name}", params)
41
+ end
42
+ alias :find :get
43
+
44
+ # Create a team
45
+ #
46
+ # In order to create a team, the authenticated user must be an owner of<tt>:org</tt>.
47
+ # = Inputs
48
+ # <tt>:name</tt> - Required string
49
+ # <tt>:repo_names</tt> - Optional array of strings
50
+ # <tt>:permission</tt> - Optional string
51
+ # * <tt>pull</tt> - team members can pull, but not push or administor this repositories. Default
52
+ # * <tt>push</tt> - team members can pull and push, but not administor this repositores.
53
+ # * <tt>admin</tt> - team members can pull, push and administor these repositories.
54
+ #
55
+ # = Examples
56
+ # github = Github.new :oauth_token => '...'
57
+ # github.orgs.teams.create 'org-name',
58
+ # "name" => "new team",
59
+ # "permission" => "push",
60
+ # "repo_names" => [
61
+ # "github/dotfiles"
62
+ # ]
63
+ #
64
+ def create(org_name, params={})
65
+ _validate_presence_of org_name
66
+ _normalize_params_keys(params)
67
+ _filter_params_keys(VALID_TEAM_PARAM_NAMES, params)
68
+ _validate_params_values(VALID_TEAM_PARAM_VALUES, params)
69
+ _validate_inputs(%w[ name ], params)
70
+
71
+ post_request("/orgs/#{org_name}/teams", params)
72
+ end
73
+
74
+ # Edit a team
75
+ # In order to edit a team, the authenticated user must be an owner of the org that the team is associated with.
76
+ #
77
+ # = Inputs
78
+ # <tt>:name</tt> - Required string
79
+ # <tt>:permission</tt> - Optional string
80
+ # * <tt>pull</tt> - team members can pull, but not push or administor this repositories. Default
81
+ # * <tt>push</tt> - team members can pull and push, but not administor this repositores.
82
+ # * <tt>admin</tt> - team members can pull, push and administor these repositories.
83
+ #
84
+ # = Examples
85
+ # github = Github.new :oauth_token => '...'
86
+ # github.orgs.teams.edit 'team-name',
87
+ # "name" => "new team name",
88
+ # "permission" => "push"
89
+ #
90
+ def edit(team_name, params={})
91
+ _validate_presence_of team_name
92
+ _normalize_params_keys(params)
93
+
94
+ _filter_params_keys(VALID_TEAM_PARAM_NAMES, params)
95
+ _validate_params_values(VALID_TEAM_PARAM_VALUES, params)
96
+ _validate_inputs(%w[ name ], params)
97
+
98
+ patch_request("/teams/#{team_name}", params)
99
+ end
100
+
101
+ # Delete a team
102
+ # In order to delete a team, the authenticated user must be an owner of the org that the team is associated with
103
+ #
104
+ # = Examples
105
+ # github = Github.new :oauth_token => '...'
106
+ # github.orgs.teams.delete 'team-name'
107
+ #
108
+ def delete(team_name, params={})
109
+ _validate_presence_of team_name
110
+ _normalize_params_keys(params)
111
+ delete_request("/teams/#{team_name}", params)
112
+ end
113
+ alias :remove :delete
114
+
115
+ # List team members
116
+ # In order to list members in a team, the authenticated user must be a member of the team.
117
+ #
118
+ # = Examples
119
+ # github = Github.new :oauth_token => '...'
120
+ # github.orgs.teams.list_members 'team-name'
121
+ # github.orgs.teams.list_members 'team-name' { |member| ... }
122
+ #
123
+ def list_members(team_name, params={})
124
+ _validate_presence_of team_name
125
+ _normalize_params_keys(params)
126
+
127
+ response = get_request("/teams/#{team_name}/members", params)
128
+ return response unless block_given?
129
+ response.each { |el| yield el }
130
+ end
131
+ alias :all_members :list_members
132
+
133
+ # Check if a user is a member of a team
134
+ #
135
+ # = Examples
136
+ # github = Github.new :oauth_token => '...'
137
+ # github.orgs.teams.team_member? 'team-name', 'user-name'
138
+ #
139
+ def team_member?(team_name, member_name, params={})
140
+ _validate_presence_of team_name, member_name
141
+ _normalize_params_keys(params)
142
+ get_request("/teams/#{team_name}/members/#{member_name}", params)
143
+ true
144
+ rescue Github::Error::NotFound
145
+ false
146
+ end
147
+
148
+ # Add a team member
149
+ # In order to add a user to a team, the authenticated user must have ‘admin’ permissions to the team or be an owner of the org that the team is associated with.
150
+ #
151
+ # = Examples
152
+ # github = Github.new :oauth_token => '...'
153
+ # github.orgs.teams.add_member 'team-name', 'user-name'
154
+ #
155
+ def add_member(team_name, member_name, params={})
156
+ _validate_presence_of team_name, member_name
157
+ _normalize_params_keys(params)
158
+ put_request("/teams/#{team_name}/members/#{member_name}", params)
159
+ end
160
+ alias :add_team_member :add_member
161
+
162
+ # Remove a team member
163
+ # In order to remove a user from a team, the authenticated user must
164
+ # have ‘admin’ permissions to the team or be an owner of the org that
165
+ # the team is associated with.
166
+ # note: This does not delete the user, it just remove them from the team.
167
+ #
168
+ # = Examples
169
+ # github = Github.new :oauth_token => '...'
170
+ # github.orgs.teams.remove_member 'team-name', 'member-name'
171
+ #
172
+ def remove_member(team_name, member_name, params={})
173
+ _validate_presence_of team_name, member_name
174
+ _normalize_params_keys(params)
175
+ delete_request("/teams/#{team_name}/members/#{member_name}", params)
176
+ end
177
+ alias :remove_team_member :remove_member
178
+
179
+ # List team repositories
180
+ #
181
+ # = Examples
182
+ # github = Github.new :oauth_token => '...'
183
+ # github.orgs.teams.list_repos 'team-name'
184
+ #
185
+ def list_repos(team_name, params={})
186
+ _validate_presence_of team_name
187
+ _normalize_params_keys(params)
188
+
189
+ response = get_request("/teams/#{team_name}/repos", params)
190
+ return response unless block_given?
191
+ response.each { |el| yield el }
192
+ end
193
+ alias :repos :list_repos
194
+
195
+ # Check if a repository belongs to a team
196
+ #
197
+ # = Examples
198
+ # github = Github.new :oauth_token => '...'
199
+ # github.orgs.teams.team_repo? 'team-name', 'user-name', 'repo-name'
200
+ #
201
+ def team_repo?(team_name, user_name, repo_name, params={})
202
+ _validate_presence_of team_name, user_name, repo_name
203
+ _normalize_params_keys(params)
204
+ get_request("/teams/#{team_name}/repos/#{user_name}/#{repo_name}", params)
205
+ true
206
+ rescue Github::Error::NotFound
207
+ false
208
+ end
209
+ alias :team_repository? :team_repo?
210
+
211
+ # Add a team repository
212
+ # In order to add a repo to a team, the authenticated user must be
213
+ # an owner of the org that the team is associated with.
214
+ #
215
+ # = Examples
216
+ # github = Github.new :oauth_token => '...'
217
+ # github.orgs.teams.add_repo 'team-name', 'user-name', 'repo-name'
218
+ #
219
+ def add_repo(team_name, user_name, repo_name, params={})
220
+ _validate_presence_of team_name, user_name, repo_name
221
+ _normalize_params_keys(params)
222
+ put_request("/teams/#{team_name}/repos/#{user_name}/#{repo_name}", params)
223
+ end
224
+ alias :add_repository :add_repo
225
+
226
+ # Remove a team repository
227
+ # In order to add a repo to a team, the authenticated user must be
228
+ # an owner of the org that the team is associated with.
229
+ # note: This does not delete the repo, it just removes it from the team.
230
+ #
231
+ # = Examples
232
+ # github = Github.new :oauth_token => '...'
233
+ # github.orgs.teams.remove_repo 'team-name', 'user-name', 'repo-name'
234
+ #
235
+ def remove_repo(team_name, user_name, repo_name, params={})
236
+ _validate_presence_of team_name, user_name, repo_name
237
+ _normalize_params_keys(params)
238
+ delete_request("/teams/#{team_name}/repos/#{user_name}/#{repo_name}", params)
239
+ end
240
+ alias :remove_repository :remove_repo
241
+
242
+ end # Orgs::Teams
244
243
  end # Github