{"id":17473740,"url":"https://github.com/rob-derosa/sentiment-analysis-action","last_synced_at":"2026-01-20T03:31:29.334Z","repository":{"id":37796135,"uuid":"282951831","full_name":"rob-derosa/sentiment-analysis-action","owner":"rob-derosa","description":"Analyzes the body of issues, pull requests and comments downstream for sentiment. If negative sentiment \u003e= 60% is detected, a label is applied to the issue or pull request.","archived":false,"fork":false,"pushed_at":"2023-01-24T17:05:12.000Z","size":1065,"stargazers_count":2,"open_issues_count":18,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-05-28T20:49:00.541Z","etag":null,"topics":["actions","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rob-derosa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-27T16:19:57.000Z","updated_at":"2024-08-13T05:50:57.376Z","dependencies_parsed_at":"2023-02-13T23:46:16.349Z","dependency_job_id":null,"html_url":"https://github.com/rob-derosa/sentiment-analysis-action","commit_stats":{"total_commits":28,"total_committers":1,"mean_commits":28.0,"dds":0.0,"last_synced_commit":"8b22aa590ce0247367cad5beb2b69c40490cbfcb"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rob-derosa%2Fsentiment-analysis-action","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rob-derosa%2Fsentiment-analysis-action/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rob-derosa%2Fsentiment-analysis-action/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rob-derosa%2Fsentiment-analysis-action/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rob-derosa","download_url":"https://codeload.github.com/rob-derosa/sentiment-analysis-action/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247471396,"owners_count":20944154,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["actions","typescript"],"created_at":"2024-10-18T18:06:51.162Z","updated_at":"2026-01-20T03:31:29.305Z","avatar_url":"https://github.com/rob-derosa.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sentiment Analysis Action \n\nThis is a sample GitHub action to analyze sentiment in any issues or pull requests that are opened, edited or commented on. If negative sentiment is detected using the [Sentiment Analysis Cognitive Service](https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/how-tos/text-analytics-how-to-sentiment-analysis?tabs=version-3) from Microsoft with a confidence score of \u003e= 90%, a custom label `negativity detected` is added to the issue or pull request.\n\nA `results` output value is available containing the JSON response payload providing a detailed analysis of the results.\n\nFor this sample, I tried to keep the typescript logic limited to just analyzing sentiment on input text. The rest of the logic is in the `analyze-sentiment.yml` workflow file. This allows for greater variation on how and when to react to sentiment.\n\n## Usage\n\nCreate a `.github/workflows/analyze-sentiment.yml` file:\n\n```yaml\nname: 'analyze-sentiment'\non:\n  issues:\n    types:\n      - opened\n      - edited\n  issue_comment:\n    types:\n      - created\n      - edited\n  pull_request:\n    types:\n      - opened\n      - edited\n  pull_request_review_comment:\n    types:\n      - created\n      - edited\n\njobs:\n  analyze-sentiment:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v2\n      \n      - name: set text input pull request\n        if: ${{ github.event.pull_request.body }}\n        run: |\n          echo \"::set-env name=TEXT_TO_ANALYZE::${{ github.event.pull_request.body }}\"\n\n      - name: set text input issue\n        if: ${{ github.event.issue.body }}\n        run: |\n          echo \"::set-env name=TEXT_TO_ANALYZE::${{ github.event.issue.body }}\"\n\n      - name: set text input comment\n        if: ${{ github.event.comment.body }}\n        run: |\n          echo \"::set-env name=TEXT_TO_ANALYZE::${{ github.event.comment.body }}\"\n      \n      - uses: ./\n        id: analyzeSentiment\n        name: \"Run Sentiment Analysis\"\n        with:\n          azure-cognitive-subscription-key: ${{ secrets.AZURE_COGNITIVE_SUBSCRIPTION_KEY }}\n          azure-cognitive-endpoint: ${{ secrets.AZURE_COGNITIVE_ENDPOINT }}\n          text-to-analyze: ${{ env.TEXT_TO_ANALYZE }}\n          text-language: \"en\"\n      - name: Dump output\n        env:\n          OUTPUTS: ${{ toJson(steps.analyzeSentiment.outputs) }}\n        run: echo \"$OUTPUTS\"\n      - name: label issue\n        if: ${{ steps.analyzeSentiment.outputs.negative \u003e= .9 }}\n        uses: andymckay/labeler@master\n        with:\n          add-labels: \"negativity detected\"\n```\n\n## Configuration\n\nThe following inputs are required:\n\n- `azure-cognitive-subscription-key`: A valid [Azure Cognitive Service](https://ms.portal.azure.com/#create/Microsoft.CognitiveServicesAllInOne) key\n- `azure-cognitive-endpoint`: in the [Azure portal](https://portal.azure.com), navigate to your Cognitive Service resource \u003e Keys and Endpoint \u003e Endpoint (i.e. `https://centralus.api.cognitive.microsoft.com/`)\n- `text-to-analyze`: the text to analyze for sentiment\n- `text-language`: the language of the text to be analyzed (i.e. `en`)\n\n## In Action\n\n**A PR filed by a user that contained negative sentiment**\n![Sentiment Analysis Step Output](https://github.com/rob-derosa/SentimentAnalysisAction/blob/main/assets/sentiment_analysis_action_output.png?raw=true)\n\n**The confidence score for this PR was over 60% so the PR was labeled accordingly**\n![PR containing negative sentiment flagged with label](https://github.com/rob-derosa/SentimentAnalysisAction/blob/main/assets/sentiment_analysis_pr_labeled.png?raw=true)\n\n\n## Limitations\n\n* There is a 5,120 character limit and 1MB total request payload size as outlined [here](https://docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/concepts/data-limits?tabs=version-3).\n* This sample could be extended to batch the request up to 5 per payload.\n\n## License\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frob-derosa%2Fsentiment-analysis-action","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frob-derosa%2Fsentiment-analysis-action","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frob-derosa%2Fsentiment-analysis-action/lists"}