Skip to content

Commit

Permalink
Add support for issue create/update
Browse files Browse the repository at this point in the history
Also build tests for existing issue methods
  • Loading branch information
Daniel Farrell committed May 26, 2016
1 parent 0a9c850 commit 3aa9ca4
Show file tree
Hide file tree
Showing 8 changed files with 332 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Tentacool + Cat = Tentacat
* Gitignore
* Contents
* Trees
* Issues
* Comments
* Events
* Labels
* Pulls
* Comments
* Commits
Expand Down
47 changes: 47 additions & 0 deletions lib/tentacat/issues/issues.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,51 @@ defmodule Tentacat.Issues do
def find(owner, repo, number, client \\ %Client{}) do
get "repos/#{owner}/#{repo}/issues/#{number}", client
end

@doc """
Create an issue
Possible values for `body`:
* [title: "title of issue"] (required)
* [body: "body of issue"]
* [assignee: "username"]
* [milestone: 4]
* [labels: ["bug", "frontend"]]
## Example
Tentacat.Issues.create "elixir-lang", "elixir", %{"title" => "Issue", "body" => "Details"}
Tentacat.Issues.create "elixir-lang", "elixir", %{"title" => "Issue", "body" => "Details"}, client
More info at: https://developer.github.com/v3/issues/#create-an-issue
"""
@spec create(binary, binary, list | map, Client.t) :: Tentacat.response
def create(owner, repo, body, client \\ %Client{}) do
post "repos/#{owner}/#{repo}/issues", client, body
end

