Giter VIP home page Giter VIP logo

Comments (22)

pengwynn avatar pengwynn commented on May 9, 2024

We should definitely catch that error instead of barfing, but could you let us know how you were authenticating?

from octokit.rb.

retorquere avatar retorquere commented on May 9, 2024

config[:login] = ...
config[:oauth_token] = ...

CLIENT = Octokit::Client.new(config)
REPO = "backlogs/redmine_backlogs"
....
CLIENT.replace_all_labels(REPO, issue.number, ['one', 'two'])

from octokit.rb.

retorquere avatar retorquere commented on May 9, 2024

But it throws a 404 error, not a 401 error. Maybe the server side of the GH API is broken? I've fetched the issue number using list_issues, and I've verified that it exists. And I'm the repo owner.

from octokit.rb.

pengwynn avatar pengwynn commented on May 9, 2024

Can you check the scope on that OAuth token? I suspect it might be public_repo and not repo scope.

from octokit.rb.

retorquere avatar retorquere commented on May 9, 2024

I apologize for having to ask this... but how do I so this? And how do I
generate a repo scope token?

from octokit.rb.

pengwynn avatar pengwynn commented on May 9, 2024

If you're using the Web flow for OAuth, simply declare what scopes you need as part of the initial request as outlined here.

If you're creating a stand alone non-web app for your own use and prefer not to use your username/pass on each request, you can create tokens via the Authorizations API.

from octokit.rb.

retorquere avatar retorquere commented on May 9, 2024

It's a stand-alone non-web app. Looking at that doc, should I be posting

{
"scopes": [ "backlogs/redmine_backlogs" ],
"note": "issue manager"
}

to get access to that repo? The docs are pretty scant.

from octokit.rb.

pengwynn avatar pengwynn commented on May 9, 2024

Try:

curl -i -u username -d '{"scopes": ["repo"], "note": "issue manager"}' https://api.github.com/authorizations

or you can use Octokit:

c = Octokit::Client.new :login => 'username', :password => 'password'
c.create_authorization :scopes => ['repo'], :note => 'issue manager'

from octokit.rb.

retorquere avatar retorquere commented on May 9, 2024

superb, thanks. The error is now

raise_octokit_error.rb:10:in `on_complete': PUT https://api.github.com/repos/backlogs/redmine_backlogs/issues/626/labels?access_token=blablabla: 400: Body should be a JSON Array (Octokit::BadRequest)

from octokit.rb.

pengwynn avatar pengwynn commented on May 9, 2024

Hrrm. It's working for me. Can you share your version of Ruby and Octokit?

from octokit.rb.

retorquere avatar retorquere commented on May 9, 2024

Octokit 1.7.0, ruby 1.8.7 and 1.9.3.

from octokit.rb.

retorquere avatar retorquere commented on May 9, 2024

Full trace:

raise_octokit_error.rb:10:in on_complete': PUT https://api.github.com/repos/backlogs/redmine_backlogs/issues/626/labels?access_token=blabla: 400: Body should be a JSON Array (Octokit::BadRequest) from /home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/faraday-0.8.1/lib/faraday/response.rb:9:incall'
from /home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/faraday-0.8.1/lib/faraday/response.rb:63:in on_complete' from /home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/faraday-0.8.1/lib/faraday/response.rb:8:incall'
from /home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/faraday_middleware-0.8.7/lib/faraday_middleware/request/encode_json.rb:21:in call' from /home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/faraday-0.8.1/lib/faraday/connection.rb:226:inrun_request'
from /home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/faraday-0.8.1/lib/faraday/connection.rb:99:in put' from /home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/octokit-1.7.0/lib/octokit/request.rb:40:insend'
from /home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/octokit-1.7.0/lib/octokit/request.rb:40:in request' from /home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/octokit-1.7.0/lib/octokit/request.rb:22:input'
from /home/hnse/.rvm/gems/ruby-1.8.7-p358@redmine/gems/octokit-1.7.0/lib/octokit/client/labels.rb:138:in `replace_all_labels'

from octokit.rb.

catsby avatar catsby commented on May 9, 2024

