48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
"use server";
|
|
|
|
import { getInstallationAccessToken } from "./installation";
|
|
|
|
export type GithubRepository = {
|
|
id: number;
|
|
name: string;
|
|
full_name: string;
|
|
owner: {
|
|
login: string;
|
|
id: number;
|
|
type: string;
|
|
};
|
|
private: boolean;
|
|
html_url: string;
|
|
description: string;
|
|
fork: boolean;
|
|
url: string;
|
|
created_at: string;
|
|
updated_at: string;
|
|
pushed_at: string;
|
|
homepage: string;
|
|
size: number;
|
|
stargazers_count: number;
|
|
watchers_count: number;
|
|
language: string;
|
|
forks_count: number;
|
|
open_issues_count: number;
|
|
default_branch: string;
|
|
permissions: {
|
|
admin: boolean;
|
|
push: boolean;
|
|
pull: boolean;
|
|
};
|
|
};
|
|
|
|
export async function getUserRepository(userId: string, username: string): Promise<GithubRepository[]> {
|
|
const repositories = await fetch('https://api.github.com/installation/repositories', {
|
|
headers: {
|
|
Authorization: `Bearer ${await getInstallationAccessToken(userId, username)}`,
|
|
Accept: "application/vnd.github+json",
|
|
"X-GitHub-Api-Version": "2022-11-28",
|
|
},
|
|
method: 'GET',
|
|
}).then(res => res.json());
|
|
|
|
return repositories.repositories as GithubRepository[];
|
|
} |