Fix NoMethodError by using Octokit's add_label to create missing labels - #25
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Replace the
@client.create_label(@repo, label, "0075ca")call inGitHubClient#ensure_labelswith@client.add_label(...).Why
create_labelis not a method onOctokit::Clientin Octokit 10 (the version bundled by this action), so whenever the action tried to create a missing label it raised:Octokit's method for creating a repository label is
add_label(repo, label, color)(maps toPOST /repos/{owner}/{repo}/labels).Backwards compatibility
Checked Octokit 9.2.0 and 10.0.0 sources — both define
add_labeland neither definescreate_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_labelstests now mockadd_labelinstead ofcreate_label. Verified the updated tests fail against the old code (unmockedcreate_labelerror) and pass with the fix.bundle exec rake test— 133 runs, 0 failuresbundle exec standardrb— clean