mirror of https://github.com/msgbyte/tailchat
feat: add github repo group ensure action which will auto create group and subscribe activity
parent
588fae2e60
commit
c96367f157
@ -1,7 +1,7 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
externalDeps: ['react'],
|
externalDeps: ['react', 'react-router'],
|
||||||
pluginRoot: path.resolve(__dirname, './web'),
|
pluginRoot: path.resolve(__dirname, './web'),
|
||||||
outDir: path.resolve(__dirname, '../../public'),
|
outDir: path.resolve(__dirname, '../../public'),
|
||||||
};
|
};
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
import {
|
||||||
|
getModelForClass,
|
||||||
|
prop,
|
||||||
|
DocumentType,
|
||||||
|
modelOptions,
|
||||||
|
} from '@typegoose/typegoose';
|
||||||
|
import { Base, TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';
|
||||||
|
import type { Types } from 'mongoose';
|
||||||
|
|
||||||
|
@modelOptions({
|
||||||
|
options: {
|
||||||
|
customName: 'p_githubRepo',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
export class Repo extends TimeStamps implements Base {
|
||||||
|
_id: Types.ObjectId;
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
@prop({
|
||||||
|
unique: true,
|
||||||
|
})
|
||||||
|
repoName: string; // 完整地址
|
||||||
|
|
||||||
|
@prop()
|
||||||
|
groupId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type RepoDocument = DocumentType<Repo>;
|
||||||
|
|
||||||
|
const model = getModelForClass(Repo);
|
||||||
|
|
||||||
|
export type RepoModel = typeof model;
|
||||||
|
|
||||||
|
export default model;
|
@ -0,0 +1,99 @@
|
|||||||
|
import type { GroupStruct } from 'tailchat-server-sdk';
|
||||||
|
import { GroupPanelType, TcContext } from 'tailchat-server-sdk';
|
||||||
|
import { TcService, TcDbService } from 'tailchat-server-sdk';
|
||||||
|
import type { RepoDocument, RepoModel } from '../models/repo';
|
||||||
|
|
||||||
|
const ACTIVITY_PANEL_NAME = 'Activity';
|
||||||
|
|
||||||
|
const defaultGroupPanel = [
|
||||||
|
{
|
||||||
|
id: '00',
|
||||||
|
name: 'Default',
|
||||||
|
type: GroupPanelType.GROUP,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '01',
|
||||||
|
name: 'Lobby',
|
||||||
|
parentId: '00',
|
||||||
|
type: GroupPanelType.TEXT,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '02',
|
||||||
|
name: ACTIVITY_PANEL_NAME,
|
||||||
|
parentId: '00',
|
||||||
|
type: GroupPanelType.TEXT,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '10',
|
||||||
|
name: 'Project',
|
||||||
|
type: GroupPanelType.GROUP,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Github项目管理服务
|
||||||
|
*/
|
||||||
|
|
||||||
|
interface GithubRepoService
|
||||||
|
extends TcService,
|
||||||
|
TcDbService<RepoDocument, RepoModel> {}
|
||||||
|
class GithubRepoService extends TcService {
|
||||||
|
get serviceName() {
|
||||||
|
return 'plugin:com.msgbyte.github.repo';
|
||||||
|
}
|
||||||
|
|
||||||
|
onInit() {
|
||||||
|
this.registerLocalDb(require('../models/repo').default);
|
||||||
|
|
||||||
|
this.registerAction('ensure', this.ensure, {
|
||||||
|
params: {
|
||||||
|
repoName: 'string',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async ensure(ctx: TcContext<{ repoName: string }>): Promise<{
|
||||||
|
repoName: string;
|
||||||
|
groupId: string;
|
||||||
|
}> {
|
||||||
|
const { repoName } = ctx.params;
|
||||||
|
|
||||||
|
let doc = await this.adapter.model.findOne({
|
||||||
|
repoName,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!doc) {
|
||||||
|
// 不存在
|
||||||
|
const group = await this.systemCall<GroupStruct>(
|
||||||
|
ctx,
|
||||||
|
'group.createGroup',
|
||||||
|
{
|
||||||
|
name: repoName,
|
||||||
|
panels: defaultGroupPanel,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
const groupId = String(group._id);
|
||||||
|
const activityPanel = group.panels.find(
|
||||||
|
(item) => item.name === ACTIVITY_PANEL_NAME
|
||||||
|
);
|
||||||
|
if (activityPanel) {
|
||||||
|
await this.systemCall(ctx, 'plugin:com.msgbyte.github.subscribe.add', {
|
||||||
|
groupId,
|
||||||
|
textPanelId: activityPanel.id,
|
||||||
|
repoName,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
doc = await this.adapter.model.create({
|
||||||
|
repoName,
|
||||||
|
groupId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const json = await this.transformDocuments(ctx, {}, doc);
|
||||||
|
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default GithubRepoService;
|
@ -0,0 +1,23 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { useParams } from 'react-router';
|
||||||
|
|
||||||
|
interface GithubRepoName {
|
||||||
|
owner: string;
|
||||||
|
repo: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const GithubRepoInfo: React.FC<GithubRepoName> = React.memo((props) => {
|
||||||
|
return <div>GithubRepoInfo {JSON.stringify(props)}</div>;
|
||||||
|
});
|
||||||
|
GithubRepoInfo.displayName = 'GithubRepoInfo';
|
||||||
|
|
||||||
|
export const GithubRepoInfoRoute: React.FC = React.memo(() => {
|
||||||
|
const params = useParams<GithubRepoName>();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<GithubRepoInfo owner={params.owner} repo={params.repo} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
GithubRepoInfoRoute.displayName = 'GithubRepoInfoRoute';
|
@ -1,26 +1,40 @@
|
|||||||
import {
|
import {
|
||||||
regCustomPanel,
|
regCustomPanel,
|
||||||
Loadable,
|
|
||||||
regInspectService,
|
regInspectService,
|
||||||
regPluginPermission,
|
regPluginPermission,
|
||||||
|
regPluginRootRoute,
|
||||||
|
isDevelopment,
|
||||||
} from '@capital/common';
|
} from '@capital/common';
|
||||||
|
import { Loadable } from '@capital/component';
|
||||||
import { Translate } from './translate';
|
import { Translate } from './translate';
|
||||||
|
|
||||||
|
const PLUGIN_ID = 'com.msgbyte.github';
|
||||||
|
|
||||||
regCustomPanel({
|
regCustomPanel({
|
||||||
position: 'groupdetail',
|
position: 'groupdetail',
|
||||||
name: 'com.msgbyte.github/groupSubscribe',
|
name: `${PLUGIN_ID}/groupSubscribe`,
|
||||||
label: Translate.groupSubscribe,
|
label: Translate.groupSubscribe,
|
||||||
render: Loadable(() => import('./GroupSubscribePanel')),
|
render: Loadable(() => import('./GroupSubscribePanel')),
|
||||||
});
|
});
|
||||||
|
|
||||||
regInspectService({
|
regInspectService({
|
||||||
name: 'plugin:com.msgbyte.github.subscribe',
|
name: `plugin:${PLUGIN_ID}.subscribe`,
|
||||||
label: Translate.githubService,
|
label: Translate.githubService,
|
||||||
});
|
});
|
||||||
|
|
||||||
regPluginPermission({
|
regPluginPermission({
|
||||||
key: 'plugin.com.msgbyte.github.subscribe.manage',
|
key: `plugin.${PLUGIN_ID}.subscribe.manage`,
|
||||||
title: Translate.permissionTitle,
|
title: Translate.permissionTitle,
|
||||||
desc: Translate.permissionDesc,
|
desc: Translate.permissionDesc,
|
||||||
default: false,
|
default: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (isDevelopment) {
|
||||||
|
regPluginRootRoute({
|
||||||
|
name: `plugin:${PLUGIN_ID}/route`,
|
||||||
|
path: '/github/:owner/:repo',
|
||||||
|
component: Loadable(() =>
|
||||||
|
import('./components/GithubRepoInfo').then((m) => m.GithubRepoInfoRoute)
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue