From 691bc2b7c57708e302e23d1fe452a7d73c57ce5a Mon Sep 17 00:00:00 2001 From: Lucas Johannson <122710986+neo-Lucas-Johannson@users.noreply.github.com> Date: Fri, 26 Apr 2024 13:25:00 -0600 Subject: [PATCH] Creating ignoreBots field on action (#39) --- CHANGELOG.md | 5 +++++ README.md | 5 +++-- action.yml | 6 +++--- package.json | 2 +- src/index.ts | 27 ++++++++++++++++++--------- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c766c3ba..38fdc32f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Coverage Upload Action Changelog +## 2.2.0 (April 26, 2024) + +- Replaced ignoredUsers with ignoreBots which is a boolean defaulted to "true". +- Action will be skipped if ignoreBots is set to true and the senderType is "Bot" + ## 2.1.1 (April 19, 2024) - Updated default ignoredUsers to dependabot[bot] diff --git a/README.md b/README.md index d80a808d..4d2c4ca1 100644 --- a/README.md +++ b/README.md @@ -43,20 +43,21 @@ jobs: with: coverageEndpoint: https://your.endpoint.here coverageToken: ${{ secrets.COVERAGE_TOKEN }} + ignoreBots: 'true' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ``` If you have an existing workflow that runs your tests you can just add the `Upload coverage` step at the end of that workflow. -If you want to exclude certain authors from running this action update the ignoreUsers input as seen below +If you want the action to run for pull requests created by bots (dependabot, crowdin etc) set the ignoreBots field to false ``` ... with: coverageEndpoint: https://your.endpoint.here coverageToken: ${{ secrets.COVERAGE_TOKEN }} - ignoredUsers: 'dependabot,ignoredUser1,ignoredUser2' // <--- Update here + ignoreBots: 'false' ... ``` diff --git a/action.yml b/action.yml index 2d9ac9da..7520cc30 100644 --- a/action.yml +++ b/action.yml @@ -15,9 +15,9 @@ inputs: coverageToken: description: token to send with coverage data required: false - ignoredUsers: - description: 'disable action to run on specified users PRs' - default: 'dependabot[bot]' + ignoreBots: + description: 'disable action to run on pull requests created by bots' + default: 'true' required: false runs: using: 'node16' diff --git a/package.json b/package.json index ab3e2e97..49dbbfcb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coverage-upload-action", - "version": "2.1.1", + "version": "2.2.0", "description": "Parses coverage file and uploads to remote endpoint", "author": "Neo Financial Engineering", "license": "MIT", diff --git a/src/index.ts b/src/index.ts index bfea266e..d3a83842 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,22 +1,31 @@ -import { getInput, setFailed, warning } from '@actions/core'; +import { debug as log, getInput, setFailed, warning } from '@actions/core'; import { context } from '@actions/github'; import { getData } from './get-data'; import makePullRequestComment from './make-comment'; import sendPullRequestData from './send-data'; +const debug = (label: string, message: string): void => { + log(''); + log(`[${label.toUpperCase()}]`); + log(message); + log(''); +}; + const run = async (): Promise => { try { - const ignoredUsers = getInput('ignoredUsers') - .split(',') - .map((user) => user.trim()); + const ignoreBots = getInput('ignoreBots'); - if (ignoredUsers.includes(context.payload.pull_request?.user.login)) { - console.log( - `Skipping the action because the pull request is created by ${context.payload.pull_request?.user.login}` - ); + if (ignoreBots === 'true') { + const senderType = context.payload.pull_request?.user.type as string; - return; + debug('senderType', senderType); + + if ((senderType as string) === 'Bot') { + console.log(`Skipping the action because the pull request is created by bot`); + + return; + } } const url = getInput('coverageEndpoint');