Files
vercel/api/_lib/examples/gitlab-repo-info.ts
Andy 890de6a625 Add API for frameworks and examples (#3514)
* 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>
2020-01-07 23:55:39 +01:00

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,
};
}