popomore / github-labels

Add github labels automatically
177 stars 20 forks source link

Token in dotfile breaks this without info when it has a newline at EOF #1

Closed henrahmagix closed 10 years ago

henrahmagix commented 10 years ago

If a user places a token in ~/.github-labels themselves, it's very likely there'll be a \n at the end when read into node as a string. With that \n, GitHub errors with Bad credentials.

This PR removes a trailing newline if it's there, then tests the token before moving on. If the token fails, more verbose errors are output.

In general, I think it's a good idea to always output the error message that GitHub returns so users are informed.

$: echo 'bad-token' > ~/.github-labels
$: labels -c ~/.config/github-labels/labels-api.json henrahmagix/labels-test
>> Authorizing
>> Token error
{"message":"Bad credentials","documentation_url":"https://developer.github.com/v3"}

Commit message:

Fix malformed token when \n is at the end.

  • When the token is read from the dotfile, sometimes it will have a newline at the end with which GitHub errors: Bad credentials. This does a string replace to remove newlines.
  • Test the token when being read from the dotfile before deciding everything is ok. Error if authentication fails.
  • Show GitHub error message when failing so the user understands what's going wrong.
popomore commented 10 years ago

Thx

henrahmagix commented 10 years ago

Thanks for merging!