Sync assigned user from Github
We need to sync the issues assigned to users from Github, so when someone is assigned to Github, the user assigned should be assigned on Gitpay as well. And we expect that the user is notified about this change by email.
We have two scenarios:
- User assigned on Github is registered on Gitpay
- User assigned on Github is not registered on Gitpay
The email should follow this template:
When the given user assigned on Github is registered on Gitpay
Hello {{name}},
The issue {{title}} - {{url}} was assigned to {{userAssigned}} on Github ({{GithubUrl}}), so he was assigned on Gitpay too.
Thanks,
Gitpay Team
----------------------
https://gitpay.me (Web)
[email protected] (Email)
Worknenjoy Inc., 2035 Sunset Lake Road #Suite B-2, Newark, DE 19702 (Mail)
When user assigned on Github is not registered on Gitpay
Hello {{name}},
The issue {{title}} - {{url}} was assigned to {{userAssigned}} on Github ({{GithubUrl}}), and this user is not registered on Gitpay.
Thanks,
Gitpay Team
----------------------
https://gitpay.me (Web)
[email protected] (Email)
Worknenjoy Inc., 2035 Sunset Lake Road #Suite B-2, Newark, DE 19702 (Mail)
Why
Synchronize to reflect the assigned from Github. So when an issue is closed we close on Gitpay too. But the user would be notified by e-mail that change.
Level
Beginner
How to solve this issue
- You will have to receive the changes from Webhooks events on Github
- These events would make a request to our Gitpay webhooks routes, and you can create automated tests to emulate requests from these webhooks
- Then update the task model assigned user
How to reproduce the user scenario
- Create a new user
- Import a new issue
- Close original issue on Github
- The issue should be set to finish on Gitpay
Tips
Important things to know to better find the solution for this task
I guess using cronjobs are not the best way. How about using github webhooks and we get an update of every time an issue is created? If I am implementing with cronjobs I will have to check the db state everyday and change for each change (remove, added, updated), the email message will take a day to arrive and a lot of others problems.
I guess the emit would be the way to go. What are your thoughts on this matter?
thanks @iwaduarte for the suggest, actually you're right, and after some investigation, we will have issues with the limit of request to Github API, once we have thousand of issues to check. So webhooks will be the best option and I updated the issue.
Could you assign that task to me ? I will do it. 👍
Yes @iwaduarte , I assigned you to it, thanks 🙏
@iwaduarte We will need a script to run the check of status on the existing ones
@alexanmtz
There are few problems with that implementation.
The issue payload does not provide an email but a login field. I guess that would not suffice since we are enabling email notifications.
I haven't thought before but I would guess email is a protected field and to prevent spam Github would prevent the API from disclosing via requests/hooks methods.
I guess in order to assign somebody the steps would be:
Not registered user wants to take on a Task
- It must create a gitpay account in order to contribute
- A github field in the User Model called github_login is created in that process
- Now the link between the two platforms are provided.
Registered user wants to take on a Task
If working from the gitpay platform that would be a simple API request.
If working from the github platform the web hook would find a user as:
const assigneeLogin = response.assignees[0].login
const user = await models.User.findOne({ where: { github_login: assigneeLogin } });
and send an email from there.
tl;dr
Structural changes are needed in order to implement this issue/feature:
- update the user Model to include a github login.
Also I imho this is not a beginner task.
What is you take on that?
Cheers
Hello @iwaduarte , thanks for all your considerations, yeah, I moved the issue to a medium level, and let's just cover the case when the user is actually on Gitpay, and yeah, we need a login field, as we support Bitbucket too and this is a generic solution, we should add provider_login field. We have the provider field so we know if is a Github, so we could use that combined information.
@alexanmtz What do you mean by the user is actually on Gitpay? Could you give an example?
What does the provider field contains?
@iwaduarte, I mean the first scenario, that the user assigned on Github is registered on Gitpay, and vice-versa. The provider contains the values github or bitbucket, which correspond if this user is connected on Github or Bitbucket.
@alexanmtz Is the username the same ? Look at my problem there. How do I know that userAXAS (github_login) is AXASuser(gitpay_login) ? Which field connects both platforms?
You're right @iwaduarte, we will need something like provider_username field. We don't have username/login today. we will check the field provider(we have this today) with the value of github and the provider_username (we don't have this field today).
@alexanmtz So you will need to update the database before we could tackle on that issue. Right?
Yes @iwaduarte, you can create a migration like the ones we have today and add the new field, and update the model.
Using Sequelize you can do it like this example:
sequelize migration:generate --name add-login-from-provider-to-user
It's a little bit more complicated. We need to review this one and create another related issue, so we will close for now