Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support application/vnd.github.v3.star+json #345

Closed
danvk opened this issue Oct 12, 2015 · 2 comments
Closed

Support application/vnd.github.v3.star+json #345

danvk opened this issue Oct 12, 2015 · 2 comments

Comments

@danvk
Copy link
Contributor

danvk commented Oct 12, 2015

See https://developer.github.com/v3/activity/starring/#list-stargazers

When requesting a list of stargazers, you can set a custom media type to find out when each user starred your repo. It would be great if pygithub supported this.

@danvk
Copy link
Contributor Author

danvk commented Oct 12, 2015

Here's some code:

class Stargazer(github.GithubObject.NonCompletableGithubObject):
    @property
    def starred_at(self):
        """
        :type: datetime.datetime
        """
        return self._starred_at.value

    @property
    def user(self):
        """
        :type: :class:`github.NamedUser`
        """
        return self._user.value

    def _initAttributes(self):
        self._starred_at = github.GithubObject.NotSet
        self._user = github.GithubObject.NotSet
        self._url = github.GithubObject.NotSet

    def _useAttributes(self, attributes):
        if 'starred_at' in attributes:
            self._starred_at = self._makeDatetimeAttribute(attributes['starred_at'])
        if 'user' in attributes:
            self._user = self._makeClassAttribute(github.NamedUser.NamedUser, attributes['user'])


def get_stargazers(repo):
    return github.PaginatedList.PaginatedList(
        Stargazer,
        repo._requester,
        repo.url + "/stargazers",
        None,
        # XXX: pygithub doesn't support this:
        headers={
            'Accept': 'application/vnd.github.v3.star+json'
        }
    )

and then you have to modify PaginatedList to accept a headers keyword arg which it passes through the call to self.__requester.requestJsonAndCheck.

@danvk
Copy link
Contributor Author

danvk commented Oct 12, 2015

(I'd be happy to turn this into a pull request if there's interest and adding a headers parameter seems like the way to go.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant