-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[GITHUB]: connect #807
[GITHUB]: connect #807
Conversation
lib/code_corps/github.ex
Outdated
end | ||
|
||
defp update_user(%{github_id: _github_id} = github_info, user) do | ||
associate(user, github_info) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just pass the github_id
instead of the whole map?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean, pass into associate/2
? That would work for now, if that's the only thing we need to pass in. Later on, we might not have just the client ID but instead store a larger set of values, but we can worry about that when we come to it.
That being said, if associate already exists, and tests for it exist, no point i changing it now.
lib/code_corps/github.ex
Outdated
@token_url "" | ||
@client_id "" | ||
@client_secret "" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need help with these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
client_id
and _secret
will be environment variables which we will get when we register CodeCorps as a github application. It may even make sense not to have them as module variables, so we can inject them in tests.
Either way, assume the environment variables GITHUB_CLIENT_ID
and GITHUB_CLIENT_SECRET
exist, are loaded during config and stored into a config key.
For @token_url
, this should simply be https://github.com/login/oauth/access_token
Just looking for some initial feedback and help! Haven't looked at testing, b/c wanted to see first if going down the right path. |
@snewcomer I'm currently in the process of implementing the API key stuff as part of this PR, since, in order to do that, I need to work with Github API keys for CodeCorps. I'll try to implement it in a way so that tests will be reliable, but will not require other developers to provide API keys. Be sure to pull the latest before doing more work on this. I'll make sure to do the same. |
@snewcomer My commit still needs thorough testing and wrapping up, but I managed to get through the basic flow.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So guessing we can remove the tentacat dep? These changes look great!
lib/code_corps/github/api.ex
Outdated
} | ||
|
||
def connect(code) do | ||
with {:ok, %HTTPoison.Response{body: response}} <- code |> build_connect_params() |> do_connect(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@begedin Just curious on the reason not to use Tentacat.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had issues getting it to work. The documented methods do not work as documented. They also raise exceptions when they should not be doing so and are named without exclamation marks.
Due to that, for this specific case, I went with a direct API call.
For the regular stuff, in the integration milestone, we should go with Tentacat.
lib/code_corps/github.ex
Outdated
|> Tentacat.Client.new | ||
|> Tentacat.Users.me | ||
|> update_user(user) | ||
case code |> @api.connect do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I like this move to a separate module for testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comments that I think deserve some work before a merge.
do | ||
{:ok, access_token} | ||
else | ||
{:ok, %{"error" => error}} -> {:error, error} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit weird to me that this returns an :ok
tuple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, surprised a HTTPoison request with an error response would return an :ok
tuple, there should be a better way of differentiating a HTTPoison error and a response error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is what it is, though. Seems that github itself returns a 200 ok, with an error hash. Not much we can do about it, other than interpret it here.
use Ecto.Migration | ||
|
||
def change do | ||
rename table(:users), :github_id, to: :github_auth_token |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you no longer expecting to track the GitHub user ID? I would think this would be important information for us to have on-hand and indexed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not consider that. We'd need it as part of the integration feature. Technically, however, all the connect feature needs is the auth_token
.
I'll revert this change and make it so both fields are there.
web/models/user.ex
Outdated
@@ -97,8 +98,8 @@ defmodule CodeCorps.User do | |||
|
|||
def github_associate_changeset(struct, params) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not github_association
changeset, since it looks like this wants to be a noun and associate
in this case is verbed?
@snewcomer @begedin are we able to implement the above minor suggestions and then get this merged? |
0dc0c24
to
2c78d03
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joshsmith Made the changes, rebased and squashed. This ought to be good to merge.
I've added support for an optional parameter for the connect method, so we can explicityl inject a boundary module when testing. This allows really easy testing for various response cases and is advised to do in http://blog.plataformatec.com.br/2015/10/mocks-and-explicit-contracts/
This PR is meant to retrieving an access token for a user and updating the User record with their github_id.
Not sure where constants
@token_url
,@client_id
,@client_secret
come from.Progress on: #789