Skip to content

Commit

Permalink
Creating ignoreBots field on action (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
neo-Lucas-Johannson authored Apr 26, 2024
1 parent 9f41cf2 commit 691bc2b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
...
```
Expand Down
6 changes: 3 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
27 changes: 18 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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<void> => {
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');
Expand Down

0 comments on commit 691bc2b

Please sign in to comment.