mikepenz/release-changelog-builder-action

Filter PR's based on author

paul-dingemans opened this issue ยท 9 comments

Currently PR are categorized using labels. It would be cool if PR's could alternatively be categorized on author. In this way, a category like "dependencies" could filter on author "renovate".

I found that this is already possible using a label_extractor.

    "label_extractor": [
        {
          "pattern": "renovate\\[bot\\]",
          "on_property": "author",
          "method": "replace",
          "target": "dependency"
        }
      ],

@paul-dingemans there is also a different feature which is a bit newer than label_extractors you can use.

Categories can have rules provided in addition to organize PRs in categories. An example test:

it('Use Rules to include a PR within a Category.', async () => {
const customConfig = Object.assign({}, DefaultConfiguration)
customConfig.categories = [
{
title: '## ๐Ÿš€ Features But No ๐Ÿ› Fixes and only merged with a title containing `[ABC-1234]`',
labels: ['Feature'],
exclude_labels: ['Fix'],
rules: [
{
pattern: '\\[ABC-1234\\]',
on_property: 'title'
},
{
pattern: 'merged',
on_property: 'status'
}
],
exhaustive: true
}
]
expect(buildChangelogTest(customConfig, pullRequestsWithLabels)).toStrictEqual(
`## ๐Ÿš€ Features But No ๐Ÿ› Fixes and only merged with a title containing \`[ABC-1234]\`\n\n- [ABC-1234] - this is a PR 1 title message\n - PR: #1\n\n`
)
})

(this feature is best used with v4 though)

I like syntax above. Unfortunately, it does not seem to work in my use case. After changing the code my action flow throws and error. None of the PR's seems to be categorized anymore. Am I missing something?

Screenshot 2023-08-26 at 17 43 31

It seems there is a problem in the syntax of the config.

Screenshot 2023-08-26 at 17 44 03

looks there is a , missing.

One additional advice. Looking at the output for the shell output. you get a bunch of errors as it writes the string as non escaped string.

Screenshot 2023-08-26 at 17 45 55

The reason for that is how GitHub Actions replaces the template. It basically just puts the string from the variable into that specific location. In non escaped form.

https://github.com/pinterest/ktlint/blob/master/.github/workflows/generate-changelog.yml#L80

So if you want to output it in bash or use in bash, I highly recommend you setting it into an env variable (this is not specific to this action, but general advice for GitHub actions)

E.g. something along those lines:
https://github.com/mikepenz/release-changelog-builder-action/blob/develop/.github/workflows/ci.yml#L165-L174

Note that my workflow did work before I change to using category.rules.

The label dependency changelog is just a single label and should not be separated by a comma.

Is it allowed to have both labels and rules defined for a single category? According to the documentation it is allowed. In this particular case, I would like to select all PR's for which either the label or the rule is met. After replacing the selection on label with a rule (see pinterest/ktlint#2212) the output is generated correctly.

I'm currently on the phone so I'll only answer briefly.

I see that it is only a single item, however you miss the comma afterwards, before the next item in the JSON.

Yes it is allowed to have both.

Yes, was my mistake. I am so used to the editor highlight and use of trailing comma's that I completely overlooked that.