The labels you're sending in the labels array, do they already exist on the repo? I was able to reproduce this if I used labels that did not already exist, but if I supplied labels that did exist it worked fine.

from octokit.rb.

retorquere avatar retorquere commented on May 9, 2024

Some of the labels did not exist. But from reading the docs, replace_all_labels ought to add what didn't exist, right?

from octokit.rb.

catsby avatar catsby commented on May 9, 2024

I assumed that if they didn't exist they would be created, but the API documentation doesn't specify. @pengwynn Thoughts on that?

from octokit.rb.

pengwynn avatar pengwynn commented on May 9, 2024

Current behavior is to 422 if the label doesn't exist. I'm looking to see if we can change that, but for now, we need to fail gracefully in Octokit.

from octokit.rb.

pengwynn avatar pengwynn commented on May 9, 2024

I've updated the GitHub API to allow creating labels on-the-fly which should fix this issue. Please reopen if you're still seeing it.

from octokit.rb.

retorquere avatar retorquere commented on May 9, 2024

I don't have permission to re-open the issue. I currently get a "bad request" error:

/.rvm/gems/ruby-1.9.3-p194@redmine/gems/octokit-1.15.1/lib/faraday/response/raise_octokit_error.rb:10:in on_complete': PUT https://api.github.com/repos/backlogs/redmine_backlogs/issues/700/labels?access_token=2bd147935d6a3f1ab33c4ebd8ee6b3ce7688e33e: 400: Body should be a JSON Array (Octokit::BadRequest) from /home/hnse/.rvm/gems/ruby-1.9.3-p194@redmine/gems/faraday-0.8.4/lib/faraday/response.rb:9:inblock in call'
from /home/hnse/.rvm/gems/ruby-1.9.3-p194@redmine/gems/faraday-0.8.4/lib/faraday/response.rb:63:in on_complete' from /home/hnse/.rvm/gems/ruby-1.9.3-p194@redmine/gems/faraday-0.8.4/lib/faraday/response.rb:8:incall'
from /home/hnse/.rvm/gems/ruby-1.9.3-p194@redmine/gems/faraday_middleware-0.8.8/lib/faraday_middleware/request/encode_json.rb:23:in call' from /home/hnse/.rvm/gems/ruby-1.9.3-p194@redmine/gems/faraday-0.8.4/lib/faraday/connection.rb:226:inrun_request'
from /home/hnse/.rvm/gems/ruby-1.9.3-p194@redmine/gems/faraday-0.8.4/lib/faraday/connection.rb:99:in put' from /home/hnse/.rvm/gems/ruby-1.9.3-p194@redmine/gems/octokit-1.15.1/lib/octokit/request.rb:41:inrequest'
from /home/hnse/.rvm/gems/ruby-1.9.3-p194@redmine/gems/octokit-1.15.1/lib/octokit/request.rb:22:in put' from /home/hnse/.rvm/gems/ruby-1.9.3-p194@redmine/gems/octokit-1.15.1/lib/octokit/client/labels.rb:138:inreplace_all_labels'
from ./lib/tasks/manage-issues.rb:72:in `labels'

With line 72 reading
CLIENT.replace_all_labels(REPO, @issue.number, @labels) # @labels is an array of strings

from octokit.rb.

pengwynn avatar pengwynn commented on May 9, 2024

Since your token was included in the backtrace I reset it for you. Please treat those as you would a password.

I'm only able to reproduce this by passing an empty array []. Are you 100% sure @labels is populated?

from octokit.rb.

retorquere avatar retorquere commented on May 9, 2024

Yikes! Thanks. In some cases the array is empty, yes.

from octokit.rb.

retorquere avatar retorquere commented on May 9, 2024

Replacing replace_all with delete_all for empty labels list works!

from octokit.rb.

pengwynn avatar pengwynn commented on May 9, 2024

Awesome. It looks like the issue with [] is a GitHub API issue. I'm investigating.

Wynn Netherland

On Friday, October 5, 2012 at 8:51 AM, friflaj wrote:

Replacing replace_all with delete_all for empty labels list works!


Reply to this email directly or view it on GitHub (#104 (comment)).

from octokit.rb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.