@doc """
Update an issue
Possible values for `body`:
* [title: "title of issue"]
* [body: "body of issue"]
* [assignee: "username"]
* [state: "closed"]
* [milestone: 4]
* [labels: ["bug", "frontend"]]
## Example
Tentacat.Issues.update "elixir-lang", "elixir", "2974", %{"assignee" => "edgurgel"}
Tentacat.Issues.update "elixir-lang", "elixir", "2974", %{"state" => "closed"}, client
More info at: https://developer.github.com/v3/issues/#edit-an-issue
"""
@spec update(binary, binary, binary | integer, list | map, Client.t) :: Tentacat.response
def update(owner, repo, number, body, client \\ %Client{}) do
patch "repos/#{owner}/#{repo}/issues/#{number}", client, body
end
end
45 changes: 45 additions & 0 deletions test/fixture/vcr_cassettes/issues/issues#create.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[
{
"request": {
"body": "{\"title\":\"Something broke\"}",
"headers": {
"User-agent": "tentacat",
"Authorization": "token yourtokengoeshere"
},
"method": "post",
"options": [],
"request_body": "",
"url": "https://api.github.com/repos/soudqwiggle/elixir-conspiracy/issues"
},
"response": {
"body": "{\"id\":1,\"url\":\"https://api.github.com/repos/soudqwiggle/elixir-conspiracy/issues/3\",\"repository_url\":\"https://api.github.com/repos/soudqwiggle/elixir-conspiracy\",\"labels_url\":\"https://api.github.com/repos/soudqwiggle/elixir-conspiracy/issues/3/labels{/name}\",\"comments_url\":\"https://api.github.com/repos/soudqwiggle/elixir-conspiracy/issues/3/comments\",\"events_url\":\"https://api.github.com/repos/soudqwiggle/elixir-conspiracy/issues/3/events\",\"html_url\":\"https://github.com/soudqwiggle/elixir-conspiracy/issues/3\",\"number\":3,\"state\":\"open\",\"title\":\"Something broke\",\"body\":\"\",\"user\":{\"login\":\"octocat\",\"id\":1,\"avatar_url\":\"https://github.com/images/error/octocat_happy.gif\",\"gravatar_id\":\"\",\"url\":\"https://api.github.com/users/octocat\",\"html_url\":\"https://github.com/octocat\",\"followers_url\":\"https://api.github.com/users/octocat/followers\",\"following_url\":\"https://api.github.com/users/octocat/following{/other_user}\",\"gists_url\":\"https://api.github.com/users/octocat/gists{/gist_id}\",\"starred_url\":\"https://api.github.com/users/octocat/starred{/owner}{/repo}\",\"subscriptions_url\":\"https://api.github.com/users/octocat/subscriptions\",\"organizations_url\":\"https://api.github.com/users/octocat/orgs\",\"repos_url\":\"https://api.github.com/users/octocat/repos\",\"events_url\":\"https://api.github.com/users/octocat/events{/privacy}\",\"received_events_url\":\"https://api.github.com/users/octocat/received_events\",\"type\":\"User\",\"site_admin\":false},\"labels\":[{\"url\":\"https://api.github.com/repos/soudqwiggle/elixir-conspiracy/labels/bug\",\"name\":\"bug\",\"color\":\"f29513\"}],\"assignee\":{\"login\":\"octocat\",\"id\":1,\"avatar_url\":\"https://github.com/images/error/octocat_happy.gif\",\"gravatar_id\":\"\",\"url\":\"https://api.github.com/users/octocat\",\"html_url\":\"https://github.com/octocat\",\"followers_url\":\"https://api.github.com/users/octocat/followers\",\"following_url\":\"https://api.github.com/users/octocat/following{/other_user}\",\"gists_url\":\"https://api.github.com/users/octocat/gists{/gist_id}\",\"starred_url\":\"https://api.github.com/users/octocat/starred{/owner}{/repo}\",\"subscriptions_url\":\"https://api.github.com/users/octocat/subscriptions\",\"organizations_url\":\"https://api.github.com/users/octocat/orgs\",\"repos_url\":\"https://api.github.com/users/octocat/repos\",\"events_url\":\"https://api.github.com/users/octocat/events{/privacy}\",\"received_events_url\":\"https://api.github.com/users/octocat/received_events\",\"type\":\"User\",\"site_admin\":false},\"milestone\":{\"url\":\"https://api.github.com/repos/soudqwiggle/elixir-conspiracy/milestones/1\",\"html_url\":\"https://github.com/soudqwiggle/elixir-conspiracy/milestones/v1.0\",\"labels_url\":\"https://api.github.com/repos/soudqwiggle/elixir-conspiracy/milestones/1/labels\",\"id\":1002604,\"number\":1,\"state\":\"open\",\"title\":\"v1.0\",\"description\":\"Trackingmilestoneforversion1.0\",\"creator\":{\"login\":\"octocat\",\"id\":1,\"avatar_url\":\"https://github.com/images/error/octocat_happy.gif\",\"gravatar_id\":\"\",\"url\":\"https://api.github.com/users/octocat\",\"html_url\":\"https://github.com/octocat\",\"followers_url\":\"https://api.github.com/users/octocat/followers\",\"following_url\":\"https://api.github.com/users/octocat/following{/other_user}\",\"gists_url\":\"https://api.github.com/users/octocat/gists{/gist_id}\",\"starred_url\":\"https://api.github.com/users/octocat/starred{/owner}{/repo}\",\"subscriptions_url\":\"https://api.github.com/users/octocat/subscriptions\",\"organizations_url\":\"https://api.github.com/users/octocat/orgs\",\"repos_url\":\"https://api.github.com/users/octocat/repos\",\"events_url\":\"https://api.github.com/users/octocat/events{/privacy}\",\"received_events_url\":\"https://api.github.com/users/octocat/received_events\",\"type\":\"User\",\"site_admin\":false},\"open_issues\":4,\"closed_issues\":8,\"created_at\":\"2011-04-10T20:09:31Z\",\"updated_at\":\"2014-03-03T18:58:10Z\",\"closed_at\":\"2013-02-12T13:22:01Z\",\"due_on\":\"2012-10-09T23:39:01Z\"},\"locked\":false,\"comments\":0,\"pull_request\":{\"url\":\"https://api.github.com/repos/soudqwiggle/elixir-conspiracy/pulls/3\",\"html_url\":\"https://github.com/soudqwiggle/elixir-conspiracy/pull/3\",\"diff_url\":\"https://github.com/soudqwiggle/elixir-conspiracy/pull/3.diff\",\"patch_url\":\"https://github.com/soudqwiggle/elixir-conspiracy/pull/3.patch\"},\"closed_at\":null,\"created_at\":\"2011-04-22T13:33:48Z\",\"updated_at\":\"2011-04-22T13:33:48Z\",\"closed_by\":{\"login\":\"octocat\",\"id\":1,\"avatar_url\":\"https://github.com/images/error/octocat_happy.gif\",\"gravatar_id\":\"\",\"url\":\"https://api.github.com/users/octocat\",\"html_url\":\"https://github.com/octocat\",\"followers_url\":\"https://api.github.com/users/octocat/followers\",\"following_url\":\"https://api.github.com/users/octocat/following{/other_user}\",\"gists_url\":\"https://api.github.com/users/octocat/gists{/gist_id}\",\"starred_url\":\"https://api.github.com/users/octocat/starred{/owner}{/repo}\",\"subscriptions_url\":\"https://api.github.com/users/octocat/subscriptions\",\"organizations_url\":\"https://api.github.com/users/octocat/orgs\",\"repos_url\":\"https://api.github.com/users/octocat/repos\",\"events_url\":\"https://api.github.com/users/octocat/events{/privacy}\",\"received_events_url\":\"https://api.github.com/users/octocat/received_events\",\"type\":\"User\",\"site_admin\":false}}",
"headers": {
"Server": "GitHub.com",
"Date": "Fri, 13 May 2016 00:32:00 GMT",
"Content-Type": "application/json; charset=utf-8",
"Content-Length": "99",
"Status": "201 Created",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4999",
"X-RateLimit-Reset": "1463103120",
"Cache-Control": "private, max-age=60, s-maxage=60",
"Vary": "Accept, Authorization, Cookie, X-GitHub-OTP",
"ETag": "\"ab4e0d15d156bef84f70247602b3ff34\"",
"X-OAuth-Scopes": "admin:org",
"X-Accepted-OAuth-Scopes": "admin:org, repo",
"X-GitHub-Media-Type": "github.v3; format=json",
"Access-Control-Expose-Headers": "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval",
"Access-Control-Allow-Origin": "*",
"Content-Security-Policy": "default-src 'none'",
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
"X-Content-Type-Options": "nosniff",
"X-Frame-Options": "deny",
"X-XSS-Protection": "1; mode=block",
"X-Served-By": "cee4c0729c8e9147e7abcb45b9d69689",
"X-GitHub-Request-Id": "44073D0C:7F8C:1DC332:5735207F"
},
"status_code": 201,
"type": "created"
}
}
]
46 changes: 46 additions & 0 deletions test/fixture/vcr_cassettes/issues/issues#filter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[
{
"request": {
"body": "\"\"",
"headers": {
"User-agent": "tentacat",
"Authorization": "token yourtokencomeshere"
},
"method": "get",
"options": [],
"request_body": "",
"url": "https://api.github.com/repos/soudqwiggle/elixir-conspiracy/issues?state=open"
},
"response": {
"body": "[]",
"headers": {
"Server": "GitHub.com",
"Date": "Fri, 18 Dec 2015 21:39:52 GMT",
"Content-Type": "application/json; charset=utf-8",
"Content-Length": "2",
"Status": "200 OK",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4999",
"X-RateLimit-Reset": "1450478392",
"Cache-Control": "private, max-age=60, s-maxage=60",
"ETag": "\"411634914830e1b11d359df5aeb17ed4\"",
"X-OAuth-Scopes": "admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user",
"X-Accepted-OAuth-Scopes": "",
"Vary": "Accept, Authorization, Cookie, X-GitHub-OTP",
"X-GitHub-Media-Type": "github.v3; format=json",
"Access-Control-Allow-Credentials": "true",
"Access-Control-Expose-Headers": "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval",
"Access-Control-Allow-Origin": "*",
"Content-Security-Policy": "default-src 'none'",
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
"X-Content-Type-Options": "nosniff",
"X-Frame-Options": "deny",
"X-XSS-Protection": "1; mode=block",
"X-Served-By": "07ff1c8a09e44b62e277fae50a1b1dc4",
"X-GitHub-Request-Id": "3E552BA7:134F4:1252D5D2:56747D27"
},
"status_code": 200,
"type": "ok"
}
}
]
46 changes: 46 additions & 0 deletions test/fixture/vcr_cassettes/issues/issues#find.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[
{
"request": {
"body": "\"\\\"\\\"\"",
"headers": {
"User-agent": "tentacat",
"Authorization": "token yourtokencomeshere"
},
"method": "get",
"options": [],
"request_body": "",
"url": "https://api.github.com/repos/soudqwiggle/elixir-conspiracy/issues/1347"
},
"response": {
"body": "{\"id\":1,\"url\":\"https://api.github.com/repos/soudqwiggle/elixir-conspiracy/issues/1347\",\"repository_url\":\"https://api.github.com/repos/soudqwiggle/elixir-conspiracy\",\"labels_url\":\"https://api.github.com/repos/soudqwiggle/elixir-conspiracy/issues/1347/labels{/name}\",\"comments_url\":\"https://api.github.com/repos/soudqwiggle/elixir-conspiracy/issues/1347/comments\",\"events_url\":\"https://api.github.com/repos/soudqwiggle/elixir-conspiracy/issues/1347/events\",\"html_url\":\"https://github.com/soudqwiggle/elixir-conspiracy/issues/1347\",\"number\":1347,\"state\":\"open\",\"title\":\"Foundabug\",\"body\":\"Something is broken\",\"user\":{\"login\":\"octocat\",\"id\":1,\"avatar_url\":\"https://github.com/images/error/octocat_happy.gif\",\"gravatar_id\":\"\",\"url\":\"https://api.github.com/users/octocat\",\"html_url\":\"https://github.com/octocat\",\"followers_url\":\"https://api.github.com/users/octocat/followers\",\"following_url\":\"https://api.github.com/users/octocat/following{/other_user}\",\"gists_url\":\"https://api.github.com/users/octocat/gists{/gist_id}\",\"starred_url\":\"https://api.github.com/users/octocat/starred{/owner}{/repo}\",\"subscriptions_url\":\"https://api.github.com/users/octocat/subscriptions\",\"organizations_url\":\"https://api.github.com/users/octocat/orgs\",\"repos_url\":\"https://api.github.com/users/octocat/repos\",\"events_url\":\"https://api.github.com/users/octocat/events{/privacy}\",\"received_events_url\":\"https://api.github.com/users/octocat/received_events\",\"type\":\"User\",\"site_admin\":false},\"labels\":[{\"url\":\"https://api.github.com/repos/soudqwiggle/elixir-conspiracy/labels/bug\",\"name\":\"bug\",\"color\":\"f29513\"}],\"assignee\":{\"login\":\"octocat\",\"id\":1,\"avatar_url\":\"https://github.com/images/error/octocat_happy.gif\",\"gravatar_id\":\"\",\"url\":\"https://api.github.com/users/octocat\",\"html_url\":\"https://github.com/octocat\",\"followers_url\":\"https://api.github.com/users/octocat/followers\",\"following_url\":\"https://api.github.com/users/octocat/following{/other_user}\",\"gists_url\":\"https://api.github.com/users/octocat/gists{/gist_id}\",\"starred_url\":\"https://api.github.com/users/octocat/starred{/owner}{/repo}\",\"subscriptions_url\":\"https://api.github.com/users/octocat/subscriptions\",\"organizations_url\":\"https://api.github.com/users/octocat/orgs\",\"repos_url\":\"https://api.github.com/users/octocat/repos\",\"events_url\":\"https://api.github.com/users/octocat/events{/privacy}\",\"received_events_url\":\"https://api.github.com/users/octocat/received_events\",\"type\":\"User\",\"site_admin\":false},\"milestone\":{\"url\":\"https://api.github.com/repos/soudqwiggle/elixir-conspiracy/milestones/1\",\"html_url\":\"https://github.com/soudqwiggle/elixir-conspiracy/milestones/v1.0\",\"labels_url\":\"https://api.github.com/repos/soudqwiggle/elixir-conspiracy/milestones/1/labels\",\"id\":1002604,\"number\":1,\"state\":\"open\",\"title\":\"v1.0\",\"description\":\"Trackingmilestoneforversion1.0\",\"creator\":{\"login\":\"octocat\",\"id\":1,\"avatar_url\":\"https://github.com/images/error/octocat_happy.gif\",\"gravatar_id\":\"\",\"url\":\"https://api.github.com/users/octocat\",\"html_url\":\"https://github.com/octocat\",\"followers_url\":\"https://api.github.com/users/octocat/followers\",\"following_url\":\"https://api.github.com/users/octocat/following{/other_user}\",\"gists_url\":\"https://api.github.com/users/octocat/gists{/gist_id}\",\"starred_url\":\"https://api.github.com/users/octocat/starred{/owner}{/repo}\",\"subscriptions_url\":\"https://api.github.com/users/octocat/subscriptions\",\"organizations_url\":\"https://api.github.com/users/octocat/orgs\",\"repos_url\":\"https://api.github.com/users/octocat/repos\",\"events_url\":\"https://api.github.com/users/octocat/events{/privacy}\",\"received_events_url\":\"https://api.github.com/users/octocat/received_events\",\"type\":\"User\",\"site_admin\":false},\"open_issues\":4,\"closed_issues\":8,\"created_at\":\"2011-04-10T20:09:31Z\",\"updated_at\":\"2014-03-03T18:58:10Z\",\"closed_at\":\"2013-02-12T13:22:01Z\",\"due_on\":\"2012-10-09T23:39:01Z\"},\"locked\":false,\"comments\":0,\"pull_request\":{\"url\":\"https://api.github.com/repos/soudqwiggle/elixir-conspiracy/pulls/1347\",\"html_url\":\"https://github.com/soudqwiggle/elixir-conspiracy/pull/1347\",\"diff_url\":\"https://github.com/soudqwiggle/elixir-conspiracy/pull/1347.diff\",\"patch_url\":\"https://github.com/soudqwiggle/elixir-conspiracy/pull/1347.patch\"},\"closed_at\":null,\"created_at\":\"2011-04-22T13:33:48Z\",\"updated_at\":\"2011-04-22T13:33:48Z\",\"closed_by\":{\"login\":\"octocat\",\"id\":1,\"avatar_url\":\"https://github.com/images/error/octocat_happy.gif\",\"gravatar_id\":\"\",\"url\":\"https://api.github.com/users/octocat\",\"html_url\":\"https://github.com/octocat\",\"followers_url\":\"https://api.github.com/users/octocat/followers\",\"following_url\":\"https://api.github.com/users/octocat/following{/other_user}\",\"gists_url\":\"https://api.github.com/users/octocat/gists{/gist_id}\",\"starred_url\":\"https://api.github.com/users/octocat/starred{/owner}{/repo}\",\"subscriptions_url\":\"https://api.github.com/users/octocat/subscriptions\",\"organizations_url\":\"https://api.github.com/users/octocat/orgs\",\"repos_url\":\"https://api.github.com/users/octocat/repos\",\"events_url\":\"https://api.github.com/users/octocat/events{/privacy}\",\"received_events_url\":\"https://api.github.com/users/octocat/received_events\",\"type\":\"User\",\"site_admin\":false}}",
"headers": {
"Server": "GitHub.com",
"Date": "Wed, 13 Apr 2016 17:22:25 GMT",
"Content-Type": "application/json; charset=utf-8",
"Content-Length": "2899",
"Status": "200 OK",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4996",
"X-RateLimit-Reset": "1460570248",
"Cache-Control": "private, max-age=60, s-maxage=60",
"Vary": "Accept, Authorization, Cookie, X-GitHub-OTP",
"ETag": "\"8c0087cf5cf191d9039d16d11e2a7cc3\"",
"Last-Modified": "Fri, 08 Apr 2016 20:44:47 GMT",
"X-OAuth-Scopes": "gist, repo",
"X-Accepted-OAuth-Scopes": "repo",
"X-GitHub-Media-Type": "github.v3; format=json",
"Access-Control-Expose-Headers": "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval",
"Access-Control-Allow-Origin": "*",
"Content-Security-Policy": "default-src 'none'",
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
"X-Content-Type-Options": "nosniff",
"X-Frame-Options": "deny",
"X-XSS-Protection": "1; mode=block",
"X-Served-By": "8dd185e423974a7e13abbbe6e060031e",
"X-GitHub-Request-Id": "323A6983:76D0:2B28F0E:570E8051"
},
"status_code": 200,
"type": "ok"
}
}
]
46 changes: 46 additions & 0 deletions test/fixture/vcr_cassettes/issues/issues#list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[
{
"request": {
"body": "\"\"",
"headers": {
"User-agent": "tentacat",
"Authorization": "token yourtokencomeshere"
},
"method": "get",
"options": [],
"request_body": "",
"url": "https://api.github.com/repos/soudqwiggle/elixir-conspiracy/issues"
},
"response": {
"body": "[]",
"headers": {
"Server": "GitHub.com",
"Date": "Fri, 18 Dec 2015 21:39:52 GMT",
"Content-Type": "application/json; charset=utf-8",
"Content-Length": "2",
"Status": "200 OK",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4999",
"X-RateLimit-Reset": "1450478392",
"Cache-Control": "private, max-age=60, s-maxage=60",
"ETag": "\"411634914830e1b11d359df5aeb17ed4\"",
"X-OAuth-Scopes": "admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user",
"X-Accepted-OAuth-Scopes": "",
"Vary": "Accept, Authorization, Cookie, X-GitHub-OTP",
"X-GitHub-Media-Type": "github.v3; format=json",
"Access-Control-Allow-Credentials": "true",
"Access-Control-Expose-Headers": "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval",
"Access-Control-Allow-Origin": "*",
"Content-Security-Policy": "default-src 'none'",
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
"X-Content-Type-Options": "nosniff",
"X-Frame-Options": "deny",
"X-XSS-Protection": "1; mode=block",
"X-Served-By": "07ff1c8a09e44b62e277fae50a1b1dc4",
"X-GitHub-Request-Id": "3E552BA7:134F4:1252D5D2:56747D27"
},
"status_code": 200,
"type": "ok"
}
}
]
Loading

0 comments on commit 3aa9ca4

Please sign in to comment.