@candriajs/karin-plugin-git 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +23 -2
  3. package/config/defSet/{cnb.yaml → cnbcool.yaml} +0 -2
  4. package/config/defSet/gitcode.yaml +0 -2
  5. package/config/defSet/gitee.yaml +0 -2
  6. package/config/defSet/github.yaml +0 -3
  7. package/config/defSet/proxy.yaml +5 -0
  8. package/config/defSet/token.yaml +11 -0
  9. package/lib/apps/admin.js +1 -1
  10. package/lib/apps/commit.js +3 -0
  11. package/lib/apps/help.js +1 -1
  12. package/lib/apps/push.js +1 -5
  13. package/lib/common-DJ-f21cV.js +250 -0
  14. package/lib/db-DhpZxiAN.js +55 -0
  15. package/lib/index.js +1 -1
  16. package/lib/models-qDLDUVt0.js +3 -0
  17. package/lib/web.config.js +1 -0
  18. package/package.json +6 -26
  19. package/resources/background.webp +0 -0
  20. package/lib/apps/issue.js +0 -1
  21. package/lib/common-Df1uHYOv.js +0 -1
  22. package/lib/db-DZFBXSmG.js +0 -44
  23. package/lib/types-7HeFLBYV.js +0 -1
  24. package/resources/commit/index.css +0 -293
  25. package/resources/commit/index.html +0 -123
  26. package/resources/fonts/DouyinSansBold.woff2 +0 -0
  27. package/resources/fonts/NotoColorEmoji-Regular.woff2 +0 -0
  28. package/resources/fonts/SmileySans-Oblique.woff2 +0 -0
  29. package/resources/help/index.css +0 -124
  30. package/resources/help/index.html +0 -84
  31. package/resources/help/version-info.css +0 -31
  32. package/resources/help/version-info.html +0 -22
  33. package/resources/icons/branch.svg +0 -1
  34. package/resources/icons/cnb.svg +0 -1
  35. package/resources/icons/commit.svg +0 -1
  36. package/resources/icons/gitcode.svg +0 -1
  37. package/resources/icons/gitee.svg +0 -1
  38. package/resources/icons/github.svg +0 -1
  39. package/resources/icons/issue.svg +0 -1
  40. package/resources/issue/index.css +0 -229
  41. package/resources/issue/index.html +0 -79
  42. /package/lib/{root-C9I_RrRd.js → root-q84D5Ojp.js} +0 -0
  43. /package/resources/{icons/repo.svg → repo.svg} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # 变更日志
2
2
 
