fix(storage): persist close_reason to issues table on close (#551)

CloseIssue was storing the reason only in the events table, not in the
issues.close_reason column. This caused `bd show --json` to return an
empty close_reason even when one was provided.

- Update CloseIssue in queries.go and transaction.go to set close_reason
- Clear close_reason when reopening issues (in manageClosedAt)
- Add tests for close_reason in storage and CLI JSON output
- Document the dual-storage of close_reason (issues + events tables)
This commit is contained in:
cbro
2025-12-14 17:18:01 -05:00
committed by GitHub
parent 3a4da4e08d
commit 2651620a4c
5 changed files with 31 additions and 7 deletions

View File

@@ -706,6 +706,10 @@ func TestCloseIssue(t *testing.T) {
if closed.ClosedAt == nil {
t.Error("ClosedAt should be set")
}
if closed.CloseReason != "Done" {
t.Errorf("CloseReason not set: got %q, want %q", closed.CloseReason, "Done")
}
}
func TestClosedAtInvariant(t *testing.T) {
@@ -766,7 +770,7 @@ func TestClosedAtInvariant(t *testing.T) {
t.Fatalf("CloseIssue failed: %v", err)
}
// Verify it's closed with closed_at set
// Verify it's closed with closed_at and close_reason set
closed, err := store.GetIssue(ctx, issue.ID)
if err != nil {
t.Fatalf("GetIssue failed: %v", err)
@@ -774,6 +778,9 @@ func TestClosedAtInvariant(t *testing.T) {
if closed.ClosedAt == nil {
t.Fatal("ClosedAt should be set after closing")
}
if closed.CloseReason != "Done" {
t.Errorf("CloseReason should be 'Done', got %q", closed.CloseReason)
}
// Reopen the issue
updates := map[string]interface{}{
@@ -784,7 +791,7 @@ func TestClosedAtInvariant(t *testing.T) {
t.Fatalf("UpdateIssue failed: %v", err)
}
// Verify closed_at was cleared
// Verify closed_at and close_reason were cleared
reopened, err := store.GetIssue(ctx, issue.ID)
if err != nil {
t.Fatalf("GetIssue failed: %v", err)
@@ -795,6 +802,9 @@ func TestClosedAtInvariant(t *testing.T) {
if reopened.ClosedAt != nil {
t.Error("ClosedAt should be cleared when reopening issue")
}
if reopened.CloseReason != "" {
t.Errorf("CloseReason should be cleared when reopening issue, got %q", reopened.CloseReason)
}
})
t.Run("CreateIssue rejects closed issue without closed_at", func(t *testing.T) {