Skip to content

Commit

Permalink
Fixes opentofu/opentofu#1131: Provide releases page
Browse files Browse the repository at this point in the history
  • Loading branch information
Janos Bonic committed Jan 16, 2024
1 parent c3963f6 commit 1996ec4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/functions/releases.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type {PagesFunction} from "@cloudflare/workers-types";

interface Env {
}

export const onRequest: PagesFunction<Env> = async (context) => {
const data = JSON.parse(await fetch("https://api.github.com/repos/opentofu/opentofu/releases"))

const listItems = data.map(data => {
const li = document.createElement("li")
const a = document.createElement("a")
li.appendChild(a)
a.href = data.name.replace("v", "")
a.innerText = data.name.replace("v", "")
return li.outerHTML
})

return new Response('<!DOCTYPE html><html><head></head><body><ul>' + listItems.join() + '</ul></body></html>', {
status: 200,
headers: {
'content-type': 'text/html; charset=utf-8',
},
});
}
18 changes: 18 additions & 0 deletions src/functions/releases/[release].ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type {PagesFunction} from "@cloudflare/workers-types";

interface Env {
}

export const onRequest: PagesFunction<Env> = async (context) => {
const response = await fetch("https://api.github.com/repos/opentofu/opentofu/releases/tags/v" + encodeURIComponent(context.params.release), {headers: {"User-Agent": "OpenTofu Releases Page"}})
const data = await response.json()

const listItems = data.assets.map(asset => `<li><a href="${asset.browser_download_url}">${asset.name}</a></li>`)

return new Response('<!DOCTYPE html><html><head><title>OpenTofu releases</title></head><body><ul><li><a href="/releases/">../</a></li>' + listItems.join() + '</ul></body></html>', {
status: 200,
headers: {
'content-type': 'text/html; charset=utf-8',
},
});
}

0 comments on commit 1996ec4

Please sign in to comment.