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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: handle release branching strategy #1359

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -143,6 +143,7 @@ You can configure Release Drafter using the following key in your `.github/relea
| `version-resolver` | Optional | Adjust the `$RESOLVED_VERSION` variable using labels. Refer to [Version Resolver](#version-resolver) to learn more about this |
| `commitish` | Optional | The release target, i.e. branch or commit it should point to. Default: the ref that release-drafter runs for, e.g. `refs/heads/master` if configured to run on pushes to `master`. |
| `filter-by-commitish` | Optional | Filter previous releases to consider only those with the target matching `commitish`. Default: `false`. |
| `filter-by-regex` | Optional | Filter previous releases to consider only those with the target matching this regex. |
| `include-paths` | Optional | Restrict pull requests included in the release notes to only the pull requests that modified any of the paths in this array. Supports files and directories. Default: `[]` |

Release Drafter also supports [Probot Config](https://github.com/probot/probot-config), if you want to store your configuration files in a central repository. This allows you to share configurations between projects, and create a organization-wide configuration file by creating a repository named `.github` with the file `.github/release-drafter.yml`.
Expand Down
14 changes: 12 additions & 2 deletions dist/index.js
Expand Up @@ -142357,6 +142357,7 @@ module.exports = (app, { getRouter }) => {

const {
'filter-by-commitish': filterByCommitish,
'filter-by-regex': filterByRegex,
'include-pre-releases': includePreReleases,
'prerelease-identifier': preReleaseIdentifier,
'tag-prefix': tagPrefix,
Expand All @@ -142372,6 +142373,7 @@ module.exports = (app, { getRouter }) => {
context,
targetCommitish,
filterByCommitish,
filterByRegex,
includePreReleases: shouldIncludePreReleases,
tagPrefix,
})
Expand Down Expand Up @@ -142945,6 +142947,7 @@ const findReleases = async ({
context,
targetCommitish,
filterByCommitish,
filterByRegex,
includePreReleases,
tagPrefix,
}) => {
Expand Down Expand Up @@ -142975,9 +142978,16 @@ const findReleases = async ({
targetCommitishName === r.target_commitish.replace(headRefRegex, '')
)
: releases
const filteredReleases = tagPrefix
? commitishFilteredReleases.filter((r) => r.tag_name.startsWith(tagPrefix))
const regexFilteredReleases = filterByRegex
? commitishFilteredReleases.filter((r) =>
new RegExp(filterByRegex).test(
r.target_commitish.replace(headRefRegex, '')
)
)
: commitishFilteredReleases
const filteredReleases = tagPrefix
? regexFilteredReleases.filter((r) => r.tag_name.startsWith(tagPrefix))
: regexFilteredReleases
const sortedSelectedReleases = sortReleases(
filteredReleases.filter(
(r) => !r.draft && (!r.prerelease || includePreReleases)
Expand Down
2 changes: 2 additions & 0 deletions index.js
Expand Up @@ -154,6 +154,7 @@ module.exports = (app, { getRouter }) => {

const {
'filter-by-commitish': filterByCommitish,
'filter-by-regex': filterByRegex,
'include-pre-releases': includePreReleases,
'prerelease-identifier': preReleaseIdentifier,
'tag-prefix': tagPrefix,
Expand All @@ -169,6 +170,7 @@ module.exports = (app, { getRouter }) => {
context,
targetCommitish,
filterByCommitish,
filterByRegex,
includePreReleases: shouldIncludePreReleases,
tagPrefix,
})
Expand Down
12 changes: 10 additions & 2 deletions lib/releases.js
Expand Up @@ -29,6 +29,7 @@ const findReleases = async ({
context,
targetCommitish,
filterByCommitish,
filterByRegex,
includePreReleases,
tagPrefix,
}) => {
Expand Down Expand Up @@ -59,9 +60,16 @@ const findReleases = async ({
targetCommitishName === r.target_commitish.replace(headRefRegex, '')
)
: releases
const filteredReleases = tagPrefix
? commitishFilteredReleases.filter((r) => r.tag_name.startsWith(tagPrefix))
const regexFilteredReleases = filterByRegex
? commitishFilteredReleases.filter((r) =>
new RegExp(filterByRegex).test(
r.target_commitish.replace(headRefRegex, '')
)
)
: commitishFilteredReleases
const filteredReleases = tagPrefix
? regexFilteredReleases.filter((r) => r.tag_name.startsWith(tagPrefix))
: regexFilteredReleases
const sortedSelectedReleases = sortReleases(
filteredReleases.filter(
(r) => !r.draft && (!r.prerelease || includePreReleases)
Expand Down
71 changes: 46 additions & 25 deletions test/releases.test.js
Expand Up @@ -237,8 +237,19 @@ describe('releases', () => {
})

describe('findReleases', () => {
const paginateMock = jest.fn()
const context = {
payload: { repository: { full_name: 'test' } },
octokit: {
paginate: paginateMock,
repos: { listReleases: { endpoint: { merge: jest.fn() } } },
},
repo: jest.fn(),
log: { info: jest.fn(), warn: jest.fn() },
}

it('should retrieve last release respecting semver, stripped prefix', async () => {
const paginate = jest.fn().mockResolvedValue([
paginateMock.mockResolvedValue([
{
tag_name: 'test-1.0.1',
target_commitish: 'master',
Expand All @@ -251,19 +262,6 @@ describe('releases', () => {
},
])

const context = {
log: {
info: jest.fn(),
},
repo: jest.fn(),
payload: {
repository: 'test',
},
octokit: {
paginate,
repos: { listReleases: { endpoint: { merge: jest.fn() } } },
},
}
const targetCommitish = 'refs/heads/master'
const filterByCommitish = ''
const tagPrefix = 'test-'
Expand All @@ -277,17 +275,6 @@ describe('releases', () => {
expect(lastRelease.tag_name).toEqual('test-1.0.1')
})

const paginateMock = jest.fn()
const context = {
payload: { repository: { full_name: 'test' } },
octokit: {
paginate: paginateMock,
repos: { listReleases: { endpoint: { merge: jest.fn() } } },
},
repo: jest.fn(),
log: { info: jest.fn(), warn: jest.fn() },
}

it('should return last release without draft and prerelease', async () => {
paginateMock.mockResolvedValueOnce([
{ tag_name: 'v1.0.0', draft: true, prerelease: false },
Expand Down Expand Up @@ -348,5 +335,39 @@ describe('releases', () => {
prerelease: true,
})
})

it('should retrieve last release respecting filterByRegex', async () => {
paginateMock.mockResolvedValue([
{
tag_name: '1.1.1',
target_commitish: 'hotfix-1.1.1',
created_at: '2022-06-29T05:45:15Z',
},
{
tag_name: '1.1.0',
target_commitish: 'release-1.1.0',
created_at: '2021-06-29T05:45:15Z',
},
{
tag_name: '1.0.0',
target_commitish: 'release-1.0.0',
created_at: '2020-06-29T05:45:15Z',
},
])

const targetCommitish = 'refs/heads/release-1.2.0'
const filterByCommitish = ''
const filterByRegex = '^release-[0-9]+\\.[0-9]+\\.[0-9]+$'
const tagPrefix = ''

const { lastRelease } = await findReleases({
context,
targetCommitish,
filterByCommitish,
filterByRegex,
tagPrefix,
})
expect(lastRelease.tag_name).toEqual('1.1.0')
})
})
})