Skip to content

Fix NoMethodError by using Octokit's add_label to create missing labels - #25

Merged
neilvcarvalho merged 1 commit into
thoughtbot:mainfrom
elalemanyo:fix/octokit-add-label
Aug 3, 2026
Merged

Fix NoMethodError by using Octokit's add_label to create missing labels#25
neilvcarvalho merged 1 commit into
thoughtbot:mainfrom
elalemanyo:fix/octokit-add-label

Conversation

@elalemanyo

Copy link
Copy Markdown
Contributor

What

Replace the @client.create_label(@repo, label, "0075ca") call in GitHubClient#ensure_labels with @client.add_label(...).

Why

create_label is not a method on Octokit::Client in Octokit 10 (the version bundled by this action), so whenever the action tried to create a missing label it raised:

lib/github_client.rb:58:in 'block in ImportmapUpdate::GitHubClient#ensure_labels': undefined method 'create_label' for an instance of Octokit::Client (NoMethodError)

Octokit's method for creating a repository label is add_label(repo, label, color) (maps to POST /repos/{owner}/{repo}/labels).

Backwards compatibility

Checked Octokit 9.2.0 and 10.0.0 sources — both define add_label and neither defines create_label. So the fix is compatible with every Octokit version this action can resolve (the Gemfile pins no version), and the previous code was broken on Octokit 9 as well.

Test

The ensure_labels tests now mock add_label instead of create_label. Verified the updated tests fail against the old code (unmocked create_label error) and pass with the fix.

  • bundle exec rake test — 133 runs, 0 failures
  • bundle exec standardrb — clean

Octokit's method for creating a repository label is add_label, not
create_label. create_label never existed in Octokit 9 or 10, so calling
it raised NoMethodError whenever the action tried to create a missing
label.

add_label(repo, label, color) maps to POST /repos/{owner}/{repo}/labels
and is available in both Octokit 9.x and 10.x, so this fix is backwards
compatible across the versions the action bundles.

@neilvcarvalho neilvcarvalho left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@neilvcarvalho
neilvcarvalho merged commit 7cf20e7 into thoughtbot:main Aug 3, 2026
6 checks passed
@elalemanyo
elalemanyo deleted the fix/octokit-add-label branch August 3, 2026 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants