DEV Community

Alex Pliutau
Alex Pliutau

Posted on

4

Year Of Commits: simple systray program in Go

Happy New Year Gophers! One of my goals for 2018 is to commit a code to GitHub every single day. So "Contributions" on GitHub will look like this:

Contributions

To track this process I decided to write a Go program, which will be always in my tray, and which will show how many days in a row I committed something to Github.

Tadaa! yearofcommits

It's a single-file command line tool using the following packages:

  • github.com/getlantern/systray
  • github.com/google/go-github/github
  • golang.org/x/oauth2

We're installing them using dep.

systray is a cross-platform package to place an icon and menu into notification area. Though I tested it only on Mac.

Then application uses GitHub API with help of go-github/github Go package. GitHub API doesn't have contributions endpoint, so we need to get all repositories and get all commits made by specified user.

client.Repositories.List(ctx, user, reposOpts)
client.Repositories.ListCommits(ctx, user, repo.GetName(), commitsOpts)
Enter fullscreen mode Exit fullscreen mode

The rest is easy, count days.

Contributions

To run it in locally you need to install dep and run:

dep ensure
go install
yearofcommits -u github_user -t github_api_token
Enter fullscreen mode Exit fullscreen mode

Also, if you want keep it running even after you restart your Mac, you can configure launchctl. Create /Library/LaunchAgents/yearofcommits.plist file with the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>yearofcommits</string>

    <key>OnDemand</key>
    <false/>

    <key>UserName</key>
    <string>MAC_USER</string>

    <key>GroupName</key>
    <string>MAC_GROUP</string>

    <key>ProgramArguments</key>
    <array>
            <string>/go/bin/yearofcommits</string>
            <string>-u</string>
            <string>GITHUB_USER</string>
            <string>-t</string>
            <string>GITHUB_TOKEN</string>
    </array>
</dict>
</plist>
Enter fullscreen mode Exit fullscreen mode

Change /go/bin/yearofcommits to the absolute path inside your $GOBIN.

Run:

sudo launchctl load /Library/LaunchAgents/yearofcommits.plist
Enter fullscreen mode Exit fullscreen mode

Origin post in my Blog

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay