[add] 新增填入issue
This commit is contained in:
parent
00045b3c8c
commit
3f363c9a3c
48
index.html
48
index.html
@ -49,8 +49,7 @@
|
||||
<div id="log"></div>
|
||||
|
||||
<script>
|
||||
const accessToken = "587f612b5cdbf59bfa6ebb8e082109a6aa26d435";
|
||||
// https://dash.cloudflare.com/361c3fb1feb10c54c262c3872c51a3a5/workers/services/view/cors-anywhere/production/metrics
|
||||
const accessToken = "96ed6b6d33931b122c7f12f94153594be0d75b32";
|
||||
const proxy = "https://cors-anywhere.bir840124.workers.dev/?url=";
|
||||
const giteaAPIBase = "https://git.catan.com.tw/api/v1";
|
||||
|
||||
@ -60,9 +59,9 @@
|
||||
logBox.scrollTop = logBox.scrollHeight;
|
||||
}
|
||||
|
||||
// 建立儲存庫功能(維持不變)
|
||||
// 建立儲存庫功能
|
||||
async function loadAndCreateRepos() {
|
||||
logBox.textContent = ""; // 清空 log
|
||||
logBox.textContent = "";
|
||||
const orgInput = document.getElementById("orgInput").value.trim();
|
||||
if (!orgInput) {
|
||||
alert("請輸入組織名稱");
|
||||
@ -134,6 +133,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 新增:建立 Issue
|
||||
if (repo.issue) {
|
||||
await createIssue(repo.org, repo.name, repo.issue);
|
||||
}
|
||||
|
||||
} else {
|
||||
log(`⚠️ 建立失敗:${repo.org}/${repo.name} - ${data.message}`);
|
||||
}
|
||||
@ -143,6 +147,34 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function createIssue(org, repoName, issue) {
|
||||
const url = `${giteaAPIBase}/repos/${org}/${repoName}/issues`;
|
||||
const payload = {
|
||||
title: issue.title || "",
|
||||
body: issue.content || ""
|
||||
};
|
||||
|
||||
try {
|
||||
const res = await fetch(proxy + url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": `token ${accessToken}`
|
||||
},
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
log(`📌 已建立 Issue:${issue.title}`);
|
||||
} else {
|
||||
const data = await res.json();
|
||||
log(`⚠️ 建立 Issue 失敗:${data.message || res.statusText}`);
|
||||
}
|
||||
} catch (err) {
|
||||
log(`❌ 建立 Issue 錯誤:${err.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function addTeamToRepo(org, repo, teamName) {
|
||||
const teamsURL = `${giteaAPIBase}/orgs/${org}/teams`;
|
||||
const teamRes = await fetch(proxy + teamsURL, {
|
||||
@ -169,9 +201,9 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 新增:創建團隊功能
|
||||
// 創建團隊功能
|
||||
async function loadAndCreateTeams() {
|
||||
logBox.textContent = ""; // 清空 log
|
||||
logBox.textContent = "";
|
||||
const orgInput = document.getElementById("orgInput").value.trim();
|
||||
if (!orgInput) {
|
||||
alert("請輸入組織名稱");
|
||||
@ -180,7 +212,6 @@
|
||||
log(`✅ 開始建立團隊:${orgInput}`);
|
||||
|
||||
try {
|
||||
// 載入 teams.json
|
||||
const res = await fetch("teams.json");
|
||||
const teamList = await res.json();
|
||||
|
||||
@ -234,7 +265,6 @@
|
||||
} catch (err) {
|
||||
log(`❌ 團隊建立錯誤:${team.name} - ${err.message}`);
|
||||
}
|
||||
// await delay(1000); // 每次請求間隔 1 秒,避免 rate limit
|
||||
}
|
||||
|
||||
async function addMemberToTeam(teamId, username) {
|
||||
@ -255,13 +285,11 @@
|
||||
} catch (err) {
|
||||
log(`❌ 新增成員錯誤:${username} - ${err.message}`);
|
||||
}
|
||||
// await delay(500);
|
||||
}
|
||||
|
||||
async function delay(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
16
repos.json
16
repos.json
@ -28,6 +28,10 @@
|
||||
"name": "Official-B2B",
|
||||
"description": "官網-廠商串接(前端寫入)",
|
||||
"default_branch": "master",
|
||||
"issue": {
|
||||
"title": "Update code B2B",
|
||||
"content": "{\"platform\":\"待填入\",\"env\":\"b2b\",\"action\":\"updateCode\"}"
|
||||
},
|
||||
"teams": [
|
||||
"FrontendWrite"
|
||||
]
|
||||
@ -36,6 +40,10 @@
|
||||
"name": "Official-Out",
|
||||
"description": "官網-外版(前端寫入)",
|
||||
"default_branch": "master",
|
||||
"issue": {
|
||||
"title": "Update code OUT",
|
||||
"content": "{\"platform\":\"待填入\",\"env\":\"production\",\"action\":\"updateCode\"}"
|
||||
},
|
||||
"teams": [
|
||||
"FrontendWrite"
|
||||
]
|
||||
@ -90,6 +98,10 @@
|
||||
"name": "Resource-B2B",
|
||||
"description": "外載資源-廠商串接(前端寫入)",
|
||||
"default_branch": "master",
|
||||
"issue": {
|
||||
"title": "Update code B2B",
|
||||
"content": "{\"platform\":\"待填入\",\"env\":\"b2b\",\"action\":\"updateCode\"}"
|
||||
},
|
||||
"teams": [
|
||||
"FrontendWrite",
|
||||
"PlanWrite"
|
||||
@ -99,6 +111,10 @@
|
||||
"name": "Resource-Out",
|
||||
"description": "外載資源-外版(前端寫入)",
|
||||
"default_branch": "master",
|
||||
"issue": {
|
||||
"title": "Update code OUT",
|
||||
"content": "{\"platform\":\"待填入\",\"env\":\"production\",\"action\":\"updateCode\"}"
|
||||
},
|
||||
"teams": [
|
||||
"FrontendWrite"
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user