@vdmdi/bridge
v1.0.0
Published
This module provides an API for gitea.
Readme
Gitea Bridge
This module provides an API for gitea.
Capabilities
- sign in, generate a token
- make requests using the token
- create, modify, delete, and read files
Notes
This module is designed for workflows with one organisation holding data for every app, where every app has its own repository. The default org name is AppData. An app called hello-world would thus use /AppData/hello-world. Compliance with this standard is not mandatory.
Usage
import * as Bridge from "@vdmdi/bridge";
const old_token: string; //token stored from previous login
const gitea = new Bridge.API("my-app-name", old_token, "AppData"); //AppData is the default value for the data organisation
// sign in
const ok = await gitea.signIn("john", "password");
if (ok == true) console.log(gitea.token); // get token
// fetch
const response = await gitea.fetch("repos/john/some-repo/issues", "get");
const response = await gitea.fetch("repos/john/some-repo/issues", "post", {
title: "Some Ticket",
});
// files
await gitea.createFile({
// manually create file object
ownner: "john",
repo: "some-repo",
path: "path/to/file.txt",
content: "Hello, world!",
});
await gitea.createFile(
// use "AppData/my-app-name"
gitea.generateFileObject("path/to/file.txt")
);
const receivedFile: Bridge.FileWithSha = await gitea.readFile({
gitea.generateFileObject("path/to/file.txt")
});
await gitea.updateFile({
...receivedFile,
content: "New Content"
});
await gitea.deleteFile(receivedFile);