This week I got more Involved in a new project still closely related to the previous one. Gabriel’s keras bot is used to monitor pull requests on the github repo, and I looked into extending this bot to parse and warn about improper imports. I learned to work with PyGithub a powerful tool to interact with Github repos through python, as well as extended commands for git.
Where To Begin?
In order to see results from this I knew I needed to start by creating a repo solely to test this. I began by creating the repo, followed by creating the first pull request. I made sure to use an actual keras PR so the structure would be identical to the real thing.
I originally began by trying to implement my tool in its current state, however I faced a slight problem. PyGithub is powerful but faces setbacks, one example being the inability to access the PR Files, which was where I first faced an issue, and reached out to Gabriel. Thankfully Gabriel was able to provide a work around, cloning the repo using the user name and repo name. This worked like a charm, combatted the inability to access PR files, but created another problem. In any open source project, and pull requests there will be different branches, fundamentally straightforward, but difficult to mitigate in PyGithub.
Example of problem
Link to docs. The user will have the directory in their repos, but the branch by default goes to master. In PyGithub there are two methods related to branch; get_branches(), and get_branch(). The latter required an Id to get that branch which would require knowing the branch name. The first option provides a list of all branches on the repo, which is again not very helpful.
Everything else works! I said earlier I learned more about git commands this week, more specifically the clone command. I learned about the –single-branch flag that exists and the need to use it get the correct branch of the PR. For the time being I have it hardcoded to test and it works! Results are collected properly, and I am waiting to hear about how I should add them to the message sent to the user who submitted the PR.
To wrap up this release I created my pull request, as the inaugural PR to the keras-bot repository. I described the changes in the pull request, being the additional script importTester.py, as well as the updates I made to the existing file. The major changes include testing the imports, and adding the error messages to the user message.
I didn’t want to bombard the user with walls of text with errors, so I limited it to 10 errors for relative and 10 for absolute, as well as including the total amount of files with errors.
PyGithub is very cool and fun to work with, but does not encompass the full functionality that this tool needs, so for the time being I am still looking for a work around. This week gave me new insights into thinking of alternative flows, as a few times I became stuck but was able to change path. I would love to see this tool through and incorporate it to keras and the keras bot, just need to figure out the pesky branch!
Until next time…