DEV Community

Cover image for Analyse Sentiments In Issues and PRs And Get Notified
Lukasz Gornicki
Lukasz Gornicki

Posted on

Analyse Sentiments In Issues and PRs And Get Notified

My Workflow

I created an action named Code of conduct compliance through sentiments analysis and want to use it in a workflow with Slack integration in the AsyncAPI Initiative. I'm a maintainer and community guardian in this project and want to make sure that people respect each other when working in the project.

Submission Category: Maintainer Must-Haves

Cause you want to keep your community healthy and know when people disrespect each other.

Yaml File and Link to Code

The most basic example of using this action with other actions is when you want to send the information about negative sentiments to some communicator. Below example shows how to use this action with another action for sending messages to Slack:

name: 'Sentiment analysis'

on: 
  issue_comment:
    types: 
      - created
      - edited
  issues:
    types:
      - opened
      - edited
  pull_request:
    types:
      - opened
      - edited
  pull_request_review:
    types:
      - submitted
      - edited
  pull_request_review_comment:
    types:
      - created
      - edited
jobs:
  test:
    name: Checking sentiments
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Check sentiment
        uses: derberg/code-of-conduct-sentiment-analysis-github-action@v1
        # id is needed for a step if you want to access its output in another step
        id: sentiments
        with:
          # you can find an instruction on how to setup Google project with access to Natural Language API here https://github.com/BogDAAAMN/copy-sentiment-analysis#gcp_key-get-your-gcp-api-key
          gcp_key: ${{ secrets.GCP_KEY }} 
      - uses: someimportantcompany/github-actions-slack-message@v1
        # this step runs only if sentiment is a negative numner
        if: steps.sentiments.outputs.sentiment < 0
        with:
          # to get a webhook url of your channel use this documentation https://slack.com/intl/en-pl/help/articles/115005265063-Incoming-webhooks-for-Slack
          # first register new app here (https://api.slack.com/apps
          webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
          text: Here ${{steps.sentiments.outputs.source}} you can find a potential negative text that requires your attention as the sentiment analysis score is ${{steps.sentiments.outputs.sentiment}}
          color: orange

This is what you see in Slack once the negative sentiment is spotted:

Alt Text

Not using Slack? then check different actions:

There are plenty of different notifications-like actions that you can use. Check this awesome list.

The rest of the examples of using the action are stored in the readme of the GitHub Action.

GitHub logo derberg / code-of-conduct-sentiment-analysis-github-action

Use this action to analyze sentiments in issues and pull request to identify negative emotions that need to be checked against the Code of Conduct

Code of Conduct Compliance Through Sentiments Analysis

Overview

Use this action to analyze sentiments in issues and pull requests to identify emotions that need to be checked against the Code of Conduct This action only analyzes sentiments. Alone it is not very useful as it is just able to log the sentiment on GitHub Actions log level. It is intended to be used with other Github Actions. An example use case could be run this action and then send the results to Slack with another action.

Why this action requires other actions?

It is because it "only" analyzes the sentiment, but it is up to you to decide in the workflow setup the negative sentiment for you…

Additional Resources / Info

This action can analyze sentiments using two different solutions: built-in and 3rd party. Out of the box, this action is integrated with sentiment package to do analytics based on AFINN wordlist. Instead of such basic analytics, better use this action to communicate with Google Natural Language API.

Google API is not expensive. It is free up to 5k requests and 1$ up to 1m requests. I recommend this way instead of the dictionary check.

Cover photo by Greg Rakozy on Unsplash

Latest comments (4)

Collapse
 
ender_minyard profile image
ender minyard

If statistical natural language processing with AFINN seems too simple for you, you could use machine learning to make your own sentiment analysis library. I thought you were an open-source freak, what's all this about Google Natural Language API?

Collapse
 
derberg profile image
Lukasz Gornicki

Being open-source freak doesn't mean being 10 times developer :D

I wanted to make an action that is not expensive and can be used by others. This is why I added basic library to it and also integrated with with cheap Google API that in theory does things better. I was also thinking about adding integration with Microsoft's Content Moderator API but only in case pleople ask for it, or I just notice over time that I get to many false-positives with Google.

I'm always standing in position that people should first use what is available and then write their own solution as a last resort.

Collapse
 
ender_minyard profile image
ender minyard
I'm always standing in position that people should first use what is available and then write their own solution as a last resort.

Why?

Thread Thread
 
derberg profile image
Lukasz Gornicki

like, do not reinvent the wheel if you first didn't try if the wheel is what you need or maybe you just need to tune it