Skip to content

Commit

Permalink
feat: sync (#43)
Browse files Browse the repository at this point in the history
* feat: sync labels

* remove label to ignore error

* Improved coveraged by adding more test

* Updated README.md
  • Loading branch information
fuxingloh authored Jan 18, 2021
1 parent 02100e8 commit 8afa186
Show file tree
Hide file tree
Showing 11 changed files with 333 additions and 125 deletions.
6 changes: 6 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ labels:
commits: "^docs:.*"

- label: "test:labeler"
sync: true
matcher:
files: ".github/labeler.yml"

- label: "test:dist"
sync: true
matcher:
files: ["dist/*"]

- label: "test:tests"
sync: true
matcher:
files: [ "__tests__/matcher/**", "__tests__/*.ts" ]

Expand All @@ -50,20 +53,23 @@ labels:
comment: "/stale"

- label: "test: s"
sync: true
matcher:
files:
count:
gte: 1
lte: 4

- label: "test: m"
sync: true
matcher:
files:
count:
gte: 5
lte: 10

- label: "test: l"
sync: true
matcher:
files:
count:
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ version: v1
labels:
- label: "feat"
sync: true # remove label if match failed, default: false
matcher:
# Matcher will match on any 6 matcher
title: "^feat:.*"
Expand Down Expand Up @@ -326,11 +327,13 @@ version: v1
labels:
- label: "github"
sync: true
matcher:
# This is shorthand for any: [".github/**"]
files: ".github/**"
- label: "security"
sync: true
matcher:
# This is shorthand for any: ["web/security/**", "security/**"]
files: [ "web/security/**", "security/**" ]
Expand All @@ -343,20 +346,23 @@ version: v1
labels:
- label: "size: s"
sync: true
matcher:
files:
count:
gte: 1
lte: 4
- label: "size: m"
sync: true
matcher:
files:
count:
gte: 5
lte: 10
- label: "size: l"
sync: true
matcher:
files:
count:
Expand All @@ -370,12 +376,14 @@ version: v1
labels:
- label: "ci"
sync: true
matcher:
files:
any: [ ".github/workflow/**", ".circleci/**" ]
all: [ "!app/**" ]
- label: "attention"
sync: true
matcher:
files:
any: [ "app/**" ]
Expand Down
100 changes: 15 additions & 85 deletions __tests__/checks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as github from '@actions/github'
import {GitHub} from '@actions/github/lib/utils'
import {getConfig} from '../src/config'
import * as fs from 'fs'
import {checks, is, joined, StatusCheck} from '../src/checks'
import {checks, is, StatusCheck} from '../src/checks'

const client: InstanceType<typeof GitHub> = {
repos: {
Expand All @@ -29,64 +29,6 @@ async function runChecks(
return checks(client, config, labels)
}

describe('joined', () => {
it('lhs empty should join', function () {
github.context.payload = {
pull_request: {
number: 1,
labels: []
}
}

const labels = ['a', 'b', 'c']
expect(joined(labels)).toEqual(labels)
})

it('rhs empty should join', function () {
const labels = ['a', 'b', 'c']
github.context.payload = {
pull_request: {
number: 1,
labels: labels.map(value => {
return {name: value}
})
}
}

expect(joined([])).toEqual(labels)
})

it('non empty should join', function () {
const lhs = ['a', 'b', 'c']
const rhs = ['d', 'e', 'f']
github.context.payload = {
pull_request: {
number: 1,
labels: lhs.map(value => {
return {name: value}
})
}
}

expect(joined(rhs).sort()).toEqual([...lhs, ...rhs].sort())
})

it('should dedupe', function () {
const lhs = ['a', 'b', 'c']
const rhs = ['c', 'b', 'f']
github.context.payload = {
pull_request: {
number: 1,
labels: lhs.map(value => {
return {name: value}
})
}
}

expect(joined(rhs).sort()).toEqual(['a', 'b', 'c', 'f'].sort())
})
})

describe('is', () => {
it('should empty true', function () {
expect(
Expand Down Expand Up @@ -402,6 +344,14 @@ describe('checks', () => {
jest.restoreAllMocks()
})

it('should be empty without payload', async function () {
github.context.payload = {}

const checks = await runChecks('__tests__/fixtures/basic.yml', ['feat'])

expect(checks.length).toBe(0)
})

it('no checks', async function () {
const checks = await runChecks('__tests__/fixtures/basic.yml', ['feat'])

Expand Down Expand Up @@ -443,17 +393,9 @@ describe('checks', () => {
})

it('feat: success state', async function () {
github.context.payload = {
pull_request: {
number: 1,
labels: [{name: 'feat'}]
}
}

const checks = await runChecks(
'__tests__/fixtures/semantic-release.yml',
[]
)
const checks = await runChecks('__tests__/fixtures/semantic-release.yml', [
'feat'
])

expect(checks.length).toBe(1)
expect(checks[0].context).toBe('Semantic Pull Request')
Expand All @@ -465,13 +407,6 @@ describe('checks', () => {
})

it('chore: success state', async function () {
github.context.payload = {
pull_request: {
number: 1,
labels: [{name: 'help'}]
}
}

const checks = await runChecks('__tests__/fixtures/semantic-release.yml', [
'chore'
])
Expand Down Expand Up @@ -500,15 +435,10 @@ describe('checks', () => {
})

it('fix: success state', async function () {
github.context.payload = {
pull_request: {
number: 1,
labels: [{name: 'bug'}, {name: 'fix'}]
}
}

const checks = await runChecks('__tests__/fixtures/semantic-release.yml', [
'none'
'none',
'bug',
'fix'
])

expect(checks.length).toBe(1)
Expand Down
Loading

0 comments on commit 8afa186

Please sign in to comment.