Standardization of Github Profiles using Go and Github Actions

Morgan Gomez
6 min readAug 16, 2021

--

Learn how to encourage uniformity in the profiles of users within your Github organization.

Image from github.com

About the Authors

Morgan Gomez is a Software Engineer at NCR Corporation. She is an Atlanta native who graduated from the Georgia Institute of Technology in 2021 with a degree in Computational Media.

Rohan Sanjay Shahane is a Software Engineer at NCR Corporation. He graduated from the University of Florida and his interests lie in backend and distributed systems.

Background

When working within a large Github organization, standardization across member profiles is essential. Knowing who you’re working with, and how to get in contact with them is helpful when collaborating with others. We often found ourselves wondering, who is user “mg123456”, and why did they make a change to this file? The same could be said any for any of the hundreds of Github accounts lacking basic profile information.

We wanted to encourage users to update their profiles to include their name and make their email visible to others within the organization. Our solution was an automated email program to notify users that they needed to update their account, with instructions on how to make the required changes.

Create an Automated Email Program using Go

Below is a breakdown of our task at hand:

  1. Generate a list of users within our organization who were missing their name, public email, or both in their Github profile.
  2. Send each user an email with instructions on how to update their profile.
  3. Use Feature Flags to test our code.
  4. Automate the email process to remind users several times a week until they have made the necessary updates to their profiles.
  5. Create a Slackbot to display a list of users who were unable to be sent an email automatically.

Filtering the Users

The first task in order to implement the standards across your organization is to fetch the data of all the users in your target organization and select those whose profiles need to be updated.

This was done using our GetUsersAndFilter() function, which uses the Github API to fetch user information and selects those whose profiles need updating. To implement this function, we used the ‘go-github’ package. This package provides a client for using GitHub API that we can use to query for all the members of our organization.

For more information on go-github, see below:

For each person, we check if they’re missing either name and/or public email. From there, we send the individual an email using the Compose_emails function.

At NCR, each employee has a unique 8 character ID, which also corresponds to their email. For most Github users, this ID was used to create their employee Github account, making it easy to send this ID into our Compose_emails function and append ‘@ncr.com’ to send an email.

However, some individuals set up their accounts with a different username, meaning we were not able to send them an email. To account for these cases, we created a SlackBot to notify us of those with invalid usernames so that we can message those users manually.

Sending mass emails using SendGrid

After gathering our users, we wanted to send each user an email with instructions on how to update their profile. Our Compose_emails function takes in three parameters: a string of the users email, a string determining the type of email to send, and finally, the type of platform (in this case, Github).

func Compose_emails(user string, option string, platform string)

To send the emails, we used SendGrid API to compose and send emails to our recipients. As the “user” string is the first part of the user’s email, this was appended by “@ncr.com” and added to the new email object.

The “option” parameter indicates which email body template to send the user. Options include:

  • “name”: the user needs to update only their profile name
  • “email”: the user needs to update only their email visibility
  • “both”: the user needs to update both their name and email

Finally, the body content is added to the email and a new SendGrid Client is created.

Below is a sample email to a user who needs to update their Github profile name:

Sample Email

For more information on SendGrid, see the link below:

Feature Flags

For this project, we used LaunchDarkly Feature Flags to test our application in production without sending over 800 emails each time we tested our code. With feature flags, we were able to restrict who was being sent emails to just ourselves, so that we could check that our emails were being sent properly before finally opening up the application to send emails to all users.

In order to make this possible, we first set up a LaunchDarkly client:

In LaunchDarkly, we created a condition so that only those working on the project would be sent emails. This was then referenced within our code as a boolean statement.

When the product was ready for release, this flag was turned off so that all users who needed to update their profiles would be sent an email.

For more information on how to set up feature flags in your own project, check out their website below:

Automate the email process

We wanted this process to happen several times a week to gently remind individuals in our organization to update their profile. This was done using Github Actions.

We scheduled our application to run on Sunday, Tuesday, and Thursday evenings at 01:00 UTC (or around 8pm EST), so that users will see the email in their inbox the following morning.

on: 
schedule:
- cron: '1 0 * * 2,4,'

For more information on Github Actions, check out their docs site:

Sending a Slack alert via a Slackbot

Given that a small portion of our users had Github usernames that didn’t fit the username criteria required to send an email automatically, we decided to create a Slackbot to return the list of users we needed to notify manually. This was done with the SendSlackAlert function, which takes in a list of users with invalid usernames.

func SendSlackAlert(invalidUsername []string) {

For our project, we wanted to return a list of links to user’s Github profiles. To do so, for each user in the ‘invalidUsername’ array, we appended their Github username to ‘https://github.com’, creating a link to their profile. From there, we built a message.

Finally, we sent the message to our Slack channel.

Below is the following Slackbot:

Slackbot for invalid usernames

For more information on building Slackbots, see Slack’s bot documentation:

Future Work

With every project, there’s room to expand. This project was originally intended to standardize user profiles on Github, but has since been expanded to Slack workspaces as well. The code is configurable to fit with other platforms and a template html email body has been included for users to create their own email content.

See the link below to view the full codebase:

--

--