Skip to content

Commit

Permalink
Added ability to ignore drafts (#8)
Browse files Browse the repository at this point in the history
This PR resolves #7 

It adds a filter to ignore draft pull request. It is `on` by default.

I also upgraded the version to `0.1.0` as it adds a feature (instead of
being a fix).
  • Loading branch information
Bullrich committed Apr 19, 2023
1 parent 36aad24 commit e3254de
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ You can find all the inputs in [the action file](./action.yml) but let's walk th
- `noComments`: Boolean. If the action should only fetch Pull Requests that have 0 reviews (comments do not count).
- Short for `Ignore PRs that have comments`.
- **default**: false
- `ignoreDrafts`: Boolean. If the action should ignore Pull Requests that are [draft](https://github.blog/2019-02-14-introducing-draft-pull-requests/)
- **default**: true
- `fileOutput`: String. File to which the output from `data` should be written.
- Useful in the cases where the output is too big and GitHub Actions can not handle it as a variable.
- Make sure that the directory exists, else it will fail
Expand Down
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ inputs:
required: false
description: If true, it will only collect PRs with NO reviews.
default: false
ignoreDrafts:
required: false
description: If true, it ignore draft Pull Requests.
default: true
fileOutput:
required: false
description: File to which the output data should be written.
Expand All @@ -37,4 +41,4 @@ outputs:

runs:
using: 'docker'
image: 'docker://ghcr.io/paritytech/stale-pr-finder/action:0.0.3'
image: 'docker://ghcr.io/paritytech/stale-pr-finder/action:0.1.0'
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stale-pr-finder",
"version": "0.0.3",
"version": "0.1.0",
"description": "GitHub action that finds stale PRs and produce an output with them",
"main": "src/index.ts",
"scripts": {
Expand Down
9 changes: 7 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { byNoReviews, olderThanDays } from "./filters";
import { getPullRequestWithReviews } from "./githubApi";
import { PullRequest, Repo } from "./types";

type Filters = { daysStale: number, noReviews: boolean };
type Filters = { daysStale: number, noReviews: boolean, ignoreDrafts: boolean };

const daysSinceDate = (date: string): number => {
return moment().diff(moment(date), 'days')
Expand All @@ -32,8 +32,10 @@ const getFiltersFromInput = (): Filters => {

const noReviews = !!getInput("noComments") ? getBooleanInput("noReviews") : false;

const ignoreDrafts = !!getInput("ignoreDrafts") ? getBooleanInput("ignoreDrafts") : true;

return {
daysStale, noReviews
daysStale, noReviews, ignoreDrafts
}
}

Expand All @@ -57,6 +59,9 @@ const filterPRs = (prs: PullRequest[], filters: Filters) => {
if (filters.noReviews) {
filteredData = filteredData.filter(byNoReviews);
}
if(filters.ignoreDrafts) {
filteredData = filteredData.filter(pr => !pr.draft);
}

return filteredData;
}
Expand Down

0 comments on commit e3254de

Please sign in to comment.