Skip to content

Commit

Permalink
test: SKIP_CHANGELOG_REG
Browse files Browse the repository at this point in the history
  • Loading branch information
liweijie0812 committed Aug 14, 2024
1 parent c6fd312 commit fb9407f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const breakingLabel = ['break', 'breaking', 'breaking changes']
const featureLabel = ['feature', 'feat', 'enhancement']
export const CHANGELOG_REG = /-\s([A-Z]+)(?:\(([A-Z\s]*)\))?:\s(.+)/gi
export const PULL_NUMBER_REG = /in\shttps:\/\/github\.com\/.+\/pull\/(\d+)\s/g
export const SKIP_CHANGELOG_REG = /\[x\] 本条 PR 不需要纳入 changelog/i
export function getPullNumbers(body: string) {
const arr = [...body.matchAll(PULL_NUMBER_REG)]

Expand Down Expand Up @@ -46,7 +47,7 @@ export function renderMarkdown(pullRequestList: PullsData[]) {
return
}
// 在 pr body 明确填了 跳过 label
if (/\[x\] 本条 PR 不需要纳入 changelog/i.test(pr.body)) {
if (SKIP_CHANGELOG_REG.test(pr.body)) {
info(`pr ${pr.number} 显示不需要纳入 changelog`)
return
}
Expand Down
9 changes: 8 additions & 1 deletion test/regexp.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
import { CHANGELOG_REG, PULL_NUMBER_REG } from '../src/renderer'
import { CHANGELOG_REG, PULL_NUMBER_REG, SKIP_CHANGELOG_REG } from '../src/renderer'
import changelog from './fixtures/changelog'
import releaseNotes from './fixtures/releaseNotes'

Expand All @@ -10,10 +10,17 @@ describe('regexp', () => {
expect(arr.length).toBe(13)
expect(arr).toMatchSnapshot()
})

it(': PULL_NUMBER_REG', () => {
const result = releaseNotes.matchAll(PULL_NUMBER_REG)
const arr = [...result]
expect(arr.length).toBe(14)
expect(arr).toMatchSnapshot()
})

it(': SKIP_CHANGELOG_REG', () => {
expect(SKIP_CHANGELOG_REG.test('[x] 本条 PR 不需要纳入 Changelog')).toBe(true)
expect(SKIP_CHANGELOG_REG.test('[x] 本条 PR 不需要纳入 changelog')).toBe(true)
expect(SKIP_CHANGELOG_REG.test('[X] 本条 PR 不需要纳入 changelog')).toBe(true)
})
})

0 comments on commit fb9407f

Please sign in to comment.