-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from willemduncan/otherSection
Feat: Add option to also output uncategorized PRs
- Loading branch information
Showing
11 changed files
with
251 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export interface Configuration { | ||
/** Main title of the changelog. */ | ||
title: string | null, | ||
/** Explicit section definitions. */ | ||
sections: { title: string, prefixes: string[] }[], | ||
/** If not null, put any items that do not match an explicit section under this title. */ | ||
otherSectionTitle: string | null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import * as core from '@actions/core'; | ||
import { Configuration } from './configuration'; | ||
import { Changelog, Issue } from './models'; | ||
|
||
/** | ||
* Create a changelog model from a collection of issues. | ||
* @param items The items to use as base collection. | ||
*/ | ||
export function createChangelog(items: Issue[], config: Configuration): Changelog { | ||
core.info(`Create changelog for ${items.length} items.`); | ||
|
||
const result: Changelog = { | ||
title: config.title, | ||
sections: [] | ||
}; | ||
|
||
const addSection = (title: string, items: { title: string, item: Issue }[]) => { | ||
core.info(`Create changelog section '${title}' with ${items.length} items.`); | ||
if (items.length > 0) { | ||
result.sections.push({ title, items }); | ||
} | ||
}; | ||
|
||
config.sections.forEach(s => | ||
addSection(s.title, getItemsByPrefix(items, s.prefixes)) | ||
); | ||
|
||
if (config.otherSectionTitle) { | ||
// Take all items except those already in a section. | ||
addSection(config.otherSectionTitle, items | ||
.filter(i => !result.sections.some(s => s.items.some(si => si.item === i))) | ||
.map(i => ({ | ||
title: i.title, | ||
item: i | ||
}))); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
/** | ||
* Filter a collection of issues. | ||
* @param items The items to filter. | ||
* @param prefixes The prefixes to filter. | ||
*/ | ||
function getItemsByPrefix(items: Issue[], prefixes: string[]) { | ||
const regex = new RegExp(`^(${prefixes.join('|')})?:?\\s+`, 'i'); | ||
return items | ||
// Match with allowed prefixes | ||
.map(item => ({ | ||
data: item, | ||
match: regex.exec(item.title) | ||
})) | ||
// Filter by positive matches. | ||
.filter(item => item.match) | ||
// Create title without filtered prefix. | ||
.map(item => ({ | ||
title: item.data.title.substring(item.match![0].length), | ||
item: item.data | ||
})); | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.