feat: 添加 Repo 和 User 模块,增强 CNBCore 功能
This commit is contained in:
69
test/create-repo.ts
Normal file
69
test/create-repo.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { Repo } from "../src/repo";
|
||||
|
||||
import { token, showMore, cookie } from "./common.ts";
|
||||
|
||||
const repo = new Repo({ group: "kevisual/demo", token: token, cookie: cookie });
|
||||
|
||||
// const res = await repo.createRepo({
|
||||
// name: "test-cnb-2",
|
||||
// description: "This is my new repository",
|
||||
// visibility: "private",
|
||||
// license: 'MIT',
|
||||
// });
|
||||
|
||||
// console.log("res", showMore(res));
|
||||
|
||||
const repoName = "test-cnb";
|
||||
// const commitList = await repo.getCommitList(repoName, {
|
||||
// page: 1,
|
||||
// page_size: 1,
|
||||
// }).catch((err) => {
|
||||
// console.error("Error fetching commit list:", err);
|
||||
// return []
|
||||
// });
|
||||
// console.log("commitList", showMore(commitList));
|
||||
|
||||
// const preCommitSha = commitList.length > 0 ? commitList[0].sha : undefined;
|
||||
|
||||
const commitRes = await repo.createCommit(repoName, {
|
||||
message: "Initial commit3",
|
||||
files: [
|
||||
{ path: "README.md", content: "# Hello World\nThis is my first commit!", encoding: 'raw' },
|
||||
{ path: "a.md", content: "# Hello World\nThis is my first commit2!", encoding: 'raw' },
|
||||
],
|
||||
});
|
||||
|
||||
console.log("commitRes", showMore(commitRes));
|
||||
|
||||
|
||||
|
||||
// const blobRes = await repo.createBlobs(repoName, {
|
||||
// content: Buffer.from("Hello, CNB!").toString("base64"),
|
||||
// encoding: "base64",
|
||||
// });
|
||||
|
||||
// console.log("blobRes", showMore(blobRes));
|
||||
// sha: 4b909f74428c24221a9f795c591f5eb560817f2d
|
||||
|
||||
// const bufferText = Buffer.from("This is a sample file content. 232332");
|
||||
// const bufferSize = Buffer.byteLength(bufferText);
|
||||
// console.log("bufferSize", bufferSize);
|
||||
// const uploadRes = await repo.uploadFiles(repoName, {
|
||||
// name: "sample.txt",
|
||||
// ext: { "a": "b" },
|
||||
// size: Buffer.byteLength(bufferText),
|
||||
// });
|
||||
|
||||
// console.log("uploadRes", showMore(uploadRes));
|
||||
|
||||
// const upload_url = uploadRes.upload_url
|
||||
// const upload_token = uploadRes.token;
|
||||
|
||||
|
||||
// const uploadResponse = await repo.putFile({
|
||||
// url: upload_url,
|
||||
// token: upload_token,
|
||||
// content: bufferText,
|
||||
// });
|
||||
|
||||
// console.log("uploadResponse", showMore(uploadResponse));
|
||||
Reference in New Issue
Block a user