Skip to content

Commit

Permalink
Merge pull request #10 from jotoeri/enh/excludeLabels
Browse files Browse the repository at this point in the history
Allow configurable label exclusion
  • Loading branch information
jotoeri authored Dec 28, 2024
2 parents aa1f551 + 3b84a71 commit 54048cc
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 22 deletions.
7 changes: 3 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
Use as:
`npm run generate -- --version=3.3.0`

CLI Options
The following options can be given to the script either via CLI Argument or as a key value pair in a file named `config.json` in the repository root.
- `ghtoken` - Token to access github. Necessary for large number of requests.
- `repository` - including org and repository -> e.g. `nextcloud/forms`
- `repository` - including owner and repository -> e.g. `nextcloud/forms`
- `base` - Base-Branch, the PRs are merged to. Defaults to `main`
- `out` - Output Filename. Defaults to `nc_changelog.md`
- `releaseDate` - Date of the new release. Defaults to today's date.
- `version` - Tag-Name of upcoming release.
- `previousVersion` - Tag-Name of the previous release. Defaults to latest Github release.

All these options are possible to store a default value in a file named `config.json` in the repository root. Such they dont have to be given on each execution.
- `excludeLabels` - Array of strings. PRs which contain at least one of the given labels will be excluded. Defaults to `["dependencies"]`. As CLI Argument these should be given as comma-separated list, e.g. `--excludeLabels=dependencies,translations`
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import writeOut from './utils/writeOut.js'

const runtimeConfig = createRuntimeConfig()

if (!runtimeConfig.repository) throw 'No repository given! Aborting.'

octoInit(runtimeConfig.ghtoken)

if (!runtimeConfig.previousVersion) {
Expand Down
7 changes: 3 additions & 4 deletions utils/checkPrUsable.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import findLabel from "./findLabel.js"
import findLabels from "./findLabels.js"

/**
* Check if a fetched PR is usable for us.
Expand All @@ -13,9 +13,8 @@ function checkPrUsable (pr, runtimeConfig, oldestDate) {
return false
}

// Remove dependencies
if (findLabel(pr, 'dependencies')) {
// console.debug('Dependencies')
// Remove exclude labeled PRs
if (findLabels(pr, runtimeConfig.excludeLabels)) {
return false
}

Expand Down
6 changes: 3 additions & 3 deletions utils/createMdContent.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import filterRemainder from "./filterRemainder.js"
import findLabel from "./findLabel.js"
import findLabels from "./findLabels.js"

/**
* Function to create the Markdown Content out of the given PRs
Expand All @@ -19,7 +19,7 @@ const createMdContent = function (runtimeConfig, pulls) {
content += `\n[Full Changelog](https://github.com/${runtimeConfig.repository}/compare/${runtimeConfig.previousVersion}...${runtimeConfig.version})\n`

// Add Enhancements
;({filtered, remainder} = filterRemainder(remainder, findLabel, ['enhancement'])) // Outer brackets and preceding semicolon necessary for destructuring.
;({filtered, remainder} = filterRemainder(remainder, findLabels, [['enhancement']])) // Outer brackets and preceding semicolon necessary for destructuring.
if (filtered.length) {
content += `\n### Enhancements\n`
filtered.forEach(pull =>
Expand All @@ -28,7 +28,7 @@ const createMdContent = function (runtimeConfig, pulls) {
}

// Add Bugs
;({filtered, remainder} = filterRemainder(remainder, findLabel, ['bug'])) // Outer brackets and preceding semicolon necessary for destructuring.
;({filtered, remainder} = filterRemainder(remainder, findLabels, [['bug']])) // Outer brackets and preceding semicolon necessary for destructuring.
if (filtered.length) {
content += `\n### Fixed\n`
filtered.forEach(pull =>
Expand Down
4 changes: 4 additions & 0 deletions utils/createRuntimeConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ function createRuntimeConfig() {
runtimeConfig.releaseDate = now.toLocaleDateString('sv')
}

// Read exclude labels
runtimeConfig.excludeLabels = processArgs.excludeLabels ? processArgs.excludeLabels.split(",") :
(configFile.excludeLabels ? configFile.excludeLabels : ['dependencies'])

// Read outFile
runtimeConfig.outFile = processArgs.out ? processArgs.out :
(configFile.out ? configFile.out : 'nc_changelog.md')
Expand Down
11 changes: 0 additions & 11 deletions utils/findLabel.js

This file was deleted.

13 changes: 13 additions & 0 deletions utils/findLabels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Check if PR contains Labels
* @param {Object} pull Pull-Request Object to check
* @param {Array.<string>} labels Array of labels to check for
* @returns {Boolean} Label found
*/
const findLabels = function (pull, labels) {
return labels.some(searchL => {
return pull.labels.some(l => l.name === searchL)
})
}

export default findLabels

0 comments on commit 54048cc

Please sign in to comment.