A Typescript library to access Forgejo via its api
closes #1 Reviewed-on: #2 Co-authored-by: Maxim Slipenko <maks1ms@altlinux.org> Co-committed-by: Maxim Slipenko <maks1ms@altlinux.org> |
||
---|---|---|
.woodpecker | ||
contrib | ||
src | ||
.env.example | ||
.gitignore | ||
.prettierignore | ||
.prettierrc.js | ||
.releaserc.json | ||
LICENSE | ||
package.json | ||
pnpm-lock.yaml | ||
README.md | ||
tsconfig.json | ||
vite.config.ts |
Forgejo-js api client with Typescript support
Forgejo-js is an api client automatically created from the official OpenAPI definition of Forgejo. The client uses the Fetch Api (native browser support) to make requests. For node you can use cross-fetch to polyfill the Fetch Api.
For Gitea you can use gitea-js.
Version mapping
The major and minor version of this library is mapped to the version of the Forgejo api. The patch version of this library is incremented for every release and uses the latest patch version of Forgejo.
Forgejo-js | Forgejo |
---|---|
11.0.x | 11.0 |
9.0.x | 9.0 |
Examples
Browser
import { forgejoApi } from 'forgejo-js';
const api = forgejoApi('https://codeberg.org/', {
token: 'access-token', // generate one at https://forgejo.example.com/user/settings/applications
});
const repo = api.repos.repoGet('anbraten', 'forgejo-js');
console.log(repo);
Node.js
const { forgejoApi } = require('forgejo-js');
const fetch = require('cross-fetch'); // You have to use a fetch compatible polyfill like cross-fetch for older Node.JS versions
const api = forgejoApi('https://codeberg.org/', {
token: 'access-token', // generate one at https://forgejo.example.com/user/settings/applications
customFetch: fetch,
});
const repo = api.repos.repoGet('anbraten', 'forgejo-js');
console.log(repo);