Skip to content

Commit

Permalink
feat: add none pr check (#114)
Browse files Browse the repository at this point in the history
* feat: add none pr check

* npm run all, add more test

Co-authored-by: Fuxing Loh <[email protected]>
  • Loading branch information
janos-kasa and fuxingloh authored Jan 13, 2022
1 parent 3386cbc commit b1d1a32
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 4 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,18 @@ checks:
all: [ "app" ]
```

#### PR Check none

```yml
version: v1
checks:
- context: "Merge check"
description: "Disable merging when 'DO NOT MERGE' label is set"
labels:
none: [ "DO NOT MERGE" ]
```

## Why?

> There are so many labeler why create another? 😧
Expand Down
45 changes: 45 additions & 0 deletions __tests__/checks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,51 @@ describe('is', () => {
).toBeFalsy()
})
})

describe('none', function () {
it('should be false when none is present', function () {
expect(
is(
{
context: 'abc',
labels: {
none: ['b']
}
},
['a', 'b']
)
).toBeFalsy()
})

it('should be true when none is not present', function () {
expect(
is(
{
context: 'abc',
labels: {
none: ['c']
}
},
['a', 'b']
)
).toBeTruthy()
})

it('should be true when none is not present but all not valid', function () {
expect(
is(
{
context: 'abc',
labels: {
none: ['c'],
all: ['b']
}
},
['a', 'd']
)
).toBeFalsy()
})
})
})

describe('checks', () => {
Expand Down
10 changes: 8 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ export function is(check: Check, labels: string[]): boolean {
}
}

if (check.labels?.none?.length) {
if (check.labels?.none?.some(label => labels.includes(label))) {
return false
}
}

return true
}

Expand Down
3 changes: 2 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ const Check = t.intersection([
]),
labels: t.partial({
any: t.array(t.string),
all: t.array(t.string)
all: t.array(t.string),
none: t.array(t.string)
})
})
])
Expand Down

0 comments on commit b1d1a32

Please sign in to comment.