update
This commit is contained in:
2
.cnb.yml
2
.cnb.yml
@@ -2,7 +2,7 @@
|
||||
$:
|
||||
vscode:
|
||||
- docker:
|
||||
image: docker.cnb.cool/kevisual/node24:latest
|
||||
image: docker.cnb.cool/kevisual/dev-env:latest
|
||||
services:
|
||||
- vscode
|
||||
- docker
|
||||
|
||||
23
src/ai/index.ts
Normal file
23
src/ai/index.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { CNBCore, CNBCoreOptions, RequestOptions, Result } from "../cnb-core.ts";
|
||||
type AiOptions = CNBCoreOptions<{
|
||||
group?: string;
|
||||
}>
|
||||
class AiBase extends CNBCore {
|
||||
group: string;
|
||||
constructor(options: AiOptions) {
|
||||
super({ token: options.token, cookie: options.cookie });
|
||||
this.group = options.group || '';
|
||||
}
|
||||
autoPr(repo: string, data: { body: string, branch?: string, title: string }): Promise<Result<any>> {
|
||||
const group = this.group || '';
|
||||
const url = `/${group}/${repo}/-/build/ai/auto-pr`;
|
||||
const postData = {
|
||||
...data,
|
||||
branch: data.branch || 'refs/heads/main',
|
||||
title: data.title || ''
|
||||
};
|
||||
return this.post({ url, data: postData });
|
||||
}
|
||||
}
|
||||
|
||||
export { AiBase };
|
||||
@@ -16,4 +16,40 @@ export class User extends CNBCore {
|
||||
useCookie: true,
|
||||
});
|
||||
}
|
||||
createAccessToken(data?: { description?: string, scope?: string }): Promise<AccessTokenResponse> {
|
||||
const scope = data?.scope || 'mission-manage:rw,mission-delete:rw,group-delete:rw,group-manage:rw,group-resource:rw,account-engage:rw,account-email:r,account-profile:rw,registry-delete:rw,registry-manage:rw,registry-package-delete:rw,registry-package:rw,repo-security:r,repo-delete:rw,repo-manage:rw,repo-basic-info:r,repo-cnb-detail:rw,repo-cnb-history:r,repo-cnb-trigger:rw,repo-commit-status:rw,repo-contents:rw,repo-notes:rw,repo-issue:rw,repo-pr:rw,repo-code:rw'
|
||||
const url = 'https://cnb.cool/user/personal_access_tokens'
|
||||
return this.post({
|
||||
url,
|
||||
useCookie: true,
|
||||
data: {
|
||||
description: data?.description || 'Created at ' + new Date().toISOString(),
|
||||
scope: scope,
|
||||
}
|
||||
})
|
||||
}
|
||||
getAccessTokens(params?: { page?: number, page_size?: number }): Promise<AccessTokenResponse[]> {
|
||||
const url = 'https://cnb.cool/user/personal_access_tokens'
|
||||
return this.get({
|
||||
url,
|
||||
useCookie: true,
|
||||
params: {
|
||||
...params,
|
||||
page: params?.page || 1,
|
||||
page_size: params?.page_size || 20,
|
||||
}
|
||||
})
|
||||
}
|
||||
deleteAccessToken(tokenId: string): Promise<any> {
|
||||
const url = `https://cnb.cool/user/personal_access_tokens/${tokenId}`
|
||||
return this.delete({
|
||||
url,
|
||||
useCookie: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
type AccessTokenResponse = {
|
||||
token: string;
|
||||
description: string;
|
||||
}
|
||||
12
test/ai.ts
Normal file
12
test/ai.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { AiBase } from "../src/ai/index.ts";
|
||||
|
||||
import { token, showMore, cookie } from "./common.ts";
|
||||
|
||||
const repo = new AiBase({ group: "kevisual/demo", token: token, cookie: cookie });
|
||||
|
||||
const res = await repo.autoPr("test-cnb", {
|
||||
body: "请帮我给README文件添加一句问候语",
|
||||
title: "给README添加问候语",
|
||||
});
|
||||
|
||||
console.log("res", showMore(res));
|
||||
@@ -4,7 +4,6 @@ import util from 'node:util';
|
||||
dotenv.config();
|
||||
export const token = process.env.CNB_TOKEN || "";
|
||||
export const cookie = process.env.CNB_COOKIE || "";
|
||||
console.log("Using CNB_TOKEN:", token.slice(0, 4) + "****", cookie);
|
||||
export const cnb = new CNB({ token, cookie });
|
||||
export const showMore = (obj: any) => {
|
||||
return util.inspect(obj, { showHidden: false, depth: null, colors: true });
|
||||
|
||||
@@ -7,3 +7,7 @@ const user = new User({ token: token, cookie: cookie });
|
||||
const currentUser = await user.getCurrentUser();
|
||||
|
||||
console.log("currentUser", showMore(currentUser));
|
||||
|
||||
// const accessToken = await user.createAccessToken({ description: "Test Token from API" });
|
||||
|
||||
// console.log("accessToken", showMore(accessToken));
|
||||
Reference in New Issue
Block a user