mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-06 12:57:46 +00:00
* Add API for frameworks and examples * Adjust headers * Update frameworks list * Always use latest * Add types * Use now repo for downloading and listing * Use .existsSync * Remove unused packages * Use 307 for redirect * Add examples * Update tsconfig.json Co-Authored-By: Steven <steven@ceriously.com> * Make examples unique * Remove detectors from frameworks API * Use /api instead of Next.js * Install dependencies * Rename project * Change name * Empty * Change name * Update api/tsconfig.json Co-Authored-By: Steven <steven@ceriously.com> * Update examples Co-authored-by: Steven <steven@ceriously.com>
46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
import fetch from 'node-fetch';
|
|
|
|
interface Repo {
|
|
repo: string;
|
|
owner: {
|
|
username: string;
|
|
};
|
|
username: string;
|
|
branch: string;
|
|
}
|
|
|
|
/**
|
|
* Fetch the meta info of a public gitlab repo
|
|
* @param {object} repo parsed by the `parse-github-url` package
|
|
*/
|
|
export async function getGitLabRepoInfo(repo: Repo) {
|
|
const response = await fetch(
|
|
`https://gitlab.com/api/v4/projects/${encodeURIComponent(repo.repo)}`
|
|
);
|
|
|
|
if (response.status !== 200) {
|
|
console.log(`Non-200 response code from GitLab: ${response.status}`);
|
|
return null;
|
|
}
|
|
|
|
const parsed = await response.json();
|
|
if (parsed.path_with_namespace !== repo.repo) {
|
|
console.log(`Invalid response from GitLab`);
|
|
return null;
|
|
}
|
|
|
|
return {
|
|
id: parsed.path_with_namespace,
|
|
name: parsed.path,
|
|
url: parsed.web_url,
|
|
owner: parsed.owner ? parsed.owner.username : repo.owner,
|
|
description: parsed.description,
|
|
homepage: null,
|
|
size: 0,
|
|
createdAt: parsed.created_at,
|
|
updatedAt: parsed.last_activity_at,
|
|
stars: parsed.star_count,
|
|
branch: repo.branch,
|
|
};
|
|
}
|