fix: use issue.number instead of issue.id in comment command #256

Closed
timstoop wants to merge 5 commits from timstoop/codeberg-cli:fix-issue-comment-404 into main
Contributor

Summary

Fixes #224 where berg issue comment returned a 404 error when the issue's internal database ID differed from its visible issue number.

Problem

The issue comment command was using issue.id (internal database ID) instead of issue.number (the visible issue number like #1, #2, etc.) when making the API call. The Forgejo API expects the issue number, not the internal ID.

When these values differ (which happens in repositories with closed/deleted issues), the API returns a 404 error.

Solution

Changed src/actions/issue/comment.rs:93 to use issue.number instead of issue.id, aligning with how other commands like issue edit already work.

Testing

  • The code compiles and passes cargo clippy
  • Manually verified the fix addresses the root cause
  • A test case has been added to main branch that would catch this regression

This fix aligns with the pattern used in other commands:

  • issue edit uses issue.number (line 76)
  • milestone view uses issue.number (line 106)

Closes #224

🤖 Generated with Claude Code

## Summary Fixes #224 where `berg issue comment` returned a 404 error when the issue's internal database ID differed from its visible issue number. ## Problem The `issue comment` command was using `issue.id` (internal database ID) instead of `issue.number` (the visible issue number like #1, #2, etc.) when making the API call. The Forgejo API expects the issue number, not the internal ID. When these values differ (which happens in repositories with closed/deleted issues), the API returns a 404 error. ## Solution Changed `src/actions/issue/comment.rs:93` to use `issue.number` instead of `issue.id`, aligning with how other commands like `issue edit` already work. ## Testing - The code compiles and passes cargo clippy - Manually verified the fix addresses the root cause - A test case has been added to main branch that would catch this regression ## Related This fix aligns with the pattern used in other commands: - `issue edit` uses `issue.number` (line 76) - `milestone view` uses `issue.number` (line 106) Closes #224 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Fixes #224 where commenting on issues returned a 404 error when the
issue's internal database ID differed from its visible issue number.

The Forgejo API expects the issue number (e.g., #1, #2) not the
internal ID. This aligns with how other commands like `issue edit`
already work.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Fixes the same ID vs number bug in `berg issue view --comments` that
was fixed for `berg issue comment` in the previous commit. The view
command was using issue.id instead of issue.number in two places:

1. Line 88: JSON output mode with --comments flag
2. Line 144: Pretty output mode with --comments flag

Both now correctly use issue.number to align with the Forgejo API
expectations.

Also adds test case `issueViewCommentsWithDifferentIdAndNumber` to
verify the fix works correctly when issue ID differs from issue number.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Author
Contributor

While reviewing the codebase, we found the same bug in berg issue view --comments (both JSON and Pretty output modes). The view command was also using issue.id instead of issue.number when fetching comments.

Since this is the exact same root cause (API expects issue numbers, not internal database IDs), I've added the fix to this PR along with a test case that would have caught both bugs.

Changes in the latest commit:

  • Fixed src/actions/issue/view.rs:88 (JSON output mode)
  • Fixed src/actions/issue/view.rs:144 (Pretty output mode)
  • Added test issueViewCommentsWithDifferentIdAndNumber
While reviewing the codebase, we found the same bug in `berg issue view --comments` (both JSON and Pretty output modes). The view command was also using `issue.id` instead of `issue.number` when fetching comments. Since this is the exact same root cause (API expects issue numbers, not internal database IDs), I've added the fix to this PR along with a test case that would have caught both bugs. Changes in the latest commit: - Fixed `src/actions/issue/view.rs:88` (JSON output mode) - Fixed `src/actions/issue/view.rs:144` (Pretty output mode) - Added test `issueViewCommentsWithDifferentIdAndNumber`
Resolved conflict in src/actions/issue/view.rs:
- Kept upstream's simplified owner_repo() call
- Kept PR's fix using issue.number instead of issue.id
Per feedback on PR #255, keeping PRs focused on single fixes.
The view.rs fixes will be moved to a separate PR.
Author
Contributor

Split the fix for view.rs off into its own branch, to keep the reviewing as focussed as possible.

Split the fix for view.rs off into its own branch, to keep the reviewing as focussed as possible.
Owner

Sorry for how this went here. I just now realize that you also tackled the issue. I was writing a test which could properly reproduce the issue since this was non trivial. The fix itself is now already merged!

Sorry for how this went here. I just now realize that you also tackled the issue. I was writing a test which could properly reproduce the issue since this was non trivial. The fix itself is now already merged!
Aviac closed this pull request 2025-10-13 19:25:20 +02:00

Pull request closed

Sign in to join this conversation.
No description provided.