Skip to content

Commit 2d1482b

Browse files
iHiDclaude
andauthored
Truncate GitHub issue titles to prevent ValueTooLong error (#8370) (#8416)
The github_issues.title column is VARCHAR(255) but GitHub issue titles can exceed that length, causing ActiveRecord::ValueTooLong errors. Truncate to 255 characters before saving. Also update /fix skill to use local worktrees/ directory and add it to .gitignore. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 741e5e7 commit 2d1482b

4 files changed

Lines changed: 26 additions & 4 deletions

File tree

.claude/skills/fix/SKILL.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Only create the worktree **after the plan is approved**. The issue number has be
6767

6868
```bash
6969
git pull --ff-only origin main
70+
mkdir -p worktrees
7071
git worktree add worktrees/fix-<issue-number> -b fix/<issue-number>
7172
cd worktrees/fix-<issue-number>
7273
```
@@ -78,7 +79,7 @@ ln -s /Users/iHiD/Code/exercism/website/node_modules node_modules
7879
ln -s /Users/iHiD/Code/exercism/website/.husky/_ .husky/_
7980
```
8081

81-
**Important:** After creating the worktree, `cd` into it immediately. All subsequent work (file edits, bash commands, tests) happens inside the worktree. The main repo stays untouched on its current branch.
82+
**CRITICAL:** You MUST `cd` into the worktree immediately after creating it. All subsequent work file reads, edits, bash commands, tests — MUST happen from inside the worktree directory using `cd worktrees/fix-<issue-number> && <command>` on every Bash call. Do NOT use absolute paths to the worktree from the main repo. The main repo stays untouched on its current branch.
8283

8384
### Step 4: Implement the fix
8485

@@ -138,6 +139,6 @@ cd /Users/iHiD/Code/exercism/website
138139
git worktree remove worktrees/fix-<issue-number>
139140
```
140141

141-
This removes the worktree directory and returns you to the main repo. The branch remains on the remote for the PR.
142+
This removes the worktree directory. The branch remains on the remote for the PR.
142143

143144
Report the PR URL to the user.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,6 @@ vendor/bundle/
6262

6363
# Claude local settings
6464
.claude/settings.local.json
65+
66+
# Git worktrees
67+
worktrees/

app/commands/github/issue/create_or_update.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Github::Issue::CreateOrUpdate
66
def call
77
issue = ::Github::Issue.create_or_find_by!(node_id:) do |i|
88
i.number = attributes[:number]
9-
i.title = attributes[:title]
9+
i.title = title
1010
i.status = status
1111
i.repo = attributes[:repo]
1212
i.opened_at = attributes[:opened_at]
@@ -17,7 +17,7 @@ def call
1717

1818
issue.update!(
1919
number: attributes[:number],
20-
title: attributes[:title],
20+
title:,
2121
status:,
2222
repo: attributes[:repo],
2323
opened_at: attributes[:opened_at],
@@ -35,6 +35,7 @@ def labels(issue)
3535
end
3636
end
3737

38+
def title = attributes[:title].to_s.truncate(255)
3839
def status = attributes[:state].downcase.to_sym
3940

4041
def log_metric!(issue)

test/commands/github/issue/create_or_update_test.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,23 @@ class Github::Issue::CreateOrUpdateTest < ActiveSupport::TestCase
6767
assert_nil issue.opened_by_username
6868
end
6969

70+
test "truncates title longer than 255 characters" do
71+
long_title = "a" * 300
72+
73+
issue = Github::Issue::CreateOrUpdate.(
74+
"MDU6SXNzdWU3MjM2MjUwMTI=",
75+
number: 999,
76+
title: long_title,
77+
state: "OPEN",
78+
repo: "exercism/ruby",
79+
labels: [],
80+
opened_at: Time.parse("2020-10-17T02:39:37Z").utc,
81+
opened_by_username: "SleeplessByte"
82+
)
83+
84+
assert_equal 255, issue.title.length
85+
end
86+
7087
test "update issue if data has changed" do
7188
issue = create :github_issue
7289

0 commit comments

Comments
 (0)