Skip to content

Commit 72e55c3

Browse files
committed
1 parent ba8d906 commit 72e55c3

4 files changed

Lines changed: 298 additions & 0 deletions

File tree

lib/github_api/client/issues/assignees.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,38 @@ def check(*args)
3838
rescue Github::Error::NotFound
3939
false
4040
end
41+
42+
# Add assignees to an issue
43+
#
44+
# @example
45+
# github = Github.new
46+
# github.issues.assignees.add 'user', 'repo', 'issue-number',
47+
# 'hubot', 'other_assignee', ...
48+
#
49+
# @api public
50+
def add(*args)
51+
arguments(args, required: [:user, :repo, :number])
52+
params = arguments.params
53+
params['data'] = { 'assignees' => arguments.remaining } unless arguments.remaining.empty?
54+
55+
post_request("/repos/#{arguments.user}/#{arguments.repo}/issues/#{arguments.number}/assignees", params)
56+
end
57+
alias :<< :add
58+
59+
# Remove a assignees from an issue
60+
#
61+
# @example
62+
# github = Github.new
63+
# github.issues.assignees.remove 'user', 'repo', 'issue-number',
64+
# 'hubot', 'other_assignee'
65+
#
66+
# @api public
67+
def remove(*args)
68+
arguments(args, required: [:user, :repo, :number])
69+
params = arguments.params
70+
params['data'] = { 'assignees' => arguments.remaining } unless arguments.remaining.empty?
71+
72+
delete_request("/repos/#{arguments.user}/#{arguments.repo}/issues/#{arguments.number}/assignees", params)
73+
end
4174
end # Issues::Assignees
4275
end # Github
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
{
2+
"id": 1,
3+
"url": "https://api.github.com/repos/octocat/Hello-World/issues/1347",
4+
"repository_url": "https://api.github.com/repos/octocat/Hello-World",
5+
"labels_url": "https://api.github.com/repos/octocat/Hello-World/issues/1347/labels{/name}",
6+
"comments_url": "https://api.github.com/repos/octocat/Hello-World/issues/1347/comments",
7+
"events_url": "https://api.github.com/repos/octocat/Hello-World/issues/1347/events",
8+
"html_url": "https://github.com/octocat/Hello-World/issues/1347",
9+
"number": 1347,
10+
"state": "open",
11+
"title": "Found a bug",
12+
"body": "I'm having a problem with this.",
13+
"user": {
14+
"login": "octocat",
15+
"id": 1,
16+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
17+
"gravatar_id": "",
18+
"url": "https://api.github.com/users/octocat",
19+
"html_url": "https://github.com/octocat",
20+
"followers_url": "https://api.github.com/users/octocat/followers",
21+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
22+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
23+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
24+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
25+
"organizations_url": "https://api.github.com/users/octocat/orgs",
26+
"repos_url": "https://api.github.com/users/octocat/repos",
27+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
28+
"received_events_url": "https://api.github.com/users/octocat/received_events",
29+
"type": "User",
30+
"site_admin": false
31+
},
32+
"labels": [
33+
{
34+
"id": 208045946,
35+
"url": "https://api.github.com/repos/octocat/Hello-World/labels/bug",
36+
"name": "bug",
37+
"color": "f29513",
38+
"default": true
39+
}
40+
],
41+
"assignee": {
42+
"login": "octocat",
43+
"id": 1,
44+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
45+
"gravatar_id": "",
46+
"url": "https://api.github.com/users/octocat",
47+
"html_url": "https://github.com/octocat",
48+
"followers_url": "https://api.github.com/users/octocat/followers",
49+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
50+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
51+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
52+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
53+
"organizations_url": "https://api.github.com/users/octocat/orgs",
54+
"repos_url": "https://api.github.com/users/octocat/repos",
55+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
56+
"received_events_url": "https://api.github.com/users/octocat/received_events",
57+
"type": "User",
58+
"site_admin": false
59+
},
60+
"milestone": {
61+
"url": "https://api.github.com/repos/octocat/Hello-World/milestones/1",
62+
"html_url": "https://github.com/octocat/Hello-World/milestones/v1.0",
63+
"labels_url": "https://api.github.com/repos/octocat/Hello-World/milestones/1/labels",
64+
"id": 1002604,
65+
"number": 1,
66+
"state": "open",
67+
"title": "v1.0",
68+
"description": "Tracking milestone for version 1.0",
69+
"creator": {
70+
"login": "octocat",
71+
"id": 1,
72+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
73+
"gravatar_id": "",
74+
"url": "https://api.github.com/users/octocat",
75+
"html_url": "https://github.com/octocat",
76+
"followers_url": "https://api.github.com/users/octocat/followers",
77+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
78+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
79+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
80+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
81+
"organizations_url": "https://api.github.com/users/octocat/orgs",
82+
"repos_url": "https://api.github.com/users/octocat/repos",
83+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
84+
"received_events_url": "https://api.github.com/users/octocat/received_events",
85+
"type": "User",
86+
"site_admin": false
87+
},
88+
"open_issues": 4,
89+
"closed_issues": 8,
90+
"created_at": "2011-04-10T20:09:31Z",
91+
"updated_at": "2014-03-03T18:58:10Z",
92+
"closed_at": "2013-02-12T13:22:01Z",
93+
"due_on": "2012-10-09T23:39:01Z"
94+
},
95+
"locked": false,
96+
"comments": 0,
97+
"pull_request": {
98+
"url": "https://api.github.com/repos/octocat/Hello-World/pulls/1347",
99+
"html_url": "https://github.com/octocat/Hello-World/pull/1347",
100+
"diff_url": "https://github.com/octocat/Hello-World/pull/1347.diff",
101+
"patch_url": "https://github.com/octocat/Hello-World/pull/1347.patch"
102+
},
103+
"closed_at": null,
104+
"created_at": "2011-04-22T13:33:48Z",
105+
"updated_at": "2011-04-22T13:33:48Z",
106+
"assignees": [
107+
{
108+
"login": "octocat",
109+
"id": 1,
110+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
111+
"gravatar_id": "",
112+
"url": "https://api.github.com/users/octocat",
113+
"html_url": "https://github.com/octocat",
114+
"followers_url": "https://api.github.com/users/octocat/followers",
115+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
116+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
117+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
118+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
119+
"organizations_url": "https://api.github.com/users/octocat/orgs",
120+
"repos_url": "https://api.github.com/users/octocat/repos",
121+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
122+
"received_events_url": "https://api.github.com/users/octocat/received_events",
123+
"type": "User",
124+
"site_admin": false
125+
},
126+
{
127+
"login": "hubot",
128+
"id": 1,
129+
"avatar_url": "https://github.com/images/error/hubot_happy.gif",
130+
"gravatar_id": "",
131+
"url": "https://api.github.com/users/hubot",
132+
"html_url": "https://github.com/hubot",
133+
"followers_url": "https://api.github.com/users/hubot/followers",
134+
"following_url": "https://api.github.com/users/hubot/following{/other_user}",
135+
"gists_url": "https://api.github.com/users/hubot/gists{/gist_id}",
136+
"starred_url": "https://api.github.com/users/hubot/starred{/owner}{/repo}",
137+
"subscriptions_url": "https://api.github.com/users/hubot/subscriptions",
138+
"organizations_url": "https://api.github.com/users/hubot/orgs",
139+
"repos_url": "https://api.github.com/users/hubot/repos",
140+
"events_url": "https://api.github.com/users/hubot/events{/privacy}",
141+
"received_events_url": "https://api.github.com/users/hubot/received_events",
142+
"type": "User",
143+
"site_admin": true
144+
},
145+
{
146+
"login": "other_user",
147+
"id": 1,
148+
"avatar_url": "https://github.com/images/error/other_user_happy.gif",
149+
"gravatar_id": "",
150+
"url": "https://api.github.com/users/other_user",
151+
"html_url": "https://github.com/other_user",
152+
"followers_url": "https://api.github.com/users/other_user/followers",
153+
"following_url": "https://api.github.com/users/other_user/following{/other_user}",
154+
"gists_url": "https://api.github.com/users/other_user/gists{/gist_id}",
155+
"starred_url": "https://api.github.com/users/other_user/starred{/owner}{/repo}",
156+
"subscriptions_url": "https://api.github.com/users/other_user/subscriptions",
157+
"organizations_url": "https://api.github.com/users/other_user/orgs",
158+
"repos_url": "https://api.github.com/users/other_user/repos",
159+
"events_url": "https://api.github.com/users/other_user/events{/privacy}",
160+
"received_events_url": "https://api.github.com/users/other_user/received_events",
161+
"type": "User",
162+
"site_admin": false
163+
}
164+
]
165+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# encoding: utf-8
2+
3+
require 'spec_helper'
4+
5+
describe Github::Client::Issues::Assignees, '#add' do
6+
let(:user) { 'peter-murach' }
7+
let(:repo) { 'github' }
8+
let(:request_path) { "/repos/#{user}/#{repo}/issues/#{issue_id}/assignees" }
9+
10+
before {
11+
stub_post(request_path).
12+
to_return(:body => body, :status => status,
13+
:headers => {:content_type => "application/json; charset=utf-8"})
14+
}
15+
16+
after { reset_authentication_for(subject) }
17+
18+
let(:issue_id) { 1 }
19+
let(:assignee) { "octocat" }
20+
21+
context "assignees added" do
22+
let(:body) { fixture('issues/issue_assignees.json') }
23+
let(:status) { 200 }
24+
25+
it "should fail to add assignees if issue-id is missing" do
26+
expect {
27+
subject.add user, repo, nil, assignee
28+
}.to raise_error(ArgumentError)
29+
end
30+
31+
it "should create resource successfully" do
32+
subject.add user, repo, issue_id, assignee
33+
a_post(request_path).should have_been_made
34+
end
35+
36+
it "should return the resource" do
37+
issue = subject.add user, repo, issue_id, assignee
38+
issue.assignees.first.should be_a Github::Mash
39+
end
40+
41+
it "should get the assignee information" do
42+
issue = subject.add user, repo, issue_id, assignee
43+
issue.assignees.first.login.should == 'octocat'
44+
end
45+
end
46+
47+
it_should_behave_like 'request failure' do
48+
let(:requestable) { subject.add user, repo, issue_id, assignee }
49+
end
50+
end # add
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# encoding: utf-8
2+
3+
require 'spec_helper'
4+
5+
describe Github::Client::Issues::Assignees, '#remove' do
6+
let(:user) { 'peter-murach' }
7+
let(:repo) { 'github' }
8+
let(:request_path) { "/repos/#{user}/#{repo}/issues/#{issue_id}/assignees" }
9+
10+
before {
11+
stub_delete(request_path).
12+
to_return(:body => body, :status => status,
13+
:headers => {:content_type => "application/json; charset=utf-8"})
14+
}
15+
16+
after { reset_authentication_for(subject) }
17+
18+
let(:issue_id) { 1 }
19+
let(:assignee) { "octocat" }
20+
21+
context "assignees removed" do
22+
let(:body) { fixture('issues/issue_assignees.json') }
23+
let(:status) { 200 }
24+
25+
it "should fail to remove assignees if issue-id is missing" do
26+
expect {
27+
subject.remove user, repo, nil, assignee
28+
}.to raise_error(ArgumentError)
29+
end
30+
31+
it "should remove resource successfully" do
32+
subject.remove user, repo, issue_id, assignee
33+
a_delete(request_path).should have_been_made
34+
end
35+
36+
it "should return the resource" do
37+
issue = subject.remove user, repo, issue_id, assignee
38+
issue.assignees.first.should be_a Github::Mash
39+
end
40+
41+
it "should get the assignee information" do
42+
issue = subject.remove user, repo, issue_id, assignee
43+
issue.assignees.first.login.should == 'octocat'
44+
end
45+
end
46+
47+
it_should_behave_like 'request failure' do
48+
let(:requestable) { subject.remove user, repo, issue_id, assignee }
49+
end
50+
end # remove

0 commit comments

Comments
 (0)