Skip to content

Commit 6aafe7b

Browse files
committed
Allow to use access_token for private content.
1 parent c8340e6 commit 6aafe7b

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

lib/nanoc/github.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def items
2323
private
2424

2525
def client
26-
Octokit::Client.new
26+
Octokit::Client.new(access_token: access_token)
2727
end
2828

2929
def decode(content)
@@ -43,6 +43,10 @@ def repository_items
4343
[]
4444
end
4545

46+
def access_token
47+
@config[:access_token]
48+
end
49+
4650
def path
4751
@config[:path]
4852
end

test/source_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ def flat_source
3333
})
3434
end
3535

36+
def source_with_token
37+
Source.new(site_config, nil, nil, {
38+
repository: "pawelpacana/test-source",
39+
path: "posts",
40+
access_token: "secret123"
41+
})
42+
end
43+
3644
def test_identifier
3745
assert_equal :github, source_with_posts.class.identifier
3846
end
@@ -105,6 +113,13 @@ def test_utf8
105113
EOC
106114
end
107115
end
116+
117+
def test_use_access_token
118+
stub_request(:get, "https://api.github.com/repos/pawelpacana/test-source/contents/posts")
119+
.with(headers: { "Authorization" => "token secret123" })
120+
.to_return(status: 404)
121+
source_with_token.items
122+
end
108123
end
109124
end
110125
end

test/test_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
require_relative "../lib/nanoc/github"
22
require "minitest/autorun"
3+
require "webmock/minitest"
34
require "vcr"
45

6+
57
VCR.configure do |config|
68
config.cassette_library_dir = "test/fixtures"
79
config.hook_into :webmock

0 commit comments

Comments
 (0)