-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniel Farrell
committed
Jun 7, 2016
1 parent
ce2782a
commit e95a419
Showing
7 changed files
with
346 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
defmodule Tentacat.Repositories.Labels do | ||
import Tentacat | ||
alias Tentacat.Client | ||
|
||
@doc """ | ||
List labels on a repository | ||
## Example | ||
Tentacat.Repositories.Labels.list "elixir-lang", "elixir" | ||
More info at: https://developer.github.com/v3/issues/labels/#list-all-labels-for-this-repository | ||
""" | ||
@spec list(binary, binary, Client.t) :: Tentacat.response | ||
def list(owner, repo, client \\ %Client{}) do | ||
get "repos/#{owner}/#{repo}/labels", client | ||
end | ||
|
||
@doc """ | ||
Find a label on a repository | ||
## Example | ||
Tentacat.Repositories.Labels.find "elixir-lang", "elixir", "WIP" | ||
More info at: https://developer.github.com/v3/issues/labels/#get-a-single-label | ||
""" | ||
@spec find(binary, binary, binary, Client.t) :: Tentacat.response | ||
def find(owner, repo, name, client \\ %Client{}) do | ||
get "repos/#{owner}/#{repo}/labels/#{name}", client | ||
end | ||
|
||
@doc """ | ||
Creates a new label on a repository | ||
Possible values for `body`: | ||
* [name: "name of label"] (required) | ||
* [color: "color of label"] (required) | ||
## Example | ||
Tentacat.Repositories.Labels.create "elixir-lang", "elixir", %{name: "Important", color: "f29513"} | ||
More info at: https://developer.github.com/v3/issues/labels/#create-a-label | ||
""" | ||
@spec create(binary, binary, list | map, Client.t) :: Tentacat.response | ||
def create(owner, repo, body, client \\ %Client{}) do | ||
post "repos/#{owner}/#{repo}/labels", client, body | ||
end | ||
|
||
@doc """ | ||
Update a label on a repository | ||
Possible values for `body`: | ||
* [name: "name of label"] (required) | ||
* [color: "color of label"] (required) | ||
## Example | ||
Tentacat.Repositories.Labels.update "elixir-lang", "elixir", "Important", %{color: "000000"} | ||
More info at: https://developer.github.com/v3/issues/labels/#update-a-label | ||
""" | ||
@spec update(binary, binary, binary, list | map, Client.t) :: Tentacat.response | ||
def update(owner, repo, name, body, client \\ %Client{}) do | ||
patch "repos/#{owner}/#{repo}/labels/#{name}", client, body | ||
end | ||
|
||
@doc """ | ||
Delete a label on a repository | ||
## Example | ||
Tentacat.Repositories.Labels.delete "elixir-lang", "elixir", "Important" | ||
More info at: https://developer.github.com/v3/issues/labels/#delete-a-label | ||
""" | ||
@spec delete(binary, binary, binary , Client.t) :: Tentacat.response | ||
def delete(owner, repo, name, client \\ %Client{}) do | ||
delete "repos/#{owner}/#{repo}/labels/#{name}", client | ||
end | ||
|
||
end |
42 changes: 42 additions & 0 deletions
42
test/fixture/vcr_cassettes/repositories/labels#create.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
[ | ||
{ | ||
"request": { | ||
"body": "{\"name\":\"WIP\",\"color\":\"123456\"}", | ||
"headers": { | ||
"User-agent": "tentacat" | ||
}, | ||
"method": "post", | ||
"options": [], | ||
"request_body": "", | ||
"url": "https://api.github.com/repos/danielfarrell/elixir/labels" | ||
}, | ||
"response": { | ||
"body": "{\"url\":\"https://api.github.com/repos/danielfarrell/elixir/labels/WIP\",\"name\":\"WIP\",\"color\":\"123456\"}", | ||
"headers": { | ||
"Server": "github.com", | ||
"Date": "Tue, 07 Jun 2016 15:12:44 GMT", | ||
"Content-Type": "application/json; charset=utf-8", | ||
"Content-Length": "2260", | ||
"Status": "200 OK", | ||
"X-RateLimit-Limit": "60", | ||
"X-RateLimit-Remaining": "42", | ||
"X-RateLimit-Reset": "1465314971", | ||
"Cache-Control": "public, max-age=60, s-maxage=60", | ||
"Vary": "Accept", | ||
"ETag": "\"1598b9c2c9191001f30226e51a54afb2\"", | ||
"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": "318e55760cf7cdb40e61175a4d36cd32", | ||
"X-GitHub-Request-Id": "32E9B27E:B216:239A2390:5756E46C" | ||
}, | ||
"status_code": 201, | ||
"type": "ok" | ||
} | ||
} | ||
] |
42 changes: 42 additions & 0 deletions
42
test/fixture/vcr_cassettes/repositories/labels#delete.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
[ | ||
{ | ||
"request": { | ||
"body": "\"\\\"\\\"\"", | ||
"headers": { | ||
"User-agent": "tentacat" | ||
}, | ||
"method": "delete", | ||
"options": [], | ||
"request_body": "", | ||
"url": "https://api.github.com/repos/danielfarrell/elixir/labels/WIP" | ||
}, | ||
"response": { | ||
"body": "", | ||
"headers": { | ||
"Server": "github.com", | ||
"Date": "Tue, 07 Jun 2016 15:12:44 GMT", | ||
"Content-Type": "application/json; charset=utf-8", | ||
"Content-Length": "2260", | ||
"Status": "200 OK", | ||
"X-RateLimit-Limit": "60", | ||
"X-RateLimit-Remaining": "42", | ||
"X-RateLimit-Reset": "1465314971", | ||
"Cache-Control": "public, max-age=60, s-maxage=60", | ||
"Vary": "Accept", | ||
"ETag": "\"1598b9c2c9191001f30226e51a54afb2\"", | ||
"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": "318e55760cf7cdb40e61175a4d36cd32", | ||
"X-GitHub-Request-Id": "32E9B27E:B216:239A2390:5756E46C" | ||
}, | ||
"status_code": 204, | ||
"type": "ok" | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
[ | ||
{ | ||
"request": { | ||
"body": "\"\\\"\\\"\"", | ||
"headers": { | ||
"User-agent": "tentacat" | ||
}, | ||
"method": "get", | ||
"options": [], | ||
"request_body": "", | ||
"url": "https://api.github.com/repos/danielfarrell/elixir/labels/WIP" | ||
}, | ||
"response": { | ||
"body": "{\"url\":\"https://api.github.com/repos/danielfarrell/elixir/labels/WIP\",\"name\":\"WIP\",\"color\":\"000000\"}", | ||
"headers": { | ||
"Server": "github.com", | ||
"Date": "Tue, 07 Jun 2016 15:12:44 GMT", | ||
"Content-Type": "application/json; charset=utf-8", | ||
"Content-Length": "2260", | ||
"Status": "200 OK", | ||
"X-RateLimit-Limit": "60", | ||
"X-RateLimit-Remaining": "42", | ||
"X-RateLimit-Reset": "1465314971", | ||
"Cache-Control": "public, max-age=60, s-maxage=60", | ||
"Vary": "Accept", | ||
"ETag": "\"1598b9c2c9191001f30226e51a54afb2\"", | ||
"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": "318e55760cf7cdb40e61175a4d36cd32", | ||
"X-GitHub-Request-Id": "32E9B27E:B216:239A2390:5756E46C" | ||
}, | ||
"status_code": 200, | ||
"type": "ok" | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
[ | ||
{ | ||
"request": { | ||
"body": "\"\\\"\\\"\"", | ||
"headers": { | ||
"User-agent": "tentacat" | ||
}, | ||
"method": "get", | ||
"options": [], | ||
"request_body": "", | ||
"url": "https://api.github.com/repos/danielfarrell/elixir/labels" | ||
}, | ||
"response": { | ||
"body": "[{\"url\":\"https://api.github.com/repos/danielfarrell/elixir/labels/WIP\",\"name\":\"WIP\",\"color\":\"000000\"}]", | ||
"headers": { | ||
"Server": "github.com", | ||
"Date": "Tue, 07 Jun 2016 15:12:44 GMT", | ||
"Content-Type": "application/json; charset=utf-8", | ||
"Content-Length": "2260", | ||
"Status": "200 OK", | ||
"X-RateLimit-Limit": "60", | ||
"X-RateLimit-Remaining": "42", | ||
"X-RateLimit-Reset": "1465314971", | ||
"Cache-Control": "public, max-age=60, s-maxage=60", | ||
"Vary": "Accept", | ||
"ETag": "\"1598b9c2c9191001f30226e51a54afb2\"", | ||
"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": "318e55760cf7cdb40e61175a4d36cd32", | ||
"X-GitHub-Request-Id": "32E9B27E:B216:239A2390:5756E46C" | ||
}, | ||
"status_code": 200, | ||
"type": "ok" | ||
} | ||
} | ||
] |
42 changes: 42 additions & 0 deletions
42
test/fixture/vcr_cassettes/repositories/labels#update.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
[ | ||
{ | ||
"request": { | ||
"body": "{\"color\":\"654321\"}", | ||
"headers": { | ||
"User-agent": "tentacat" | ||
}, | ||
"method": "patch", | ||
"options": [], | ||
"request_body": "", | ||
"url": "https://api.github.com/repos/danielfarrell/elixir/labels/WIP" | ||
}, | ||
"response": { | ||
"body": "{\"url\":\"https://api.github.com/repos/danielfarrell/elixir/labels/WIP\",\"name\":\"WIP\",\"color\":\"654321\"}", | ||
"headers": { | ||
"Server": "github.com", | ||
"Date": "Tue, 07 Jun 2016 15:12:44 GMT", | ||
"Content-Type": "application/json; charset=utf-8", | ||
"Content-Length": "2260", | ||
"Status": "200 OK", | ||
"X-RateLimit-Limit": "60", | ||
"X-RateLimit-Remaining": "42", | ||
"X-RateLimit-Reset": "1465314971", | ||
"Cache-Control": "public, max-age=60, s-maxage=60", | ||
"Vary": "Accept", | ||
"ETag": "\"1598b9c2c9191001f30226e51a54afb2\"", | ||
"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": "318e55760cf7cdb40e61175a4d36cd32", | ||
"X-GitHub-Request-Id": "32E9B27E:B216:239A2390:5756E46C" | ||
}, | ||
"status_code": 200, | ||
"type": "ok" | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
defmodule Tentacat.Repositories.LabelsTest do | ||
use ExUnit.Case, async: false | ||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney | ||
import Tentacat.Repositories.Labels | ||
|
||
doctest Tentacat.Repositories.Labels | ||
|
||
@client Tentacat.Client.new(%{access_token: "yourtokencomeshere"}) | ||
|
||
setup_all do | ||
HTTPoison.start | ||
end | ||
|
||
test "list/3" do | ||
use_cassette "repositories/labels#list" do | ||
assert list("danielfarrell", "elixir", @client) == [%{"url" => "https://api.github.com/repos/danielfarrell/elixir/labels/WIP", "name" => "WIP", "color" => "000000"}] | ||
end | ||
end | ||
|
||
test "find/4" do | ||
use_cassette "repositories/labels#find" do | ||
%{"name" => name, "color" => color} = find("danielfarrell", "elixir", "WIP", @client) | ||
assert name == "WIP" | ||
assert color == "000000" | ||
end | ||
end | ||
|
||
test "create/4" do | ||
use_cassette "repositories/labels#create" do | ||
{status_code, %{"name" => name, "color" => color}} = create("danielfarrell", "elixir", %{name: "WIP", color: "123456"}, @client) | ||
assert status_code == 201 | ||
assert name == "WIP" | ||
assert color == "123456" | ||
end | ||
end | ||
|
||
test "update/5" do | ||
use_cassette "repositories/labels#update" do | ||
%{"name" => name, "color" => color} = update("danielfarrell", "elixir", "WIP", %{color: "654321"}, @client) | ||
assert name == "WIP" | ||
assert color == "654321" | ||
end | ||
end | ||
|
||
test "delete/4" do | ||
use_cassette "repositories/labels#delete" do | ||
{status_code, _} = delete("danielfarrell", "elixir", "WIP", @client) | ||
assert status_code == 204 | ||
end | ||
end | ||
end |