Implementing Licenses API for

I came across this license issue while searching on GitHub. So, I thought I’d give it a shot. I pinged sigmavirus24 in seeing if this was a feature I could implement. He gave the thumbs up and I was off.

Testing manually first

Before any implementation, I always like to get a better understanding of the API by using good ol’ fashion curl.

Sending a custom Accept: Header

In the code base, most classes inherit from github3.GitHubCore, which inherits from requests.Session. We can pass in**kwargs, and requests.Session.get accepts a headers as a kwarg. So, we can pass a custom Accept: header like so:

How to add attributes to License model

By default, the model will not expose any attributes. How do we do that? The key is implementing __update_attributesmethod.

github3.licenses.License inherits from github3.models.GitHubObject, which calls __update_attriubtes in its__init__.

So, let’s add License attributes

Writing test

This guide is a great place to start. But, just a few pointers. For unit tests, copy/paste example data the API docs. For example, grab the JSON data from the license documentation. Save it under tests/unit/.

For integration tests, you’ll need to perform HTTP request(s). The betamax wrapper will record it to tests/cassettes.


This feature was merged in this pull request. I really enjoy contributing to this project. Primarily since sigmavirus24 is a pleasure to work with and extremely helpful. He’s super patient and I appreciate he takes the time onboarding new contributors.