From cda1d0dc8f178affe0fcf240790ba4cb933bb4e8 Mon Sep 17 00:00:00 2001 From: xiongxiao Date: Fri, 13 Mar 2026 03:21:26 +0800 Subject: [PATCH] test --- package.json | 8 ++++---- readme.md | 1 + src/issue/index.ts | 4 ++-- src/repo/index.ts | 15 ++++++++++++++- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index c48b37c..22103b2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/cnb", - "version": "0.0.41", + "version": "0.0.43", "description": "", "main": "index.js", "basename": "/root/cnb", @@ -17,8 +17,8 @@ }, "keywords": [], "bin": { - "cnb": "./bin/index.js", - "cloud": "./bin/index.js" + "cnb": "bin/index.js", + "cloud": "bin/index.js" }, "files": [ "dist", @@ -74,4 +74,4 @@ "./src/*": "./src/*", "./agent/*": "./agent/*" } -} \ No newline at end of file +} diff --git a/readme.md b/readme.md index 587810d..255bc71 100644 --- a/readme.md +++ b/readme.md @@ -1,5 +1,6 @@ # cnb.cool 能做什么 +所有的代码仓库,只基于一个准则 `group/repo` ## 简介 纯粹调用api的模式去使用cnb.cool,自动化方案。 diff --git a/src/issue/index.ts b/src/issue/index.ts index bb34878..b35a65d 100644 --- a/src/issue/index.ts +++ b/src/issue/index.ts @@ -73,14 +73,14 @@ export class Issue extends CNBCore { super(options); } - createIssue(repo: string, data: Partial): Promise { + createIssue(repo: string, data: Partial): Promise> { const url = `/${repo}/-/issues`; let postData = { ...data, }; return this.post({ url, data: postData }); } - updateIssue(repo: string, issueNumber: string | number, data: Partial): Promise { + updateIssue(repo: string, issueNumber: string | number, data: Partial): Promise> { const url = `/${repo}/-/issues/${issueNumber}`; let postData = { ...data, diff --git a/src/repo/index.ts b/src/repo/index.ts index ca8b22d..f2eb0fe 100644 --- a/src/repo/index.ts +++ b/src/repo/index.ts @@ -1,5 +1,5 @@ import { CNBCore, CNBCoreOptions, RequestOptions, Result } from "../cnb-core.ts"; - +import dayjs from "dayjs"; export class Repo extends CNBCore { constructor(options: CNBCoreOptions) { super(options); @@ -30,6 +30,12 @@ export class Repo extends CNBCore { const url = `/${repo}`; return this.delete({ url }); } + /** + * 使用cookie创建提交,如果没有指定parent_commit_sha,则会自动获取最新的提交作为父提交 + * @param repo + * @param data + * @returns + */ async createCommit(repo: string, data: CreateCommitData): Promise { const commitList = await this.getCommitList(repo, { page: 1, @@ -41,6 +47,12 @@ export class Repo extends CNBCore { const preCommitSha = commitList.length > 0 ? commitList[0].sha : undefined; if (!data.parent_commit_sha && preCommitSha) { data.parent_commit_sha = preCommitSha; + } else if (data.parent_commit_sha) { + // 如果指定了parent_commi_sha; + if (!data.new_branch) { + const date = dayjs().format('MMDDHHmm'); + data.new_branch = `refs/heads/${date}`; + } } const url = `${this.hackURL}/${repo}/-/git/commits`; const postData: CreateCommitData = { @@ -52,6 +64,7 @@ export class Repo extends CNBCore { new_branch: data.new_branch || 'refs/heads/main', }; if (!postData.parent_commit_sha) { + // 如果没有父提交sha,则说明是第一次提交,可以删除parent_commit_sha和base_branch字段 delete postData.parent_commit_sha; delete postData.base_branch; }