git_hub_bub 1.0.0 → 2.0.0
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.
- checksums.yaml +5 -5
- data/.github/dependabot.yml +11 -0
- data/.github/workflows/ci.yml +43 -0
- data/.standard.yml +1 -0
- data/Gemfile +2 -2
- data/README.md +2 -1
- data/Rakefile +8 -9
- data/changelog.md +10 -1
- data/git_hub_bub.gemspec +17 -17
- data/lib/git_hub_bub/request.rb +32 -29
- data/lib/git_hub_bub/response.rb +85 -83
- data/lib/git_hub_bub/version.rb +1 -1
- data/lib/git_hub_bub.rb +11 -13
- data/test/git_hub_bub/request_test.rb +42 -43
- data/test/git_hub_bub/response_test.rb +34 -18
- data/test/git_hub_bub/valid_token_test.rb +17 -8
- data/test/test_helper.rb +28 -31
- metadata +44 -29
- data/.travis.yml +0 -8
|
@@ -1,100 +1,99 @@
|
|
|
1
|
-
require
|
|
1
|
+
require "test_helper"
|
|
2
2
|
|
|
3
3
|
class RequestTest < Test::Unit::TestCase
|
|
4
|
-
|
|
5
4
|
def teardown
|
|
6
5
|
GitHubBub::Request.clear_callbacks
|
|
7
6
|
end
|
|
8
7
|
|
|
9
8
|
def test_set_url
|
|
10
|
-
request = GitHubBub::Request.new(
|
|
9
|
+
request = GitHubBub::Request.new("foo")
|
|
11
10
|
assert_equal "https://api.github.com/foo", request.url
|
|
12
|
-
request = GitHubBub::Request.new(
|
|
11
|
+
request = GitHubBub::Request.new("http://foo.com")
|
|
13
12
|
assert_equal "http://foo.com", request.url
|
|
14
|
-
request = GitHubBub::Request.new(
|
|
13
|
+
request = GitHubBub::Request.new("https://bar.com")
|
|
15
14
|
assert_equal "https://bar.com", request.url
|
|
16
|
-
request = GitHubBub::Request.new(
|
|
15
|
+
request = GitHubBub::Request.new("arthurnn/http")
|
|
17
16
|
assert_equal "https://api.github.com/arthurnn/http", request.url
|
|
18
|
-
request = GitHubBub::Request.new(
|
|
17
|
+
request = GitHubBub::Request.new("arthurnn/https")
|
|
19
18
|
assert_equal "https://api.github.com/arthurnn/https", request.url
|
|
20
19
|
end
|
|
21
20
|
|
|
22
21
|
def test_set_callback
|
|
23
|
-
request = GitHubBub::Request.new(
|
|
22
|
+
request = GitHubBub::Request.new("foo")
|
|
24
23
|
|
|
25
24
|
GitHubBub::Request.set_before_callback do |request|
|
|
26
|
-
request.url =
|
|
25
|
+
request.url = "bar"
|
|
27
26
|
end
|
|
28
27
|
|
|
29
28
|
request.before_callbacks!
|
|
30
29
|
|
|
31
|
-
assert_equal
|
|
30
|
+
assert_equal "bar", request.url
|
|
32
31
|
end
|
|
33
32
|
|
|
34
33
|
def test_token_parse
|
|
35
|
-
request = GitHubBub::Request.new(
|
|
34
|
+
request = GitHubBub::Request.new("foo", token: "foo", what: "yeah")
|
|
36
35
|
request.set_auth_from_token!
|
|
37
|
-
assert_equal "token foo", request.options[:headers][
|
|
36
|
+
assert_equal "token foo", request.options[:headers]["Authorization"]
|
|
38
37
|
assert_equal nil, request.options[:token]
|
|
39
38
|
end
|
|
40
39
|
|
|
41
40
|
def test_head_issues
|
|
42
|
-
VCR.use_cassette(
|
|
43
|
-
response = GitHubBub.head(
|
|
44
|
-
assert_equal "GitHub.com", response.headers[
|
|
41
|
+
VCR.use_cassette("HEAD rails/rails/issues") do
|
|
42
|
+
response = GitHubBub.head("/repos/rails/rails/issues")
|
|
43
|
+
assert_equal "GitHub.com", response.headers["Server"]
|
|
45
44
|
end
|
|
46
45
|
end
|
|
47
46
|
|
|
48
47
|
def test_get_issues
|
|
49
|
-
VCR.use_cassette(
|
|
50
|
-
response = GitHubBub.get(
|
|
51
|
-
assert_equal
|
|
48
|
+
VCR.use_cassette("GET rails/rails/issues") do
|
|
49
|
+
response = GitHubBub.get("/repos/rails/rails/issues")
|
|
50
|
+
assert_equal "https://api.github.com/repos/rails/rails/issues/10715", response.json_body.first["url"]
|
|
52
51
|
end
|
|
53
52
|
|
|
54
|
-
VCR.use_cassette(
|
|
55
|
-
response = GitHubBub.get(
|
|
56
|
-
assert_equal
|
|
53
|
+
VCR.use_cassette("GET rails/rails/issues?page=2") do
|
|
54
|
+
response = GitHubBub.get("/repos/rails/rails/issues", page: 2)
|
|
55
|
+
assert_equal "https://api.github.com/repos/rails/rails/issues/10664", response.json_body.first["url"]
|
|
57
56
|
end
|
|
58
57
|
end
|
|
59
58
|
|
|
60
59
|
def test_post_issues
|
|
61
|
-
VCR.use_cassette(
|
|
62
|
-
params = {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
response = GitHubBub.post("/repos/#{ENV[
|
|
66
|
-
assert_equal "https://api.github.com/repos/#{ENV[
|
|
67
|
-
assert_equal params[:title], response.json_body[
|
|
60
|
+
VCR.use_cassette("POST /:owner/:repo/issues") do
|
|
61
|
+
params = {title: "Testing",
|
|
62
|
+
body: "a gem called git_hub_bub",
|
|
63
|
+
token: ENV["GITHUB_API_KEY"]}
|
|
64
|
+
response = GitHubBub.post("/repos/#{ENV["OWNER"]}/#{ENV["REPO"]}/issues", params)
|
|
65
|
+
assert_equal "https://api.github.com/repos/#{ENV["OWNER"]}/#{ENV["REPO"]}/issues/77", response.json_body["url"]
|
|
66
|
+
assert_equal params[:title], response.json_body["title"]
|
|
68
67
|
end
|
|
69
68
|
end
|
|
70
69
|
|
|
71
70
|
def test_patch
|
|
72
|
-
VCR.use_cassette(
|
|
73
|
-
params = {
|
|
74
|
-
|
|
75
|
-
response = GitHubBub.post(
|
|
76
|
-
assert_equal params[:name], response.json_body[
|
|
77
|
-
assert_equal ENV[
|
|
71
|
+
VCR.use_cassette("PATCH user") do
|
|
72
|
+
params = {name: ENV["USER_NAME"],
|
|
73
|
+
token: ENV["GITHUB_API_KEY"]}
|
|
74
|
+
response = GitHubBub.post("user", params)
|
|
75
|
+
assert_equal params[:name], response.json_body["name"]
|
|
76
|
+
assert_equal ENV["OWNER"], response.json_body["login"]
|
|
78
77
|
end
|
|
79
78
|
end
|
|
80
79
|
|
|
81
80
|
# http://developer.github.com/v3/activity/watching/
|
|
82
81
|
def test_put
|
|
83
|
-
VCR.use_cassette(
|
|
82
|
+
VCR.use_cassette("PUT /repos/:owner/:repo/subscription") do
|
|
84
83
|
subscribed = true
|
|
85
|
-
ignored
|
|
86
|
-
response = GitHubBub.put("/repos/#{ENV[
|
|
84
|
+
ignored = false
|
|
85
|
+
response = GitHubBub.put("/repos/#{ENV["WATCH_OWNER"]}/#{ENV["WATCH_REPO"]}/subscription", subscribed: subscribed, ignored: ignored, token: ENV["GITHUB_API_KEY"])
|
|
87
86
|
assert_equal 200, response.status
|
|
88
|
-
assert_equal ignored, response.json_body[
|
|
89
|
-
assert_equal subscribed, response.json_body[
|
|
87
|
+
assert_equal ignored, response.json_body["ignored"]
|
|
88
|
+
assert_equal subscribed, response.json_body["subscribed"]
|
|
90
89
|
end
|
|
91
90
|
end
|
|
92
91
|
|
|
93
92
|
def test_delete
|
|
94
|
-
VCR.use_cassette(
|
|
95
|
-
name =
|
|
96
|
-
|
|
97
|
-
response = GitHubBub.delete("repos/#{ENV[
|
|
93
|
+
VCR.use_cassette("DELETE milestone") do
|
|
94
|
+
name = "test"
|
|
95
|
+
GitHubBub.post("repos/#{ENV["OWNER"]}/#{ENV["REPO"]}/labels", name: name, color: "FFFFFF", token: ENV["GITHUB_API_KEY"])
|
|
96
|
+
response = GitHubBub.delete("repos/#{ENV["OWNER"]}/#{ENV["REPO"]}/labels/#{name}", token: ENV["GITHUB_API_KEY"])
|
|
98
97
|
assert_equal 204, response.status
|
|
99
98
|
end
|
|
100
99
|
end
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
require
|
|
1
|
+
require "test_helper"
|
|
2
2
|
|
|
3
3
|
class ResponseTest < Test::Unit::TestCase
|
|
4
|
-
|
|
5
4
|
def test_pagination
|
|
6
5
|
response = GitHubBub::Response.new(rails_issues_data(:first))
|
|
7
|
-
assert_equal({"next_url"=>"https://api.github.com/repositories/8514/issues?page=2",
|
|
8
|
-
"last_url"=>"https://api.github.com/repositories/8514/issues?page=18"},
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
assert_equal({"next_url" => "https://api.github.com/repositories/8514/issues?page=2",
|
|
7
|
+
"last_url" => "https://api.github.com/repositories/8514/issues?page=18"},
|
|
8
|
+
response.pagination)
|
|
11
9
|
|
|
12
10
|
assert_equal "https://api.github.com/repositories/8514/issues?page=2", response.next_url
|
|
13
11
|
assert_equal "https://api.github.com/repositories/8514/issues?page=18", response.last_url
|
|
@@ -18,26 +16,25 @@ class ResponseTest < Test::Unit::TestCase
|
|
|
18
16
|
assert response.first_page?
|
|
19
17
|
|
|
20
18
|
response = GitHubBub::Response.new(rails_issues_data(:second))
|
|
21
|
-
assert_equal({"next_url"=>"https://api.github.com/repositories/8514/issues?page=3",
|
|
22
|
-
"last_url"=>"https://api.github.com/repositories/8514/issues?page=18",
|
|
23
|
-
"first_url"=>"https://api.github.com/repositories/8514/issues?page=1",
|
|
24
|
-
"prev_url"=>"https://api.github.com/repositories/8514/issues?page=1"},
|
|
25
|
-
|
|
19
|
+
assert_equal({"next_url" => "https://api.github.com/repositories/8514/issues?page=3",
|
|
20
|
+
"last_url" => "https://api.github.com/repositories/8514/issues?page=18",
|
|
21
|
+
"first_url" => "https://api.github.com/repositories/8514/issues?page=1",
|
|
22
|
+
"prev_url" => "https://api.github.com/repositories/8514/issues?page=1"},
|
|
23
|
+
response.pagination)
|
|
26
24
|
|
|
27
25
|
assert_equal "https://api.github.com/repositories/8514/issues?page=3", response.next_url
|
|
28
26
|
assert_equal "https://api.github.com/repositories/8514/issues?page=18", response.last_url
|
|
29
27
|
assert_equal "https://api.github.com/repositories/8514/issues?page=1", response.prev_url
|
|
30
28
|
assert_equal "https://api.github.com/repositories/8514/issues?page=1", response.first_url
|
|
31
29
|
|
|
32
|
-
|
|
33
30
|
refute response.last_page?
|
|
34
31
|
refute response.first_page?
|
|
35
32
|
|
|
36
33
|
response = GitHubBub::Response.new(rails_issues_data(:last))
|
|
37
|
-
assert_equal({"last_url"=>"https://api.github.com/repositories/8514/issues?page=1",
|
|
38
|
-
"first_url"=>"https://api.github.com/repositories/8514/issues?page=1",
|
|
39
|
-
"prev_url"=>"https://api.github.com/repositories/8514/issues?page=17"},
|
|
40
|
-
|
|
34
|
+
assert_equal({"last_url" => "https://api.github.com/repositories/8514/issues?page=1",
|
|
35
|
+
"first_url" => "https://api.github.com/repositories/8514/issues?page=1",
|
|
36
|
+
"prev_url" => "https://api.github.com/repositories/8514/issues?page=17"},
|
|
37
|
+
response.pagination)
|
|
41
38
|
|
|
42
39
|
assert_equal nil, response.next_url
|
|
43
40
|
assert_equal "https://api.github.com/repositories/8514/issues?page=1", response.last_url
|
|
@@ -60,12 +57,31 @@ class ResponseTest < Test::Unit::TestCase
|
|
|
60
57
|
assert_equal 0, response.rate_limit_reset_time_left
|
|
61
58
|
end
|
|
62
59
|
|
|
63
|
-
Timecop.freeze(Time.at(epoch_time - 2
|
|
60
|
+
Timecop.freeze(Time.at(epoch_time - 2).to_datetime) do
|
|
64
61
|
response = GitHubBub::Response.new(rails_issues_data(:last))
|
|
65
62
|
assert_equal 2, response.rate_limit_reset_time_left
|
|
66
63
|
end
|
|
67
64
|
end
|
|
68
65
|
|
|
66
|
+
def test_last_page_with_next_but_no_last_url
|
|
67
|
+
# This reproduces a real response from the GitHub API where the Link header
|
|
68
|
+
# only contains rel="next" but no rel="last"
|
|
69
|
+
data = {
|
|
70
|
+
body: "[{\"url\":\"https://api.github.com/repos/puma/puma/issues/3643\"}]",
|
|
71
|
+
headers: {
|
|
72
|
+
"Link" => "<https://api.github.com/repositories/2441517/issues?direction=desc&page=2&sort=comments&state=open&after=Y3Vyc29yOnYyOpIIzpU4Fek%3D&per_page=30>; rel=\"next\""
|
|
73
|
+
},
|
|
74
|
+
status: 200
|
|
75
|
+
}
|
|
76
|
+
response = GitHubBub::Response.new(data)
|
|
77
|
+
|
|
78
|
+
assert_equal "https://api.github.com/repositories/2441517/issues?direction=desc&page=2&sort=comments&state=open&after=Y3Vyc29yOnYyOpIIzpU4Fek%3D&per_page=30",
|
|
79
|
+
response.next_url
|
|
80
|
+
assert_nil response.last_url
|
|
81
|
+
|
|
82
|
+
refute response.last_page?
|
|
83
|
+
end
|
|
84
|
+
|
|
69
85
|
def test_rate_limit_sleep
|
|
70
86
|
epoch_time = 1504196685
|
|
71
87
|
|
|
@@ -99,7 +115,7 @@ class ResponseTest < Test::Unit::TestCase
|
|
|
99
115
|
Timecop.freeze(Time.at(epoch_time - 1).to_datetime) do
|
|
100
116
|
response = GitHubBub::Response.new(rails_issues_data(:last))
|
|
101
117
|
response.headers["X-RateLimit-Limit"] = "10"
|
|
102
|
-
assert_equal 1.0/10, response.rate_limit_sleep!(bypass_sleep: true)
|
|
118
|
+
assert_equal 1.0 / 10, response.rate_limit_sleep!(bypass_sleep: true)
|
|
103
119
|
end
|
|
104
120
|
end
|
|
105
121
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require "test_helper"
|
|
2
2
|
|
|
3
3
|
class ValidTokenTest < Test::Unit::TestCase
|
|
4
4
|
include WebMock::API
|
|
@@ -8,14 +8,23 @@ class ValidTokenTest < Test::Unit::TestCase
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def test_does_not_add_token_to_header
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
# Disable VCR so WebMock's stub_request can handle the request directly
|
|
12
|
+
VCR.turned_off do
|
|
13
|
+
token = "foo"
|
|
14
|
+
url = "https://api.github.com/applications/#{ENV["GITHUB_APP_ID"]}/tokens/#{token}"
|
|
15
|
+
# Add a basic auth header, will fail if `'Authorization'=>'token ...'` header is added by mistake
|
|
16
|
+
stub_get = stub_request(:get, url).with(basic_auth: [ENV["GITHUB_APP_ID"], ENV["GITHUB_APP_SECRET"]])
|
|
14
17
|
|
|
15
|
-
|
|
18
|
+
GitHubBub::Request.set_before_callback do |request|
|
|
19
|
+
if request.token?
|
|
20
|
+
# Should be true for this call
|
|
21
|
+
else
|
|
22
|
+
raise "nope"
|
|
23
|
+
end
|
|
24
|
+
end
|
|
16
25
|
|
|
17
|
-
|
|
18
|
-
|
|
26
|
+
GitHubBub.valid_token?(token)
|
|
27
|
+
assert_requested stub_get
|
|
28
|
+
end
|
|
19
29
|
end
|
|
20
|
-
|
|
21
30
|
end
|