DEV Community

Cover image for Happy-PR: Pull Request Sentiment Analysis with GitHub Actions
Tyler V. (he/him)
Tyler V. (he/him)

Posted on • Edited on

Happy-PR: Pull Request Sentiment Analysis with GitHub Actions

Example of a Pull Request response with the bot responding with a Sonic Dancing Gif

My Workflow

I'd been intrigued by GitHub actions ever since they were announced, but I was never really sure of how they worked or fit into the GitHub Repository ecosystem - and this seemed like a great time to jump in and try them out!

When starting something new, my favorite way to do things is take an existing thing and play with it. I took the basis of action-cats and modified it to respond with a different gif based on the sentiment of the PR description using the npm package sentiment (sentiment analysis was another thing I have been wanting to dabble with for a while now).

So what exactly is happy-PR?

  1. It takes the description of new pull requests and runs it through sentiment to return a value from -5 to +5, with -5 being extremely aggressive or angry and +5 being extremely positive or happy.
  2. It responds to the Pull Request with the score and an associated gif (there's one for each integer from -5 to +5 - can you collect them all? πŸ˜‰)

You can see an example of the response on this PR

Submission Category: Wacky Wildcards

I don't think this is particularly useful - it's really just a reason to try out GitHub Actions πŸ₯³

Yaml File or Link to Code

The Repo can be found here:

GitHub logo TerabyteTiger / action-happyPR

GitHub Action to check tone of PR

Happy PR ✨

This action uses sentiment to analyze the sentiment of an incoming PR and responds with a gif and score from -5 to 5.

While this could have real-world uses, in it's current state it's very much just for fun πŸ˜€

Inputs

GITHUB_TOKEN

Required This is an auto-generated token that allows Happy PR to respond as the GitHub action bot.

Outputs

An example of a response to a somewhat positive Pull Request response:

Github comment stating 'You're pull request scored a 1.167 out of a possible 5 on the sentiment scale with a gif of Sonic dancing

Example usage

on:
  pull_request:
    types: [opened]
    
uses: TerabyteTiger/action-happyPR@v3
  id: happy
  with:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Enter fullscreen mode Exit fullscreen mode



Or if you want to integrate it with your repository, on the marketplace here: https://github.com/marketplace/actions/happy-pr

Additional Resources / Info

Thanks again to action-cats for the great starting point with getting this up an running!

Potential Changes

Random thoughts I had about this action that could be added:

  • Initially I wanted to include 10 more gifs for the .5 increments, but that felt like a distraction from getting the action working (and picking half step sentiment gifs is pretty hard as it turns out)
  • It could include a "minimum sentiment" option and automatically reject any PR without a minimum rating, although I'm not sure how much this could be impacted by spamming a bunch of "positive" words to average out the score

Top comments (1)

Collapse
 
bogdaaamn profile image
Bogdan Covrig