call openAI provide github PR feedback hackathon

For Opentables 2023 October Hackathon I proposed integrating with openAI api to get feedback on github PRs . I'd already used the chatGPT interface to get feedback on code or write tests and it's good.

I know there are github Actions out there which do similar but I wanted to hack a solution for our companys setup and also to learn. Another engineer thought it was a fun idea and joined me in this hack. 

My initial idea was to: 

  1. create a github Action which triggers off PRs and 
  2. call github to get the PR code
  3. call the openAI chat api and passes it the code
  4. call github to add a comment to the PR
One challenge with this was that would be running externally and would not have access private data needed to access things.
So we pivoted to running the steps inside our CI build system instead. This gave us github triggers such as PR opened and also secure access. To get access to the PR number we had to enable a feature in the CI, but I did and it worked!

We used bash scripts and I was able to use curl to call to github to get a PR diff and also use curl to add a comment to a PR. Nice!
But calling openAI over bash and escaping data was a real problem and not working. Half way through day 2 of the hack and we did't have a working solution! Not good.
So pivot number 2: onwards to python

We rewrote the hack in python and within a few hours everything was basically working. 
When open a PR the code diff is retrieved, send to openAI, get back feedback, add as PR comment and it worked! fantastic

Our solution is very basic and assumes a happy case of a PR adding a new file. 
  • How would you support multiple pushes to a PR? Don't want to keep calling openAI and duplicating AI comments.
  • A PR of a totally new file returns a github diff of the new file, but what about a PR with some changes to existing files(s)? What would you get and pass to openAI to make sense of it?
Shortly after our Hackathon at the Github universe conference they announced github PR copilot support. They stole our idea! lol
Not surprised that is added. Have yet to use it myself.

The day is close when the first PR reviewer will be copilot and engs won't even look at a PR until the AI feedback is addressed (almost like a linter). How much further is the day when the AI writes the code as well...and no need to review its own code (scary). But that's a different discussion.


Appendix
our call to openAI was basic using model: gpt-3.5-turbo, role: 'user' and content: <the diff text> and chat completions api  and response is in json content prop

Comments

Popular posts from this blog

deep dive into Material UI TextField built by mui

angular js protractor e2e cheatsheet

react-router v6.4+ loaders, actions, forms and more