After taking part in 30 days of code, AKINJOBI Sodiq asked us, backend participants, to use the GitHub API to create a web app that can send invitations to GitHub users to join GitHub organizations. At the end of the project, I came up with different working versions of the same GitHub-Invite which are:
- Node Monolith Version
- Static Frontend Version
- NPM package
Why I made GitHub-Invite
To me, it first sounded unreasonable. After all, the moment you create an organization on GitHub, GitHub directly gives you the ability to invite members to that organization based on their emails or GitHub username. However, two things changed my mind:
- Someone requested it, Others may need it. I felt because AKINJOBI Sodiq needed it, it will do good to help him. Besides, not just him, but any other person that will ever need such a tool.
- Command-Line version
I saw the above tweet and loved the fact that for once, one could create a GitHub repo directly from the command line, without having to open a browser and I felt it could be the same for inviting members to a GitHub organization. Besides, some developers extensively use the command line, so the github-invite
’s npm package could help them.
Demanding access tokens
GitHub deprecating username/password authentication for API calls in favor of personal access tokens or OAuth tokens left me with no choice than to use tokens to make invitations in the GitHub-Invite project. I decided to use personal access tokens since any GitHub user can easily create one from their account settings at https://github.com/settings/tokens/new
Note: Personal Access Token used to make invitations through GitHub-Invite must have at least the admin:org permission, and it must be the token of an admin since only admins/owners can invite other members to a GitHub organization.
Node Monolith Version
So I began the GitHub-Invite project with the usual NodeJS/Express server for the web app, made its frontend, and published it on GitHub.
It has its benefits and drawbacks
- Pros: I made the frontend to be served to GitHub users that were to become members of an organization. It read ‘Get Invited’. The user enters their username and will receive an email from GitHub, all things being equal, and the app will tell them to check their inbox.
This monolith server version could be set up by some IT administrator and they could give the link to the necessary members.
- Cons: Was it really a disadvantage? Probably only to those that would find it demanding to host monolith servers instead of static files. Besides, it is a growing trend that JavaScript and APIs or JAMSTACK are preferred to monolith, server-run web apps. I knew no easier way to demand the admin’s access token in the server than by importing as a dependency. One has to add an
org.js
file that exports the organization’s name and admin’s token for the server to accept usernames and send invitations.
Static Frontend Version
The above led to the next version. I brought the invitation logic to the frontend, added more styles, made sure it was mobile responsive, and then published it on GitHub. Besides, it was made of static files, so I could host it with GitHub pages at https://obumnwabude.github.io/github-invite/
All I did was to rename the folder containing this version to docs
and then enable hosting from the folder in the repo settings. There is no analytics or third-party tool attached to ensure tokens are not stolen. GitHub pages are served with HTTPS, so security is assured. What I love most about this version, is the fact that it is mobile responsive, who knows any could access directly from their phone.
The NPM package
For me, this was the killer. Like I said earlier, Samson’s tweet about repo-gen
was a motivation to making a command-line interface for GitHub-Invite. To use it, make sure Node/NPM is installed on your computer, if not download it from https://nodejs.org and install it. Then run the following commands in the command line:
npm i -g github-invite
Then perform your invitation. Feel free to either use this tool interactively by typing github-invite
and pressing enter
github-invite
OR
Feeding in all the required arguments at the same time:
github-invite <org> <username> <token>
As need may arise, the help is always there to guide you, just type
github-invite –h
I learned a lot while creating this package. It is actually my first package on NPM and I can say creating and publishing npm packages is easy. I used Chalk to make the feedback colorful and use Inquirer to make github-invite
interactive.
I made sure I handled errors and gave proper feedback were possible both in this NPM package and the web apps mentioned earlier.
Check out the NPM package github-invite
at https://npmjs.com/package/github-invite
Check out the static frontend version at https://obumnwabude.github.io/github-invite
Check out the code of GitHub-Invite at https://github.com/obumnwabude/github-invite/