add basic github api

This commit is contained in:
2025-10-10 23:48:52 +02:00
parent e6a57a49f1
commit 8d11965724
3 changed files with 1830 additions and 2 deletions

1790
schafkopf-os/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -2,3 +2,8 @@
name = "schafkopf-os"
version = "0.1.0"
edition = "2024"
[dependencies]
tokio = { version = "1", features = ["full"] }
octocrab = { version = "0.47"}
axum = "0.8.6"

View File

@@ -1,3 +1,36 @@
fn main() {
println!("Hello, world!");
use octocrab::{Octocrab, Result};
use axum::{
routing::{get},
http::StatusCode,
Json, Router,
};
#[tokio::main]
async fn main() -> Result<()> {
// build our application with a route
let app: Router = Router::new()
// `GET /` goes to `root`
.route("/", get(root));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
Ok(())
}
async fn root() -> Result<Json<Vec<String>>, StatusCode> {
let gh = Octocrab::builder().build().map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
let owner = "Vale54321";
let repo = "schafkop-neu";
let mut tags: Vec<String> = vec![];
let page = gh.repos(owner, repo).releases().list().per_page(100).send().await.map_err(|_| StatusCode::BAD_GATEWAY)?;
for release in &page.items {
tags.push(release.tag_name.clone());
}
Ok(Json(tags))
}