Skip to content

Commit ba65494

Browse files
committed
fix: .gitignore
1 parent 577d63f commit ba65494

File tree

2 files changed

+56
-25
lines changed

2 files changed

+56
-25
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.DS_Store
22
node_modules
33
package-lock.json
4+
**/.docc-build

add_issue.js

Lines changed: 55 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
const axios = require('axios');
2+
const fs = require('fs').promises;
23

34
// GitHub API 配置
45
const API_URL = "https://api.github.com";
56
const REPO_OWNER = "SwiftGGTeam";
67
const REPO_NAME = "the-swift-programming-language-in-chinese";
78
const BRANCH = "swift-6-beta-translation";
89

9-
// TODO: 请在运行脚本之前设置您的个人访问令牌
10+
// 您的个人访问令牌
1011
const TOKEN = process.env.GITHUB_TOKEN;
1112

1213
// 设置请求头
@@ -28,24 +29,24 @@ async function getExistingIssues() {
2829
return issues;
2930
}
3031

31-
async function createIssue(title, body, labels, retries = 3) {
32-
for (let i = 0; i < retries; i++) {
33-
try {
34-
const url = `${API_URL}/repos/${REPO_OWNER}/${REPO_NAME}/issues`;
35-
const data = { title, body, labels };
36-
const response = await axios.post(url, data, { headers });
32+
async function createIssue(title, body, labels) {
33+
try {
34+
const url = `${API_URL}/repos/${REPO_OWNER}/${REPO_NAME}/issues`;
35+
const data = { title, body, labels };
36+
const response = await axios.post(url, data, { headers });
3737

38-
if (response.status === 201) {
39-
console.log(`Issue created successfully: ${title}`);
40-
return response.data;
41-
}
42-
} catch (error) {
43-
console.error(`Error creating issue (attempt ${i + 1}):`, error.message);
44-
if (i === retries - 1) throw error;
45-
await new Promise(resolve => setTimeout(resolve, 1000 * (i + 1))); // 等待时间递增
38+
if (response.status === 201) {
39+
console.log(`Issue created successfully: ${title}`);
40+
return response.data;
41+
} else {
42+
console.log(`Failed to create issue: ${response.status}`);
43+
console.log(response.data);
44+
return null;
4645
}
46+
} catch (error) {
47+
console.error("Error creating issue:", error.message);
48+
return null;
4749
}
48-
return null;
4950
}
5051

5152
async function getFilesInDirectory(path) {
@@ -64,27 +65,56 @@ async function getFilesInDirectory(path) {
6465
}
6566
}
6667

67-
function formatIssueTitle(filePath) {
68+
function formatIssueTitle(filePath, estimatedTime) {
6869
const parts = filePath.split('/');
69-
const fileName = parts.pop().toLowerCase().replace('.md', '');
70+
const fileName = parts.pop().toLowerCase();
7071
const folderName = parts[parts.length - 1];
71-
return `${folderName} / ${fileName}.md`;
72+
73+
// Convert camelCase or PascalCase to kebab-case
74+
const kebabFileName = fileName
75+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
76+
.replace(/([A-Z])([A-Z][a-z])/g, '$1-$2')
77+
.toLowerCase();
78+
79+
return `${folderName} / ${kebabFileName} ${estimatedTime}`;
7280
}
7381

7482
function formatIssueBody(filePath) {
7583
const fileUrl = `https://github.com/${REPO_OWNER}/${REPO_NAME}/blob/${BRANCH}/${filePath}`;
7684
return `翻译文件:${fileUrl}\n请在认领任务前查看 Markdown 文件内容,并了解对应的 Swift 原文档链接和翻译预估时长`;
7785
}
7886

87+
async function getFileContent(filePath) {
88+
try {
89+
const url = `${API_URL}/repos/${REPO_OWNER}/${REPO_NAME}/contents/${filePath}?ref=${BRANCH}`;
90+
const response = await axios.get(url, { headers });
91+
if (response.status === 200) {
92+
return Buffer.from(response.data.content, 'base64').toString('utf-8');
93+
}
94+
} catch (error) {
95+
console.error(`Error getting file content: ${error.message}`);
96+
}
97+
return null;
98+
}
99+
100+
function extractEstimatedTime(content) {
101+
const match = content.match(/(.*)/);
102+
return match ? match[1].trim() : '';
103+
}
104+
79105
async function processDirectory(path, existingIssues) {
80106
const files = await getFilesInDirectory(path);
81107
for (const file of files) {
82-
const issueTitle = formatIssueTitle(file.path);
83-
if (!existingIssues.has(issueTitle)) {
84-
const issueBody = formatIssueBody(file.path);
85-
await createIssue(issueTitle, issueBody, ["Swift 6 beta translation"]);
86-
} else {
87-
console.log(`Issue already exists: ${issueTitle}`);
108+
const content = await getFileContent(file.path);
109+
if (content) {
110+
const estimatedTime = extractEstimatedTime(content);
111+
const issueTitle = formatIssueTitle(file.path, estimatedTime);
112+
if (!existingIssues.has(issueTitle)) {
113+
const issueBody = formatIssueBody(file.path);
114+
await createIssue(issueTitle, issueBody, ["Swift 6 beta translation"]);
115+
} else {
116+
console.log(`Issue already exists: ${issueTitle}`);
117+
}
88118
}
89119
}
90120
}

0 commit comments

Comments
 (0)