Skip to content

Commit fd83bc5

Browse files
committed
fix: 修复Issue和PR创建时URL长度过大的问题,改用剪贴板复制YAML内容
1 parent 9def5fb commit fd83bc5

File tree

1 file changed

+48
-28
lines changed

1 file changed

+48
-28
lines changed

src/components/ChallengeContributePage/components/YamlPreviewSection.tsx

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,30 @@ const YamlPreviewSection: React.FC<YamlPreviewSectionProps> = ({
7575

7676
const challengeName = extractChallengeName();
7777

78-
// 准备PR内容
79-
const title = encodeURIComponent(`新增题目: ${challengeName}`);
80-
const body = encodeURIComponent(
81-
`## 新增题目\n\n` +
82-
`提交一个新的挑战题目。\n\n` +
83-
`### YAML代码\n\n` +
84-
`\`\`\`yaml\n${yamlOutput}\n\`\`\``
85-
);
86-
87-
// 构建PR创建URL
88-
const prUrl = `${GITHUB_BASE_URL}/compare/main...?quick_pull=1&title=${title}&body=${body}`;
89-
90-
// 在新标签页中打开
91-
window.open(prUrl, '_blank');
78+
// 使用navigator.clipboard API复制YAML到剪贴板
79+
navigator.clipboard.writeText(yamlOutput)
80+
.then(() => {
81+
message.success('YAML已复制到剪贴板,请在GitHub中粘贴');
82+
83+
// 准备PR标题和基本说明
84+
const title = encodeURIComponent(`新增题目: ${challengeName}`);
85+
const body = encodeURIComponent(
86+
`## 新增题目\n\n` +
87+
`提交一个新的挑战题目。\n\n` +
88+
`### YAML代码\n\n` +
89+
`<!-- 请在此处粘贴YAML代码 -->`
90+
);
91+
92+
// 构建PR创建URL
93+
const prUrl = `${GITHUB_BASE_URL}/compare/main...?quick_pull=1&title=${title}&body=${body}`;
94+
95+
// 在新标签页中打开
96+
window.open(prUrl, '_blank');
97+
})
98+
.catch((error) => {
99+
console.error('复制YAML失败:', error);
100+
message.error('复制YAML失败,请手动复制后提交');
101+
});
92102
};
93103

94104
// 创建Issue
@@ -100,20 +110,30 @@ const YamlPreviewSection: React.FC<YamlPreviewSectionProps> = ({
100110

101111
const challengeName = extractChallengeName();
102112

103-
// 准备Issue内容
104-
const title = encodeURIComponent(`题目请求: ${challengeName}`);
105-
const body = encodeURIComponent(
106-
`## 题目请求\n\n` +
107-
`请求添加以下挑战题目。\n\n` +
108-
`### YAML代码\n\n` +
109-
`\`\`\`yaml\n${yamlOutput}\n\`\`\``
110-
);
111-
112-
// 构建Issue创建URL
113-
const issueUrl = `${GITHUB_BASE_URL}/issues/new?title=${title}&body=${body}`;
114-
115-
// 在新标签页中打开
116-
window.open(issueUrl, '_blank');
113+
// 使用navigator.clipboard API复制YAML到剪贴板
114+
navigator.clipboard.writeText(yamlOutput)
115+
.then(() => {
116+
message.success('YAML已复制到剪贴板,请在GitHub中粘贴');
117+
118+
// 准备Issue标题和基本说明
119+
const title = encodeURIComponent(`题目请求: ${challengeName}`);
120+
const body = encodeURIComponent(
121+
`## 题目请求\n\n` +
122+
`请求添加以下挑战题目。\n\n` +
123+
`### YAML代码\n\n` +
124+
`<!-- 请在此处粘贴YAML代码 -->`
125+
);
126+
127+
// 构建Issue创建URL (使用简短参数)
128+
const issueUrl = `${GITHUB_BASE_URL}/issues/new?title=${title}&body=${body}`;
129+
130+
// 在新标签页中打开
131+
window.open(issueUrl, '_blank');
132+
})
133+
.catch((error) => {
134+
console.error('复制YAML失败:', error);
135+
message.error('复制YAML失败,请手动复制后提交');
136+
});
117137
};
118138

119139
return (

0 commit comments

Comments
 (0)