@alauda/doom 0.22.0 → 0.22.1
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.
package/lib/cli/index.js
CHANGED
|
File without changes
|
package/lib/cli/translate.js
CHANGED
|
@@ -12,7 +12,7 @@ import matter from 'gray-matter';
|
|
|
12
12
|
import { AzureOpenAI, RateLimitError } from 'openai';
|
|
13
13
|
import { pRateLimit } from 'p-ratelimit';
|
|
14
14
|
import { glob } from 'tinyglobby';
|
|
15
|
-
import {
|
|
15
|
+
import { xfetch } from 'x-fetch';
|
|
16
16
|
import { parse } from 'yaml';
|
|
17
17
|
import { cyan, red } from 'yoctocolors';
|
|
18
18
|
import { mdProcessor, mdxProcessor, normalizeImgSrc, } from '../plugins/index.js';
|
|
@@ -62,7 +62,7 @@ const DEFAULT_SYSTEM_PROMPT = `
|
|
|
62
62
|
`.trim();
|
|
63
63
|
let openai;
|
|
64
64
|
const resolveTerms_ = async () => {
|
|
65
|
-
const terms = await
|
|
65
|
+
const terms = await xfetch('https://gitlab-ce.alauda.cn/alauda-public/product-doc-guide/-/raw/main/terms.yaml', { type: 'text' });
|
|
66
66
|
const parsedTerms = parse(terms);
|
|
67
67
|
return ('- 以下是常见的相关术语词汇对应表(English <-> 中文)\n' +
|
|
68
68
|
parsedTerms.map(({ en, zh = en }) => ` * ${en} <-> ${zh}`).join('\n'));
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { logger } from '@rspress/shared/logger';
|
|
2
2
|
import { render } from 'ejs';
|
|
3
|
+
import { ResponseError, xfetch } from 'x-fetch';
|
|
3
4
|
import { cyan, red } from 'yoctocolors';
|
|
4
5
|
import { isCI } from './utils.js';
|
|
5
6
|
const releaseCache = new Map();
|
|
@@ -7,41 +8,38 @@ const FIELD_MAPPER = {
|
|
|
7
8
|
zh: 'customfield_13800',
|
|
8
9
|
en: 'customfield_13801',
|
|
9
10
|
};
|
|
11
|
+
const issuesToListItems = (issues, lang) => issues
|
|
12
|
+
.map((issue) => {
|
|
13
|
+
const description = ((FIELD_MAPPER[lang] && issue.fields[FIELD_MAPPER[lang]]) ||
|
|
14
|
+
issue.fields[FIELD_MAPPER.en])?.trim();
|
|
15
|
+
if (!description) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
type: 'listItem',
|
|
20
|
+
children: [
|
|
21
|
+
{
|
|
22
|
+
type: 'paragraph',
|
|
23
|
+
children: description
|
|
24
|
+
.split('\n')
|
|
25
|
+
.map((line) => ({ type: 'text', value: line }))
|
|
26
|
+
.reduce((acc, curr, index) => {
|
|
27
|
+
if (index === 0) {
|
|
28
|
+
return [curr];
|
|
29
|
+
}
|
|
30
|
+
return acc.concat({ type: 'html', value: '<br>' }, curr);
|
|
31
|
+
}, []),
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
})
|
|
36
|
+
.filter(Boolean);
|
|
10
37
|
const { JIRA_USERNAME, JIRA_PASSWORD } = process.env;
|
|
11
|
-
const issuesToMdast = (issues, lang) => {
|
|
12
|
-
return issues
|
|
13
|
-
.map((issue) => {
|
|
14
|
-
const description = ((lang !== 'en' && issue.fields[FIELD_MAPPER[lang]]) ||
|
|
15
|
-
issue.fields[FIELD_MAPPER.en])?.trim();
|
|
16
|
-
if (!description) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
return {
|
|
20
|
-
type: 'listItem',
|
|
21
|
-
children: [
|
|
22
|
-
{
|
|
23
|
-
type: 'paragraph',
|
|
24
|
-
children: description
|
|
25
|
-
.split('\n')
|
|
26
|
-
.map((line) => {
|
|
27
|
-
return {
|
|
28
|
-
type: 'text',
|
|
29
|
-
value: line,
|
|
30
|
-
};
|
|
31
|
-
})
|
|
32
|
-
.reduce((acc, curr, index) => {
|
|
33
|
-
if (index === 0) {
|
|
34
|
-
return [curr];
|
|
35
|
-
}
|
|
36
|
-
return acc.concat({ type: 'html', value: '<br>' }, curr);
|
|
37
|
-
}, []),
|
|
38
|
-
},
|
|
39
|
-
],
|
|
40
|
-
};
|
|
41
|
-
})
|
|
42
|
-
.filter((_) => !!_);
|
|
43
|
-
};
|
|
44
38
|
let warned = false;
|
|
39
|
+
const NO_ISSUE_MAPPER = {
|
|
40
|
+
zh: '此次发版无相关问题。',
|
|
41
|
+
en: 'No issues in this release.',
|
|
42
|
+
};
|
|
45
43
|
const resolveRelease_ = async (releaseTemplates, releaseQuery) => {
|
|
46
44
|
const query = new URLSearchParams(releaseQuery);
|
|
47
45
|
const templateName = query.get('template');
|
|
@@ -62,10 +60,8 @@ const resolveRelease_ = async (releaseTemplates, releaseQuery) => {
|
|
|
62
60
|
if (warned) {
|
|
63
61
|
return;
|
|
64
62
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
const message = `${cyan('`JIRA_USERNAME`')} and ${cyan('`JIRA_PASSWORD`')} environments must be set for fetching Jira issues`;
|
|
63
|
+
warned = true;
|
|
64
|
+
const message = `\`${cyan('JIRA_USERNAME')}\` and \`${cyan('JIRA_PASSWORD')}\` environments must be set for fetching Jira issues`;
|
|
69
65
|
if (isCI) {
|
|
70
66
|
throw new Error(message);
|
|
71
67
|
}
|
|
@@ -81,14 +77,32 @@ const resolveRelease_ = async (releaseTemplates, releaseQuery) => {
|
|
|
81
77
|
}
|
|
82
78
|
const jql = await render(template, data, { async: true });
|
|
83
79
|
logger.info(`Fetching release notes for query \`${cyan(releaseQuery)}\``);
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
80
|
+
let issues;
|
|
81
|
+
try {
|
|
82
|
+
;
|
|
83
|
+
({ issues } = await xfetch(`https://jira.alauda.cn/rest/api/2/search?${new URLSearchParams({ jql })}`, { headers: { Authorization } }));
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
if (err instanceof ResponseError) {
|
|
87
|
+
logger.error(`Failed to fetch release notes for query \`${red(releaseQuery)}\` with status \`${err.response.status}\` and ${err.data ? `data ${JSON.stringify(data, null, 2)}` : `message \`${err.message}\``}`);
|
|
88
|
+
}
|
|
87
89
|
return;
|
|
88
90
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
return ['en', 'zh'].reduce((acc, lang) => Object.assign(acc, {
|
|
92
|
+
[lang]: issues.length
|
|
93
|
+
? {
|
|
94
|
+
type: 'list',
|
|
95
|
+
children: issuesToListItems(issues, lang),
|
|
96
|
+
}
|
|
97
|
+
: {
|
|
98
|
+
type: 'paragraph',
|
|
99
|
+
children: [
|
|
100
|
+
{
|
|
101
|
+
type: 'text',
|
|
102
|
+
value: NO_ISSUE_MAPPER[lang] || NO_ISSUE_MAPPER.en,
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
},
|
|
92
106
|
}), {});
|
|
93
107
|
};
|
|
94
108
|
export const resolveRelease = async (releaseTemplates, releaseQuery, lang) => {
|