Skip to content

Commit

Permalink
Fix private URLs after previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
oprypin committed Aug 9, 2023
1 parent 70081b0 commit a6e57fc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions spec/main_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe "index" do
describe kind do
test "workflow" do
resp, body = serve("#{prefix}/oprypin/nightly.link/blob/master/.github/workflows/upload-test.yml")
assert_redirect "/oprypin/nightly.link/workflows/upload-test/master"
assert_redirect "/oprypin/nightly.link/workflows/upload-test/master?preview"
end

test "artifact_download" do
Expand All @@ -108,13 +108,13 @@ describe "index" do

test "unicode url" do
resp, body = serve("/?url=" + URI.encode_www_form("https://github.com/oprypin/nightly.link/blob/%D1%82%D0%B5%D1%81%D1%82/.github/workflows/build.yml"))
assert_redirect "/oprypin/nightly.link/workflows/build/%D1%82%D0%B5%D1%81%D1%82"
assert_redirect "/oprypin/nightly.link/workflows/build/%D1%82%D0%B5%D1%81%D1%82?preview"
end

test "private" do
url = URI.encode_www_form("https://github.com/#{PRIVATE_REPO}/blob/SomeBranch/.github/workflows/SomeWorkflow.yml")
resp, body = serve("/?url=#{url}&h=6c9bf24563d1896f5de321ce6043413f8c75ef16")
assert_redirect "/#{PRIVATE_REPO}/workflows/SomeWorkflow/SomeBranch?h=6c9bf24563d1896f5de321ce6043413f8c75ef16"
assert_redirect "/#{PRIVATE_REPO}/workflows/SomeWorkflow/SomeBranch?preview&h=6c9bf24563d1896f5de321ce6043413f8c75ef16"
end

test "bad url" do
Expand Down
4 changes: 3 additions & 1 deletion src/nightly_link.cr
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ class NightlyLink
when Retour::NotFound
messages << "Did not detect a link to a GitHub workflow file, actions run, or artifact." << gh_path
else
new_path += "?h=#{h}" if h
if h
new_path += new_path.ends_with?("?preview") ? "&h=#{h}" : "?h=#{h}"
end
raise HTTPException.redirect(new_path)
end
end
Expand Down

0 comments on commit a6e57fc

Please sign in to comment.