No Toxic Discussions
Tags: actionshackathon21, github, perspectiveapi, googleapis
Published: 2021-12-07 19:23:43

[Instructions]: # (To submit to the GitHub Actions x DEV Hackathon 2021, please fill out all sections.)

> 😶 **Disclaimer : Read that before use it**
> For this moment, this GitHub Actions **don't work properly like I would like**. **When GitHub add the possibility to add and/or edit comments in Discussions**, **I will update the project**.
> I started this Action because I thinked that it is a good idea to have a moderate tool in Discussions part with the toxicity of comments So I did it thinking it would be feasible, but when I got to the end of the code part, I couldn't figure out how to create/edit comments.

> 😵 **But why do I still participate in the Hackathon, knowing that my action is not entirely finished?** 
> The idea of using the Perspective API came to me quite late. In 4-5 days I had to learn how to create my own GA (GitHub Actions) and how to execute JavaScript. How to use correctly the TOKEN of GitHub. I still have some small issues to fix on the source code, but I'm working on it, and like any project, there will be updates.
 
> So when I was almost at the end, I looked at the GitHub documentation to find out how to create a comment in the Discussions with Action section. Unfortunately, it's not possible, and I'm disgusted. Nevertheless, I leave the source code visible for everybody, because when GitHub will have added this option, the code will be updated and possible to use in your repositories. 
> If you want to know more about how it works, I redirect you to [How it's work](https://github.com/thomasbnt/actions-NoToxicDiscussions#how-its-work) part.

> For the moment **it scans** well and **emits a percentage based on 1** **the TOXICITY of the content**. 

___
### My Workflow
[Note]: # (Please make sure the project links to the appropriate GitHub Actions repository, and includes [an open source license](https://choosealicense.com/) and README.)

**No Toxic Discussions** 

{% github https://github.com/thomasbnt/NoToxicDiscussions  no-readme %}


Output workflow : 

![Output workflow](https://user-images.githubusercontent.com/14293805/145136473-3fa03470-1856-404c-8b09-639e2d193b8a.png)

### Submission Category: Maintainer Must-Haves

[Note]: # (Maintainer Must-Haves, DIY Deployments, Interesting IoT, Phone Friendly, or Wacky Wildcards)


### Yaml File or Link to Code

[Note]: # (Our markdown editor supports pretty embeds. Try this syntax: `{% github link_to_your_repo %}` to share a GitHub repository)

You can see this example of workflow at **[.github/workflows/NoToxicDiscussions.yml](https://github.com/thomasbnt/NoToxicDiscussions/blob/main/.github/workflows/NoToxicDiscussionsHere.yml)**

```yaml
name: No Toxic Discussions Here
on:
  discussion:
    # created type can be marked as an error BUT IT'S WORK. See the docs :
    # https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#discussion
    types: [ created, opened, edited, answered ]
  discussion_comment:
    types: [ created, edited ]
jobs:
  CheckIfToxicContent:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v2
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          PERSPECTIVE_API_KEY: ${{ secrets.PERSPECTIVE_API_KEY }}
      - name: Install dependencies
        run: |
          yarn install
          yarn add @actions/core @actions/github
      - name: Run the script
        run: |
          yarn run start

```

### Additional Resources / Info

This Action use **[Perspective API](https://perspectiveapi.com/)** from Jigsaw Google.

> Perspective is a free API that helps you host better conversations online. The API uses machine learning models to score the perceived impact a comment might have on a conversation. You can use this score to give feedback to commenters, help moderators more easily review comments, allow readers to more easily find interesting or productive comments, and more.

![Perspective API](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lcfuwxq8j6uuxqxbb3sw.gif)
 


<!--[Note:] # (Be sure to link to any open source projects that are using your workflow!)

[Note]: # (Be sure to include the DEV usernames of your collaborators, if any. )

[Reminder]: # (Submissions are due on December 8th, 2021 (11:59 PM PT or 2 AM ET/6 AM UTC on December 9th).-->