Skip to content

Commit

Permalink
✨ feat: update auto submit
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Oct 7, 2023
1 parent b82b108 commit 53cbbc3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
19 changes: 11 additions & 8 deletions scripts/autoSubmit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { resolve } from 'node:path';

import { formatAgentJSON } from './check';
import { agentsDir, githubHomepage } from './const';
import { writeJSON } from './utils';
import { getLocaleAgentFileName, writeJSON } from './utils';

const GENERATE_LABEL = '🤖 Agent PR';
const SUCCESS_LABEL = '✅ Auto Check Pass';
Expand All @@ -17,7 +17,8 @@ const ERROR_LABEL = '🚨 Auto Check Fail';
class AutoSubmit {
owner = 'lobehub';
repo = 'lobe-chat-agents';
issueNumber = process.env.ISSUE_NUMBER;
issueNumber = Number(process.env.ISSUE_NUMBER);
private octokit: Octokit;

constructor() {
this.octokit = new Octokit({ auth: `token ${process.env.GH_TOKEN}` });
Expand Down Expand Up @@ -50,10 +51,11 @@ class AutoSubmit {
if (!issue) return;
consola.info(`Get issues #${this.issueNumber}`);

const agent = await this.formatIssue(issue);
const { agent, locale } = await this.formatIssue(issue);
const comment = this.genCommentMessage(agent);
const agentName = agent.identifier;
const fileName = agentName + '.json';

const fileName = getLocaleAgentFileName(agentName, locale);
const filePath = resolve(agentsDir, fileName);

// check same name
Expand Down Expand Up @@ -172,7 +174,7 @@ class AutoSubmit {
const { owner, repo, octokit, issueNumber } = this;
const issue = await this.getIssue();

const baseLabels = issue.labels.map(({ name }) => name);
const baseLabels = issue.labels.map((l) => (typeof l === 'string' ? l : l.name));
const removeLabels = baseLabels.filter((name) => name === label);

for (const label of removeLabels) {
Expand Down Expand Up @@ -219,21 +221,21 @@ class AutoSubmit {
json[currentKey] = currentValue.trim();
}

// @ts-ignore
json.tags = json.tags.replaceAll(',', ',').replaceAll(', ', ',').split(',');

return json;
}

async formatIssue(data) {
const json = this.markdownToJson(data.body);
const json = this.markdownToJson(data.body) as any;
const agent = {
author: data.user.login,
config: {
systemRole: json.systemRole,
},
homepage: data.user.html_url,
identifier: kebabCase(json.identifier),
locale: json.locale,
meta: {
avatar: json.avatar,
description: json.description,
Expand All @@ -242,7 +244,8 @@ class AutoSubmit {
},
};

return await formatAgentJSON(agent);
const locale: string = json.locale;
return { agent: await formatAgentJSON(agent, locale), locale };
}
}

Expand Down
13 changes: 5 additions & 8 deletions scripts/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { format } from 'prettier';
import { remark } from 'remark';
import pangu from 'remark-pangu';

import { agentMetaSchema } from './schema/agentMeta';
import { config, meta } from './const';
import { LobeAgent, agentMetaSchema } from './schema/agentMeta';

export const formatAndCheckSchema = (agent) => {
if (!agent.schemaVersion) agent.schemaVersion = meta.schemaVersion;
Expand All @@ -23,18 +23,15 @@ export const formatAndCheckSchema = (agent) => {
return agent;
};

export const formatPrompt = async (prompt, local) => {
return local === 'zh-CN'
export const formatPrompt = async (prompt: string, locale: string) => {
return locale === 'zh-CN'
? String(await remark().use(pangu).process(prompt))
: String(await remark().process(prompt));
};

export const formatAgentJSON = async (agent) => {
export const formatAgentJSON = async (agent: LobeAgent, locale: string = config.entryLocale) => {
formatAndCheckSchema(agent);
agent.config.systemRole = await formatPrompt(
agent.config.systemRole,
agent?.locale || config.entryLocale,
);
agent.config.systemRole = await formatPrompt(agent.config.systemRole, locale);

agent.config.systemRole = await format(agent.config.systemRole, { parser: 'markdown' });
agent.identifier = kebabCase(agent.identifier);
Expand Down
2 changes: 1 addition & 1 deletion scripts/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Formatter {

let { content: agent, id, locale: defaultLocale } = Parser.parseFile(fileName);

agent = await formatAgentJSON(agent);
agent = await formatAgentJSON(agent, defaultLocale);

// i18n workflow
let rawData = {};
Expand Down

0 comments on commit 53cbbc3

Please sign in to comment.