更新代码仓库相关功能,修改 API 参数,添加删除仓库功能,更新文档和测试用例
This commit is contained in:
@@ -9,7 +9,6 @@ import { Mission } from "./mission/index.ts";
|
||||
import { AiBase } from "./ai/index.ts";
|
||||
|
||||
type CNBOptions = CNBCoreOptions<{
|
||||
group?: string;
|
||||
}>;
|
||||
|
||||
export class CNB extends CNBCore {
|
||||
@@ -21,7 +20,6 @@ export class CNB extends CNBCore {
|
||||
issue!: Issue;
|
||||
mission!: Mission;
|
||||
ai!: AiBase;
|
||||
group!: string;
|
||||
constructor(options: CNBOptions) {
|
||||
super({ token: options.token, cookie: options.cookie, cnb: options.cnb });
|
||||
this.init(options);
|
||||
|
||||
@@ -6,27 +6,32 @@ export class Repo extends CNBCore {
|
||||
}
|
||||
/**
|
||||
* 创建代码仓库
|
||||
* @param group e.g. my-group
|
||||
* @param data
|
||||
* @returns
|
||||
*/
|
||||
createRepo(group: string, data: CreateRepoData): Promise<any> {
|
||||
createRepo(data: CreateRepoData): Promise<any> {
|
||||
const name = data.name;
|
||||
const [group, repo] = name.includes('/') ? name.split('/') : ['', name];
|
||||
const url = `/${group}/-/repos`;
|
||||
let postData: CreateRepoData = {
|
||||
...data,
|
||||
description: data.description || '',
|
||||
name: data.name,
|
||||
name: repo,
|
||||
license: data.license || 'Unlicense',
|
||||
visibility: data.visibility || 'private',
|
||||
};
|
||||
return this.post({ url, data: postData });
|
||||
}
|
||||
deleteRepo(name: string): Promise<any> {
|
||||
const url = `https://cnb.cool/${name}`;
|
||||
return this.delete({ url, useCookie: true });
|
||||
}
|
||||
async createCommit(repo: string, data: CreateCommitData): Promise<any> {
|
||||
const commitList = await this.getCommitList(repo, {
|
||||
page: 1,
|
||||
page_size: 1,
|
||||
}, { useOrigin: true }).catch((err) => {
|
||||
console.error("Error fetching commit list:", err);
|
||||
// console.error("Error fetching commit list:", err);
|
||||
return []
|
||||
});
|
||||
const preCommitSha = commitList.length > 0 ? commitList[0].sha : undefined;
|
||||
@@ -46,7 +51,14 @@ export class Repo extends CNBCore {
|
||||
delete postData.parent_commit_sha;
|
||||
delete postData.base_branch;
|
||||
}
|
||||
return this.post({ url, data: postData, useCookie: true, });
|
||||
return this.post({
|
||||
url,
|
||||
data: postData,
|
||||
useCookie: true,
|
||||
headers: {
|
||||
'Accept': 'application/vnd.cnb.web+json',
|
||||
}
|
||||
});
|
||||
}
|
||||
createBlobs(repo: string, data: { content: string, encoding?: 'utf-8' | 'base64' }): Promise<any> {
|
||||
const url = `/${repo}/-/git/blobs`;
|
||||
|
||||
Reference in New Issue
Block a user