From e4f7a4a748d2102a85ecacaea7dfcf0c55fc4b9a Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Mon, 20 Oct 2025 15:36:10 +0800 Subject: [PATCH 1/2] Fix CI Signed-off-by: Xuanwo --- .github/workflows/discussion-thread-link.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/discussion-thread-link.yml b/.github/workflows/discussion-thread-link.yml index 3399c836ee1e..655a8dcf421e 100644 --- a/.github/workflows/discussion-thread-link.yml +++ b/.github/workflows/discussion-thread-link.yml @@ -48,6 +48,8 @@ jobs: let discussion = context.payload.discussion || null; let number = discussion ? discussion.number : null; + let discussionRepoMismatch = false; + if (manualUrl) { const match = manualUrl.match(/github\.com\/([^/]+)\/([^/]+)\/discussions\/(\d+)/i); if (!match) { @@ -66,6 +68,9 @@ jobs: { owner, repo, number } ); discussion = data; + discussionRepoMismatch = + owner.toLowerCase() !== context.repo.owner.toLowerCase() || + repo.toLowerCase() !== context.repo.repo.toLowerCase(); } if (!discussion) { @@ -200,6 +205,15 @@ jobs: const threadUrl = `https://lists.apache.org/thread/${tid}`; + if (discussionRepoMismatch) { + core.warning( + `Discussion repository ${owner}/${repo} does not match workflow repository ` + + `${context.repo.owner}/${context.repo.repo}. Skipping PATCH.` + ); + core.info(`Computed thread URL: ${threadUrl}`); + return; + } + const { data: current } = await github.request( 'GET /repos/{owner}/{repo}/discussions/{number}', { owner, repo, number } From 10b070c03710813d3b2c675d7110103cbec843f8 Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Mon, 20 Oct 2025 15:48:47 +0800 Subject: [PATCH 2/2] Try fix Signed-off-by: Xuanwo --- .github/workflows/discussion-thread-link.yml | 49 ++++++++++++++++---- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/.github/workflows/discussion-thread-link.yml b/.github/workflows/discussion-thread-link.yml index 655a8dcf421e..021fed005079 100644 --- a/.github/workflows/discussion-thread-link.yml +++ b/.github/workflows/discussion-thread-link.yml @@ -64,8 +64,8 @@ jobs: return; } const { data } = await github.request( - 'GET /repos/{owner}/{repo}/discussions/{number}', - { owner, repo, number } + 'GET /repos/{owner}/{repo}/discussions/{discussion_number}', + { owner, repo, discussion_number: number } ); discussion = data; discussionRepoMismatch = @@ -215,8 +215,8 @@ jobs: } const { data: current } = await github.request( - 'GET /repos/{owner}/{repo}/discussions/{number}', - { owner, repo, number } + 'GET /repos/{owner}/{repo}/discussions/{discussion_number}', + { owner, repo, discussion_number: number } ); const body = current.body || ''; @@ -228,9 +228,42 @@ jobs: const separator = body.trim().length ? '\n\n' : ''; const newBody = `${body}${separator}---\n**Mailing list thread:** ${threadUrl}\n`; - await github.request( - 'PATCH /repos/{owner}/{repo}/discussions/{discussion_number}', - { owner, repo, discussion_number: number, body: newBody } - ); + let updated = false; + + try { + await github.request( + 'PATCH /repos/{owner}/{repo}/discussions/{discussion_number}', + { + owner, + repo, + discussion_number: number, + body: newBody, + headers: { 'X-GitHub-Api-Version': '2022-11-28' }, + } + ); + updated = true; + core.info('Updated discussion via REST API'); + } catch (error) { + const status = error && error.status ? error.status : 'unknown'; + core.info(`REST update failed with status ${status}, attempting GraphQL`); + if (status !== 403 && status !== 404) { + throw error; + } + } + + if (!updated) { + const mutation = ` + mutation ($discussionId: ID!, $body: String!) { + updateDiscussion(input: { discussionId: $discussionId, body: $body }) { + discussion { number } + } + } + `; + await github.graphql(mutation, { + discussionId: discussion.node_id, + body: newBody, + }); + core.info('Updated discussion via GraphQL'); + } core.info(`Appended ${threadUrl}`);