Search code examples
github-apipygithub

Get assignees and assigner via PyGithub


I'm using PyGithub to interact with GitHub API and trying to get assignees and assigner on issues. I implemented the following code, and it seem that assignee name and assigner name are not correct. For instance, clatoolkitdev2 was assigned by clatoolkitdev on issue #32. However, I got clatoolkitdev2 as assignee and assigner from my code.

gh = Github(login_or_token = token, per_page = self.parPage)
repo = gh.get_repo(repo_name)
issue = repo.get_issue(issue_number)
issue_events = issue.get_events().get_page(page)

for event in issue_events:
    assignee = event.issue.assignee
    assigner = event.actor

    assigner_id = str(assigner.id)
    assigner_name = str(assigner.login)
    assignee_name = assignee.login

    print '================================================================='
    print 'event ID: ' + str(event_id) + "     " + issue_url
    print 'assigner: %s  assignee: %s' % (assigner_name, assignee_name)

The output:

=================================================================
event ID: 866189924     https://github.com/clatoolkitdev/GitHubIntegrationTest/issues/32
assigner: clatoolkitdev2  assignee: clatoolkitdev2
=================================================================
event ID: 803384175     https://github.com/clatoolkitdev/GitHubIntegrationTest/issues/25
assigner: kojiclatoolkit  assignee: kojiclatoolkit
=================================================================
event ID: 803384176     https://github.com/clatoolkitdev/GitHubIntegrationTest/issues/25
assigner: clatoolkitdev  assignee: kojiclatoolkit
=================================================================
event ID: 852475091     https://github.com/clatoolkitdev/GitHubIntegrationTest/issues/24
assigner: kojiclatoolkit  assignee: kojiclatoolkit
=================================================================
event ID: 852475092     https://github.com/clatoolkitdev/GitHubIntegrationTest/issues/24
assigner: clatoolkitdev  assignee: kojiclatoolkit

I checked PyGithub API reference and googled to find a solution but didn't get any clue. I was wondering whether I made stupid mistakes or there is a bug in PyGithub.


Solution

  • The issue is that PyGithub (and your code) is reading the actor.login property of the event to get the assigner, which is in fact clatoolkitdev2 in the API response you provided.

    Looking at the PyGithub source, it doesn't seem to ever read the assigner property from the API payload (neither in Issue.py nor IssueEvent.py), which strikes me as a bug.