3
+ ## [1.4.0](https://github.com/CandriaJS/karin-plugin-git/compare/v1.3.0...v1.4.0) (2026-01-31)
4
+
5
+
6
+ ### ✨ 新功能
7
+
8
+ * **core:** 添加仓库绑定功能并重构数据库结构 ([84cbfa9](https://github.com/CandriaJS/karin-plugin-git/commit/84cbfa9dcd7fdc6bc36371b2765fddd23e3ad367))
9
+ * **models:** 实现session和bind数据模型 ([84cbfa9](https://github.com/CandriaJS/karin-plugin-git/commit/84cbfa9dcd7fdc6bc36371b2765fddd23e3ad367))
10
+ * **web:** 添加平台推送仓库列表配置界面 ([c720bf1](https://github.com/CandriaJS/karin-plugin-git/commit/c720bf169ad727f39484e1e4e3b68c7500e2582e))
11
+
12
+
13
+ ### 🐛 错误修复
14
+
15
+ * **commit:** 优化提交信息查询逻辑 ([84cbfa9](https://github.com/CandriaJS/karin-plugin-git/commit/84cbfa9dcd7fdc6bc36371b2765fddd23e3ad367))
16
+
17
+
18
+ ### 🔧 其他更新
19
+
20
+ * **core:** 更新 nipaw 依赖版本 ([6575fc9](https://github.com/CandriaJS/karin-plugin-git/commit/6575fc9832f56419300be40c48f704159c2f293f))
21
+
22
+
23
+ ### ♻️ 代码重构
24
+
25
+ * **config:** 重构配置文件结构 ([84cbfa9](https://github.com/CandriaJS/karin-plugin-git/commit/84cbfa9dcd7fdc6bc36371b2765fddd23e3ad367))
26
+ * **core:** 重构核心实现 ([#14](https://github.com/CandriaJS/karin-plugin-git/issues/14)) ([fa15ee1](https://github.com/CandriaJS/karin-plugin-git/commit/fa15ee174127db957b7b18584daf6ac157cf370a))
27
+
28
+
29
+ ### Dependencies
30
+
31
+ * The following workspace dependencies were updated
32
+ * devDependencies
33
+ * @candriajs/template bumped to 1.4.0
34
+
3
35
  ## [1.3.0](https://github.com/CandriaJS/karin-plugin-git/compare/v1.2.0...v1.3.0) (2025-11-29)
4
36
 
5
37
 
package/README.md CHANGED
@@ -1,3 +1,24 @@
1
- # karin-plugin-git
1
+ # <h1 align="center">karin-plugin-git</h1>
2
2
 
3
- karin的git平台仓库订阅推送
3
+ <div align="center">
4
+ <img src="https://socialify.git.ci/CandriaJS/karin-plugin-git/image?description=1&forks=1&issues=1&language=1&name=1&owner=1&pulls=1&stargazers=1&theme=Light" alt="emojimix-plugin" width="640" height="320" />
5
+
6
+ <a href="https://github.com/KarinJS/Karin"><img src="https://badgen.net/npm/v/node-karin?label=Karin" alt="Gitee"></a><a href="https://qm.qq.com/q/gBs8Ri3nIQ"><img src="https://img.shields.io/badge/group-272040396-blue" alt="Gitee"></a>
7
+
8
+ <img alt="Release" src="https://badgen.net/github/release/CandriaJS/karin-plugin-git/stable"><img alt="GitHub repo size" src="https://img.shields.io/github/repo-size/CandriaJS/karin-plugin-git">
9
+
10
+ <img src="https://badgen.net/npm/v/@candriajs/karin-plugin-git?label=karin-plugin-git" alt="npm Version">
11
+ <a href="https://pkg-size.dev/@candriajs/karin-plugin-git@beta"><img src="https://pkg-size.dev/badge/bundle/1606131" title="Bundle size for karin-plugin-git"></a>
12
+ </div>
13
+
14
+ ## 介绍 📝
15
+
16
+ `柠糖图片操作` 是一个 `Karin` 的扩展插件,提供bot对Git仓库操作功能。
17
+
18
+ ## 安装与更新 🔧
19
+
20
+ 在`Karin`目录执行以下命令
21
+
22
+ ```bash
23
+ pnpm add @candriajs/karin-plugin-git@latest -w
24
+ ```
@@ -1,3 +1 @@
1
1
  cron: '0 */5 * * * *'
2
- proxy: ''
3
- token: ''
@@ -1,3 +1 @@
1
1
  cron: '0 */5 * * * *'
2
- proxy: ''
3
- token: ''
@@ -1,3 +1 @@
1
1
  cron: '0 */5 * * * *'
2
- proxy: ''
3
- token: ''
@@ -1,4 +1 @@
1
1
  cron: '0 */5 * * * *'
2
- proxy: ''
3
- reverseProxy: ''
4
- token: ''
@@ -0,0 +1,5 @@
1
+ # 系统代理
2
+ proxy:
3
+
4
+ # 反向代理
5
+ reverseProxy:
@@ -0,0 +1,11 @@
1
+ # Github 访问令牌 https://github.com/settings/tokens
2
+ github:
3
+
4
+ # Gitee 访问令牌 https://gitee.com/profile/personal_access_tokens
5
+ gitee:
6
+
7
+ # GitCode 访问令牌 https://gitcode.com/setting/token-classic
8
+ gitcode:
9
+
10
+ # CnbCool 访问令牌 https://cnb.cool/profile/token
11
+ cnbcool:
package/lib/apps/admin.js CHANGED
@@ -1 +1 @@
1
- import"../root-C9I_RrRd.js";import{a as e,c as t,d as n,f as r,i,m as a,n as o,o as s,p as c,s as l,u}from"../db-DZFBXSmG.js";import{a as d,c as f,i as p,n as m,o as h,r as g}from"../common-Df1uHYOv.js";import{n as _,t as v}from"../types-7HeFLBYV.js";import y from"node-karin";import{isEmpty as b}from"es-toolkit/compat";const x=y.command(/^#?git(?:添加|add)([^\s]+)?订阅仓库([^/\s]+)\/([^:\s]+)(?::([^/\s]+))?(?:\s+([^/\s]+))?$/i,async t=>{let[,a,f,y,S,C]=t.msg.match(x.reg),w=C?C.toLocaleLowerCase().split(`,`).map(e=>e.trim()).filter(e=>e):[v.Push];w.length||w.push(v.Push);let T=t.selfId,E=t.groupId,D=_.GitHub,O;a?.toLowerCase()===`gitcode`?(D=_.GitCode,O=p()):a?.toLowerCase()===`gitee`?(D=_.Gitee,O=d()):a?.toLowerCase()===`cnb`?(D=_.Cnb,O=g()):(D=_.GitHub,O=h());let k=await n(T,E,f,y);if(k||=(await u(T,E,f,y),await n(T,E,f,y)),!k)return await t.reply(`添加订阅仓库失败,请重试`);let A=await i(D,k.id,w);if(A?await e(D,k.id,w):(await o(D,k.id,w),A=await i(D,k.id,w)),!A)return await t.reply(`添加仓库订阅事件失败,请重试`);let j=`添加订阅仓库成功, 平台: ${D}, 仓库: ${f}/${y}, 订阅类型: ${w.join(`,`)}`,M=w.includes(v.Push);if(M){let e=S||(await O.getRepoInfo(f,y)).defaultBranch;await c(A.id,e)?j=`仓库 ${f}/${y} 的推送订阅已存在,平台: ${D}, 分支: ${e}`:(await r(A.id,e),j+=`, 分支: ${e}`)}let N=w.includes(v.Issue);if(N)if((await l(A.id)).length)j=`仓库 ${f}/${y} 的议题订阅已存在, 平台: ${D}`;else{let e=await O.getIssueList(f,y,{perPage:100});if(b(e))return await t.reply(`添加议题订阅失败,请重试`);for(let t of e)await s(A.id,t.number,m(t.title),t.body?m(t.body):null,t.state)}console.log(M,N),await t.reply(j)},{name:`karin-plugin-git:admin:addRepo`,priority:500,event:`message.group`,permission:`master`}),S=y.command(/^#?git(?:移除|删除|remove)([^\s]+)?订阅仓库([^/\s]+)\/([^:\s]+)(?::([^/\s]+))?(?:\s+([^/\s]+))?$/i,async r=>{let[,o,s,u,d,f]=r.msg.match(S.reg),p=r.selfId,m=r.groupId,h=_.GitHub,g=f?f.toLocaleLowerCase().split(`,`).map(e=>e.trim()).filter(e=>e):[v.Push];g.length||g.push(v.Push),o?.toLowerCase()===`gitcode`?h=_.GitCode:o?.toLowerCase()===`gitee`?h=_.Gitee:o?.toLowerCase()===`cnb`&&(h=_.Cnb);let y=await n(p,m,s,u);if(!y)return await r.reply(`未找到该仓库, 删除失败,请重试`);let b=await i(h,y.id,g);if(!b)return await r.reply(`未找到该订阅事件, 删除失败,请重试`);if(g.includes(v.Push)){let t=b.eventType.filter(e=>e!==v.Push);if(await e(h,y.id,t),!await c(b.id,d))return await r.reply(`推送订阅不存在,删除失败`);await a(b.id,d)}if(g.includes(v.Issue)){let n=b.eventType.filter(e=>e!==v.Issue);if(await e(h,y.id,n),!await l(b.id))return await r.reply(`议题订阅不存在,删除失败`);await t(b.id)}await r.reply(`删除订阅仓库成功, 平台: ${h}, 仓库: ${s}/${u}, 订阅类型: ${g.join(`,`)}`)},{name:`karin-plugin-git:admin:removeRepo`,priority:500,event:`message.group`,permission:`master`}),C=y.command(/^#?git(?:设置|set)([^\s]+)?(?:token|访问令牌)([\s\S]+)$/i,async e=>{let[,t,n]=e.msg.match(C.reg),r=_.GitHub;t?.toLowerCase()===`gitcode`?r=_.GitCode:t?.toLowerCase()===`gitee`?r=_.Gitee:t?.toLowerCase()===`cnb`&&(r=_.Cnb),f.Modify(r,`token`,n),await e.reply(`设置${r}访问令牌成功`)},{name:`karin-plugin-git:admin:SetToken`,priority:500,event:`message.friend`,permission:`master`});export{x as AddRepo,S as RemoveRepo,C as SetToken};
1
+ import"../root-q84D5Ojp.js";import{a as e,c as t,d as n,f as r,i,l as a,n as o,o as s,s as c}from"../db-DhpZxiAN.js";import{i as l,n as u,r as d}from"../common-DJ-f21cV.js";import{d as f,f as p,l as m,u as h}from"../models-qDLDUVt0.js";import g from"node-karin";const _=g.command(/^#?git(?:添加|add)(?:订阅仓库|repo)(?:([a-zA-Z]+):([^/\s]+)\/([^:\s]+))(?:\s+([^/\s]+))?$/i,async e=>{let[,r,s,l,g]=e.msg.match(_.reg),v=g?g.toLocaleLowerCase().split(`,`).map(e=>e.trim()).filter(e=>e):[u.Push];v.length||v.push(u.Push);let y=e.selfId,b=e.groupId,x=d.GitHub,S=p();switch(r.toLowerCase()){case`github`:S=p(),x=d.GitHub;break;case`gitcode`:S=h(),x=d.GitCode;break;case`gitee`:S=f(),x=d.Gitee;break;case`cnb`:case`cnbcool`:S=m(),x=d.CnbCool;break;default:return await e.reply(`未找到该平台, 请重试`)}let[C,w]=await Promise.all([i(x,s,l),t(y,b)]);if(C||=(await o(x,s,l),await i(x,s,l)),w||=(await c(y,b),await t(y,b)),!C||!w)return await e.reply(`添加订阅仓库失败,请重试`);let T=`添加订阅仓库成功, 平台: ${x}, 仓库: ${s}/${l}, 订阅类型: ${v.join(`,`)}`;if(v.includes(u.Push)){let e=S.repo(),t;try{t=(await e.info({owner:s,repo:l})).defaultBranch}catch{t=`main`}await n(C.id,w.id,t)?T=`仓库 ${s}/${l} 的推送订阅已存在, 请勿重复订阅`:(await a(C.id,w.id,t),T+=`, 分支: ${t}`)}await e.reply(T)},{name:`admin:addRepo`,priority:500,event:`message.group`,permission:`master`}),v=g.command(/^#?git(?:绑定|bind)(?:仓库|repo)(?:([a-zA-Z]+):([^/\s]+)\/([^:\s]+))$/i,async t=>{let[,n,r,a]=t.msg.match(v.reg),c=d.GitHub;switch(n.toLowerCase()){case`github`:c=d.GitHub;break;case`gitcode`:c=d.GitCode;break;case`gitee`:c=d.Gitee;break;case`cnb`:case`cnbcool`:c=d.CnbCool;break;default:return await t.reply(`未找到该平台, 请重试`)}let l=await i(c,r,a);if(l||=(await o(c,r,a),await i(c,r,a)),!l)return await t.reply(`绑定仓库失败, 请重试`);if(await s(t.groupId))return await t.reply(`该群已绑定该仓库, 请勿重复绑定`);await e(t.groupId,l.id),await t.reply(`绑定仓库成功, 平台: ${c}, 仓库: ${r}/${a}`)},{name:`admin:bindRepo`,event:`message.group`}),y=g.command(/^#?git(?:移除|删除|remove)(?:订阅仓库|repo)(?:([a-zA-Z]+):([^/\s]+)\/([^:\s]+))$/i,async e=>{let[,n,a,o]=e.msg.match(y.reg),s=e.selfId,c=e.groupId,l=d.GitHub;switch(n.toLowerCase()){case`github`:l=d.GitHub;break;case`gitcode`:l=d.GitCode;break;case`gitee`:l=d.Gitee;break;case`cnb`:case`cnbcool`:l=d.CnbCool;break;default:return await e.reply(`未找到该平台, 请重试`)}let[u,f]=await Promise.all([i(l,a,o),t(s,c)]);if(!u||!f)return await e.reply(`未找到该订阅仓库, 删除失败,请重试`);await r(u.id,f.id),await e.reply(`删除订阅仓库成功`)},{name:`admin:removeRepo`,priority:500,event:`message.group`,permission:`master`}),b=g.command(/^#?git(?:设置|set)([^\s]+)?(?:token|访问令牌)([\s\S]+)$/i,async e=>{let[,t,n]=e.msg.match(b.reg),r;switch(t.toLowerCase()){case`github`:r=`github`;break;case`gitcode`:r=`gitcode`;break;case`gitee`:r=`gitee`;break;case`cnb`:case`cnbcool`:r=`cnbcool`;break;default:return await e.reply(`未找到该平台, 请重试`)}l.Modify(r,`token`,n),await e.reply(`设置${t.toLowerCase()}访问令牌成功`)},{name:`admin:SetToken`,priority:500,event:`message.friend`,permission:`master`});export{_ as AddRepo,v as BindRepo,y as RemoveRepo,b as SetToken};
@@ -0,0 +1,3 @@
1
+ import"../root-q84D5Ojp.js";import{i as e,o as t}from"../db-DhpZxiAN.js";import{i as n,r,t as i}from"../common-DJ-f21cV.js";import{d as a,f as o,l as s,u as c}from"../models-qDLDUVt0.js";import l,{logger as u}from"node-karin";import{isEmpty as d}from"es-toolkit/compat";const f=l.command(/^#?(?:git(?:commit|提交信息|提交记录))\s*(\w+)(?::(?:([^\/\s]+)\/([^:\s]+)))?(?::([^\/\s]+))?$/i,async l=>{let[,p,m,h,g]=l.msg.match(f.reg);if(!m||!h){let n=await t(l.groupId);if(!n)return await l.reply(`请先绑定仓库或指定仓库`);let r=await e(n.repoId);m=r.owner,h=r.repo}let _,v=n.token.github,y=r.GitHub;switch(p.toLowerCase()){case`github`:y=r.GitHub,_=o(),v=n.token.github;break;case`gitcode`:y=r.GitCode,_=c(),v=n.token.gitcode;break;case`gitee`:y=r.Gitee,_=a(),v=n.token.gitee;break;case`cnbcool`:y=r.CnbCool,_=s(),v=n.token.cnbcool;break;default:return await l.reply(`未找到该平台, 请重试`)}if(p.toLowerCase()!==`github`&&d(v))return await l.reply(`请先配置访问令牌`);let b=_.commit();try{let e=await b.info({owner:m,repo:h},g),t=e.commit.message.split(`
2
+ `),n={owner:m,repo:h,sha:e.sha,title:t[0],content:t.slice(1).join(`
3
+ `),stats:e.stats,files:e.files,author:e.commit.author,committer:e.commit.committer,branch:g},r=await i.commit(y,n);return await l.reply(r)}catch(e){return u.error(`获取${p.toLowerCase()}提交信息出错: ${m}/${h}:${g||``} - ${e.message}`),await l.reply(`获取提交信息失败, 请重试`)}},{name:`commit:info`,event:`message.group`});export{f as commit};
package/lib/apps/help.js CHANGED
@@ -1 +1 @@
1
- import{t as e}from"../root-C9I_RrRd.js";import{s as t}from"../common-Df1uHYOv.js";import n,{requireFile as r}from"node-karin";import i from"markdown-it";const a=n.command(/^#?(?:(git))(?:命令|帮助|菜单|help|说明|功能|指令|使用说明)$/i,async e=>{let n=e.isMaster?`master`:`member`,r=await t.render(`help/index`,{role:n});return await e.reply(r),!0},{name:`karin-plugin-git:help`,priority:500,event:`message`,permission:`all`}),o=n.command(/^#?(?:(git))(?:版本|版本信息|version|versioninfo)$/i,async n=>{let a=new i({html:!0}).render(await r(`${e.Plugin_Path}/CHANGELOG.md`)),o=await t.render(`help/version-info`,{Markdown:a});return await n.reply(o),!0},{name:`karin-plugin-git:version`,priority:500,event:`message`,permission:`all`});export{a as help,o as version};
1
+ import{t as e}from"../root-q84D5Ojp.js";import{t}from"../common-DJ-f21cV.js";import n,{segment as r}from"node-karin";import i from"node:fs";const a=n.command(/^#?(?:(git))(?:命令|帮助|菜单|help|说明|功能|指令|使用说明)$/i,async n=>{let a=[{name:`常用操作`,list:[{name:`订阅git仓库`,desc:`订阅git仓库并推送, 支持github,gitee,gitcode,cnbcool`,icon:await i.promises.readFile(`${e.Plugin_Path}/resources/icons/repo.svg`)}]}];if(n.isMaster){let t=await i.promises.readFile(`${e.Plugin_Path}/resources/icons/subscription.svg`),n=await i.promises.readFile(`${e.Plugin_Path}/resources/icons/token.svg`);a.push({name:`管理命令`,list:[{name:`#git添加订阅仓库[platform:]owner/repo[:event]`,desc:`添加一个订阅仓库, event可选:push`,icon:t},{name:`#git删除订阅仓库[platform:]owner/repo`,desc:`删除一个订阅仓库`,icon:t},{name:`#git设置[platform]token + token`,desc:`设置一个平台的访问令牌`,icon:n}]})}let o=await i.promises.readFile(`${e.Plugin_Path}/resources/background.webp`),s=await t.help({title:`Git 帮助`,theme:{backgroundImage:o},list:a});return await n.reply(r.image(`base64://${s.toString(`base64`)}`)),!0},{name:`help`,priority:500,event:`message`,permission:`all`});export{a as help};
package/lib/apps/push.js CHANGED
@@ -1,5 +1 @@
1
- import"../root-C9I_RrRd.js";import{d as e,f as t,h as n,p as r,r as i,s as a}from"../db-DZFBXSmG.js";import{a as o,c as s,i as c,o as l,r as u,s as d,t as f}from"../common-Df1uHYOv.js";import{n as p,t as m}from"../types-7HeFLBYV.js";import h,{common as g,contactGroup as _,getBot as v,logger as y}from"node-karin";import{isEmpty as b}from"es-toolkit/compat";const x=h.task(`karin-plugin-git:push:github`,s.github.cron||`0 */5 * * * *`,async()=>{let e=s.github.token;if(b(e))return y.warn(`未配置GitHub Token, 跳过任务`);try{await E(l(),p.GitHub)}catch(e){y.error(e)}}),S=h.task(`karin-plugin-git:push:gitee`,s.gitee.cron||`0 */5 * * * *`,async()=>{let e=s.gitee.token;if(b(e))return y.warn(`Gitee Token, 跳过任务`);try{await E(o(),p.Gitee)}catch(e){y.error(e)}}),C=h.task(`karin-plugin-git:push:gitee`,s.gitcode.cron||`0 */5 * * * *`,async()=>{let e=s.gitcode.token;if(b(e))return y.warn(`GitCode Token, 跳过任务`);try{await E(c(),p.GitCode)}catch(e){y.error(e)}}),w=h.task(`karin-plugin-git:push:cnb`,s.cnb.cron||`0 */5 * * * *`,async()=>{let e=s.cnb.token;if(b(e))return y.warn(`未配置CnbCool Token, 跳过任务`);try{await E(u(),p.Cnb)}catch(e){y.error(e)}}),T=h.command(/^#?git(?:推送|push)订阅仓库$/i,async t=>{try{let n=t.selfId,m=t.groupId,h=await i(),g,_=[];for(let i of h){let h=await e(i.repoId);if(!h)continue;if(i.platform==p.Gitee){if(b(s.gitee.token))return await t.reply(`未配置Gitee Token, 请先配置Gitee Token`);g=o()}else if(i.platform==p.GitCode){if(b(s.gitcode.token))return await t.reply(`未配置GitCode Token, 请先配置GitCode Token`);g=c()}else if(i.platform==p.Cnb){if(b(s.cnb.token))return await t.reply(`Cnb Token, 请先配置Cnb Token`);g=u()}else{if(b(s.github.token))return await t.reply(`未配置GitHub Token, 请先配置GitHub Token`);g=l()}let v=(await r(i.id)).map(async e=>{try{let t=await g.getCommitInfo(h.owner,h.repo,e.branch),r=t.commit.message.split(`
2
- `),i={...t,owner:h.owner,repo:h.repo,branch:e.branch,botId:n,groupId:m,title:await d.markdown(r[0]),body:await d.markdown(r.slice(1).join(`
3
- `)),commitDate:f(t.commit.committer.date)};return await d.render(`commit/index`,{commit:i})}catch(t){return y.warn(`获取仓库 ${h.owner}/${h.repo} 分支 ${e.branch} 提交信息失败:`,t),null}}),x=(await Promise.allSettled(v)).filter(e=>e.status===`fulfilled`).map(e=>e.value).filter(e=>e!==null);_.push(...x);let S=(await a(i.id)).map(async e=>{if(b(e))return null;let t=await g.getIssueInfo(h.owner,h.repo,e.issueId),n={owner:h.owner,repo:h.repo,title:await d.markdown(t.title),body:t.body?await d.markdown(t.body):null,user:t.user,state:t.state,issueDate:f(t.createdAt)};return await d.render(`issue/index`,{issue:n})}),C=(await Promise.allSettled(S)).filter(e=>e.status===`fulfilled`).map(e=>e.value).filter(e=>e!==null);_.push(...C)}_.length>0&&await D(n,m,_)}catch(e){y.error(e)}},{name:`karin-plugin-git:pushRepo`,priority:500,event:`message.group`,permission:`master`}),E=async(a,o)=>{let s=await i(o,m.Push);if(b(s))return;let c=new Map;for(let i of s){let o=await e(i.repoId);if(!o)continue;let s=`${o.groupId}-${o.botId}`,l=await r(i.id);if(b(l)){let{defaultBranch:e}=await a.getRepoInfo(o.owner,o.repo);await t(i.id,e),l=await r(i.repoId)}for(let e of l){let t=await a.getCommitInfo(o.owner,o.repo,e.branch);if(!t||t.sha===e.commitSha){y.debug(`[karin-plugin-git] 平台: ${i.platform} 仓库:${o.owner}/${o.repo} 分支: ${e.branch} 提交信息无变更`);continue}c.has(s)||c.set(s,[]),c.get(s).push({pushRepo:e,pushRepoInfo:o,commitInfo:t}),y.debug(`[karin-plugin-git] 平台: ${i.platform} 仓库:${o.owner}/${o.repo} 分支: ${e.branch} 提交信息变更`),await n(e.eventId,e.branch,t.sha)}}for(let[e,t]of c.entries()){let[n,r]=e.split(`-`),i=t.map(async e=>{let t=e.commitInfo.commit.message.split(`
4
- `),n={...e.commitInfo,owner:e.pushRepoInfo.owner,repo:e.pushRepoInfo.repo,branch:e.pushRepo.branch,botId:e.pushRepoInfo.botId,groupId:e.pushRepoInfo.groupId,title:await d.markdown(t[0]),body:await d.markdown(t.slice(1).join(`
5
- `)),commitDate:f(e.commitInfo.commit.committer.date)};return await d.render(`commit/index`,{commit:n})}),a=(await Promise.allSettled(i)).filter(e=>e.status===`fulfilled`&&e.value!==null).map(e=>e.value);a.length>0&&await D(r,n,a)}},D=async(e,t,n)=>{let r=v(e),i=await _(t);if(n.length>3){let t=await g.makeForward(n,e,r?.account.name);await r?.sendForwardMsg(i,t,{source:`仓库推送合集`,summary:`查看${t.length}张仓库推送消息`,prompt:`Gitub仓库推送结果`,news:[{text:`点击查看推送结果`}]})}else await r?.sendMsg(i,n)};export{w as cnb,C as gitcode,S as gitee,x as github,T as push};
1
+ import"../root-q84D5Ojp.js";import"../db-DhpZxiAN.js";import{i as e}from"../common-DJ-f21cV.js";import{c as t,i as n,n as r,o as i}from"../models-qDLDUVt0.js";import a,{logger as o}from"node-karin";import{isEmpty as s}from"es-toolkit/compat";const c=a.task(`commit:push:github`,e.github.cron||`0 */5 * * * *`,async()=>{let n=e.token.github;if(s(n))return o.warn(`未配置GitHub Token, 跳过任务`);try{await new t().action()}catch(e){o.error(e)}}),l=a.task(`commit:push:gitee`,e.gitee.cron||`0 */5 * * * *`,async()=>{let t=e.token.gitee;if(s(t))return o.warn(`未配置 Gitee Token, 跳过任务`);try{await new i().action()}catch(e){o.error(e)}}),u=a.task(`commit:push:gitcode`,e.gitcode.cron||`0 */5 * * * *`,async()=>{let t=e.token.gitcode;if(s(t))return o.warn(`未配置 GitCode Token, 跳过任务`);try{await new n().action()}catch(e){o.error(e)}}),d=a.task(`commit:push:cnbcool`,e.cnbcool.cron||`0 */5 * * * *`,async()=>{let t=e.token.cnbcool;if(s(t))return o.warn(`未配置 CnbCol Token, 跳过任务`);try{await new r().action()}catch(e){o.error(`推送CnbCool仓库提交信息失败: ${e}`)}});export{d as cnbcool,u as gitcode,l as gitee,c as github};