Multi-session
Mix.install([
{:req, "~> 0.3.10"},
{:kino, "~> 0.10.0"}
])
Section
gh =
Req.new(
base_url: "https://api.github.com",
auth: {:bearer, System.fetch_env!("LB_GITHUB_TOKEN")},
headers: [
{"Accept", "application/vnd.github+json"},
{"X-GitHub-API-Version", "2022-11-28"}
]
)
Kino.nothing()
repo =
"OWNER/REPO"
|> Kino.Input.text()
|> Kino.render()
|> Kino.Input.read()
if not String.contains?(repo, "/") do
Kino.interrupt!(:normal, "Please enter your OWNER/REPO")
end
case Req.get!(gh, url: "repos/#{repo}/security-advisories") do
%{status: 200, body: body} ->
"You got #{length(body)} reports"
%{status: 404} ->
Kino.interrupt!(:error, "Repo #{repo} does not exist")
%{status: status} ->
Kino.interrupt!(:error, "Failed with status #{status}")
end