simple-deno-import-gitea/gitea.ts

37 lines
1.4 KiB
TypeScript
Raw Normal View History

2023-03-24 01:40:08 +09:00
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) {
2023-06-12 10:35:43 +09:00
const results = await searchRepositoryWithTopic("denolib");
2023-03-24 01:40:08 +09:00
console.log(results.data?.map((repo) => repo.full_name));
const s = await getRepositoryContent("monoid", "script", "", "");
console.log((s as ContentsResponse[]).map((x) => x.name));
2023-06-12 10:35:43 +09:00
}