-
Notifications
You must be signed in to change notification settings - Fork 298
Fix add_comment to handle discussion numbers via fallback to GraphQL #14125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -499,10 +499,88 @@ async function main(config = {}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const errorMessage = getErrorMessage(error); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Check if this is a 404 error (discussion/issue was deleted) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Check if this is a 404 error (discussion/issue was deleted or wrong type) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // @ts-expect-error - Error handling with optional chaining | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const is404 = error?.status === 404 || errorMessage.includes("404") || errorMessage.toLowerCase().includes("not found"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // If 404 and item_number was explicitly provided and we tried as issue/PR, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // retry as a discussion (the user may have provided a discussion number) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (is404 && !isDiscussion && item.item_number !== undefined && item.item_number !== null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| core.info(`Item #${itemNumber} not found as issue/PR, retrying as discussion...`); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Try to find and comment on the discussion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const discussionQuery = ` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| query($owner: String!, $repo: String!, $number: Int!) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| repository(owner: $owner, name: $repo) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| discussion(number: $number) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| `; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const queryResult = await github.graphql(discussionQuery, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| owner: repoParts.owner, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| repo: repoParts.repo, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| number: itemNumber, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const discussionId = queryResult?.repository?.discussion?.id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!discussionId) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Error(`Discussion #${itemNumber} not found in ${itemRepo}`); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| core.info(`Found discussion #${itemNumber}, adding comment...`); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const comment = await commentOnDiscussion(github, repoParts.owner, repoParts.repo, itemNumber, processedBody, null); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+512
to
+535
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Try to find and comment on the discussion | |
| const discussionQuery = ` | |
| query($owner: String!, $repo: String!, $number: Int!) { | |
| repository(owner: $owner, name: $repo) { | |
| discussion(number: $number) { | |
| id | |
| } | |
| } | |
| } | |
| `; | |
| const queryResult = await github.graphql(discussionQuery, { | |
| owner: repoParts.owner, | |
| repo: repoParts.repo, | |
| number: itemNumber, | |
| }); | |
| const discussionId = queryResult?.repository?.discussion?.id; | |
| if (!discussionId) { | |
| throw new Error(`Discussion #${itemNumber} not found in ${itemRepo}`); | |
| } | |
| core.info(`Found discussion #${itemNumber}, adding comment...`); | |
| const comment = await commentOnDiscussion(github, repoParts.owner, repoParts.repo, itemNumber, processedBody, null); | |
| core.info(`Attempting to add comment to discussion #${itemNumber}...`); | |
| const comment = await commentOnDiscussion( | |
| github, | |
| repoParts.owner, | |
| repoParts.repo, | |
| itemNumber, | |
| processedBody, | |
| null | |
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fallback logic does not respect the
hide-older-commentsconfiguration. When a 404 occurs and the code retries as a discussion, it directly adds the comment without callinghideOlderComments. This means that ifhide-older-commentsis enabled and the fallback succeeds, older comments won't be hidden as expected. Consider callinghideOlderCommentsbefore adding the comment in the fallback path, similar to the primary flow at lines 433-437.