simple-deno-import-gitea/gitea.ts

36 lines
1.3 KiB
TypeScript

import { SearchResults, Tag, ContentsResponse } from "./gitea_api.d.ts";
const ENDPOINT_URL = "https://git.prelude.duckdns.org/api/v1/";
export async function searchRepositoryWithTopic(topic: string): Promise<SearchResults> {
const url = new URL(ENDPOINT_URL+ "repos/search");
url.searchParams.append("q", topic);
url.searchParams.append("topic", "true");
const response = await fetch(url);
const data = await response.json();
return data;
}
export async function getRepositoryTags(owner:string,
repo:string): Promise<Tag[]>{
const url = new URL(ENDPOINT_URL+ "repos/"+owner+"/"+repo+"/tags");
const response = await fetch(url);
const data = await response.json();
return data;
}
export async function getRepositoryContent(owner:string,
repo:string, path:string, ref:string): Promise<ContentsResponse[] | ContentsResponse>{
const url = new URL(ENDPOINT_URL+ "repos/"+owner+"/"+repo+"/contents/"+path);
url.searchParams.append("ref", ref);
const response = await fetch(url);
const data = await response.json();
return data;
}
if (import.meta.main) {
const results = await searchRepositoryWithTopic("deno");
console.log(results.data?.map((repo) => repo.full_name));
const s = await getRepositoryContent("monoid", "script", "", "");
console.log((s as ContentsResponse[]).map((x) => x.name));
}