Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for moving uncategorized to a category with no labels #1013

Merged
merged 2 commits into from Jan 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 29 additions & 2 deletions dist/index.js
Expand Up @@ -133522,14 +133522,24 @@ const categorizePullRequests = (pullRequests, config) => {
return { ...category, pullRequests: [] }
})

const uncategorizedCategoryIndex = categories.findIndex(
(category) => category.labels.length === 0
)

const filterUncategorizedPullRequests = (pullRequest) => {
const labels = pullRequest.labels.nodes

if (
labels.length === 0 ||
!labels.some((label) => allCategoryLabels.has(label.name))
) {
uncategorizedPullRequests.push(pullRequest)
if (uncategorizedCategoryIndex === -1) {
uncategorizedPullRequests.push(pullRequest)
} else {
categorizedPullRequests[uncategorizedCategoryIndex].pullRequests.push(
pullRequest
)
}
return false
}
return true
Expand Down Expand Up @@ -133766,7 +133776,11 @@ const _ = __nccwpck_require__(90250)
const Joi = __nccwpck_require__(44010)
const { SORT_BY, SORT_DIRECTIONS } = __nccwpck_require__(11940)
const { DEFAULT_CONFIG } = __nccwpck_require__(85869)
const { validateReplacers, validateAutolabeler } = __nccwpck_require__(47282)
const {
validateReplacers,
validateAutolabeler,
validateCategories,
} = __nccwpck_require__(47282)
const merge = __nccwpck_require__(56323)

const schema = (context) => {
Expand Down Expand Up @@ -133915,6 +133929,8 @@ const validateSchema = (context, repoConfig) => {

if (error) throw error

validateCategories({ categories: config.categories })

try {
config.replacers = validateReplacers({
context,
Expand Down Expand Up @@ -134076,9 +134092,20 @@ function validateAutolabeler({ context, autolabeler }) {
.filter(Boolean)
}

function validateCategories({ categories }) {
if (
categories.filter((category) => category.labels.length === 0).length > 1
) {
throw new Error(
'Multiple categories detected with no labels.\nOnly one category with no labels is supported for uncategorized pull requests.'
)
}
}

exports.template = template
exports.validateReplacers = validateReplacers
exports.validateAutolabeler = validateAutolabeler
exports.validateCategories = validateCategories


/***/ }),
Expand Down
12 changes: 11 additions & 1 deletion lib/releases.js
Expand Up @@ -129,14 +129,24 @@ const categorizePullRequests = (pullRequests, config) => {
return { ...category, pullRequests: [] }
})

const uncategorizedCategoryIndex = categories.findIndex(
(category) => category.labels.length === 0
)

const filterUncategorizedPullRequests = (pullRequest) => {
const labels = pullRequest.labels.nodes

if (
labels.length === 0 ||
!labels.some((label) => allCategoryLabels.has(label.name))
) {
uncategorizedPullRequests.push(pullRequest)
if (uncategorizedCategoryIndex === -1) {
uncategorizedPullRequests.push(pullRequest)
} else {
categorizedPullRequests[uncategorizedCategoryIndex].pullRequests.push(
pullRequest
)
}
return false
}
return true
Expand Down
8 changes: 7 additions & 1 deletion lib/schema.js
Expand Up @@ -2,7 +2,11 @@ const _ = require('lodash')
const Joi = require('@hapi/joi')
const { SORT_BY, SORT_DIRECTIONS } = require('./sort-pull-requests')
const { DEFAULT_CONFIG } = require('./default-config')
const { validateReplacers, validateAutolabeler } = require('./template')
const {
validateReplacers,
validateAutolabeler,
validateCategories,
} = require('./template')
const merge = require('deepmerge')

const schema = (context) => {
Expand Down Expand Up @@ -151,6 +155,8 @@ const validateSchema = (context, repoConfig) => {

if (error) throw error

validateCategories({ categories: config.categories })

try {
config.replacers = validateReplacers({
context,
Expand Down
11 changes: 11 additions & 0 deletions lib/template.js
Expand Up @@ -76,6 +76,17 @@ function validateAutolabeler({ context, autolabeler }) {
.filter(Boolean)
}

function validateCategories({ categories }) {
if (
categories.filter((category) => category.labels.length === 0).length > 1
) {
throw new Error(
'Multiple categories detected with no labels.\nOnly one category with no labels is supported for uncategorized pull requests.'
)
}
}

exports.template = template
exports.validateReplacers = validateReplacers
exports.validateAutolabeler = validateAutolabeler
exports.validateCategories = validateCategories
@@ -0,0 +1,13 @@
template: |
# What's Changed

$CHANGES

categories:
- title: 馃殌 Features
labels:
- feature
- title: 馃悰 Bug Fixes
labels:
- fix
- title: 馃摑 Other Changes
56 changes: 56 additions & 0 deletions test/index.test.js
Expand Up @@ -916,6 +916,62 @@ describe('release-drafter', () => {
expect.assertions(1)
})

it('categorizes pull requests with other category at the bottom', async () => {
getConfigMock('config-with-categories-with-other-category.yml')

nock('https://api.github.com')
.get('/repos/toolmantim/release-drafter-test-project/releases')
.query(true)
.reply(200, [releasePayload])

nock('https://api.github.com')
.post('/graphql', (body) =>
body.query.includes('query findCommitsWithAssociatedPullRequests')
)
.reply(200, graphqlCommitsMergeCommit)

nock('https://api.github.com')
.post(
'/repos/toolmantim/release-drafter-test-project/releases',
(body) => {
expect(body).toMatchInlineSnapshot(`
Object {
"body": "# What's Changed

## 馃殌 Features

* Add big feature (#2) @TimonVS
* 馃懡 Add alien technology (#1) @TimonVS

## 馃悰 Bug Fixes

* Bug fixes (#3) @TimonVS

## 馃摑 Other Changes

* Add documentation (#5) @TimonVS
* Update dependencies (#4) @TimonVS
",
"draft": true,
"name": "",
"prerelease": false,
"tag_name": "",
"target_commitish": "",
}
`)
return true
}
)
.reply(200, releasePayload)

await probot.receive({
name: 'push',
payload: pushPayload,
})

expect.assertions(1)
})

it('categorizes pull requests with multiple labels', async () => {
getConfigMock('config-with-categories-2.yml')

Expand Down
35 changes: 34 additions & 1 deletion test/schema.test.js
@@ -1,4 +1,4 @@
const { schema } = require('../lib/schema')
const { schema, validateSchema } = require('../lib/schema')
const schemaJson = require('../schema.json')
const { jsonSchema } = require('../bin/generate-schema')

Expand Down Expand Up @@ -73,4 +73,37 @@ describe('schema', () => {
it('current schema matches the generated JSON Schema, update schema with `yarn generate-schema`', () => {
expect(jsonSchema).toMatchObject(schemaJson)
})

describe('validateSchema', () => {
it('Multiple other categories', () => {
expect(() => {
validateSchema(context, {
template,
categories: [
{
title: '馃摑 Other Changes',
},
{
title: '馃摑 Yet Other Changes',
},
],
})
}).toThrowErrorMatchingInlineSnapshot(`
"Multiple categories detected with no labels.
Only one category with no labels is supported for uncategorized pull requests."
`)
})

it('Single other categories', () => {
const expected = {
template,
categories: [
{
title: '馃摑 Other Changes',
},
],
}
expect(validateSchema(context, expected)).toMatchObject(expected)
})
})
})