chore: expand bot check diagnostics
This commit is contained in:
+12
-2
@@ -6,6 +6,13 @@ const httpsAgent = GITEA_SKIP_TLS_VERIFY ? new https.Agent({ rejectUnauthorized:
|
||||
const headers = () => ({ Authorization: `token ${GITEA_TOKEN}`, 'Content-Type': 'application/json' });
|
||||
const api = (path) => `${GITEA_SERVER_URL.replace(/\/$/, '')}/api/v1${path}`;
|
||||
|
||||
function extractCommitMessage(payload) {
|
||||
return payload?.message
|
||||
|| payload?.commit?.message
|
||||
|| payload?.commit?.commit?.message
|
||||
|| '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得 PR 的 Git Diff 內容,已自動排除 .gitea/ 資料夾。
|
||||
*/
|
||||
@@ -33,7 +40,9 @@ export async function getCommitMessageBySha(sha) {
|
||||
timeout: 30000,
|
||||
httpsAgent,
|
||||
});
|
||||
return resp.data?.message || '';
|
||||
const message = extractCommitMessage(resp.data);
|
||||
console.log(` 🔎 bot-check: commit api sha=${sha} keys=${Object.keys(resp.data || {}).join(',') || 'empty'} message=${message ? 'found' : 'empty'}`);
|
||||
return message;
|
||||
} catch (e) {
|
||||
console.log(` ⚠️ bot-check: 讀取 commit sha=${sha} 失敗: ${e.message}`);
|
||||
return '';
|
||||
@@ -49,6 +58,7 @@ export async function getBranchHeadCommitMessage(branch = PR_HEAD_BRANCH) {
|
||||
httpsAgent,
|
||||
});
|
||||
const sha = resp.data?.commit?.id || resp.data?.commit?.sha || '';
|
||||
console.log(` 🔎 bot-check: branch api branch=${branch} keys=${Object.keys(resp.data || {}).join(',') || 'empty'} sha=${sha || 'empty'} message=${extractCommitMessage(resp.data?.commit) ? 'found' : 'empty'}`);
|
||||
return await getCommitMessageBySha(sha);
|
||||
} catch (e) {
|
||||
console.log(` ⚠️ bot-check: 讀取 branch=${branch} head commit 失敗: ${e.message}`);
|
||||
@@ -57,7 +67,7 @@ export async function getBranchHeadCommitMessage(branch = PR_HEAD_BRANCH) {
|
||||
}
|
||||
|
||||
export async function shouldSkipBotCommit({ sha = PR_HEAD_SHA || process.env.GITHUB_SHA, branch = PR_HEAD_BRANCH } = {}) {
|
||||
console.log(` 🔎 bot-check: start sha=${sha || 'empty'} branch=${branch || 'empty'}`);
|
||||
console.log(` 🔎 bot-check: start PR_HEAD_SHA=${PR_HEAD_SHA || 'empty'} GITHUB_SHA=${process.env.GITHUB_SHA || 'empty'} sha=${sha || 'empty'} branch=${branch || 'empty'}`);
|
||||
|
||||
const shaMessage = await getCommitMessageBySha(sha);
|
||||
if (sha) {
|
||||
|
||||
Reference in New Issue
Block a user