Skip to content

Commit

Permalink
Merge pull request #1133 from mikepenz/feature/1074
Browse files Browse the repository at this point in the history
Offer new API to reference parent / child PR relations
  • Loading branch information
mikepenz committed Jun 4, 2023
2 parents b691df6 + 1f64818 commit e4b8b13
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 11 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ This configuration is a `JSON` in the following format. (The below showcases *ex
"on_property": "title",
"method": "match"
},
"reference": {
"pattern": ".*\\ \\#(.).*",
"on_property": "body",
"method": "replace",
"target": "$1"
},
"transformers": [
{
"pattern": "[\\-\\*] (\\[(...|TEST|CI|SKIP)\\])( )?(.+?)\n(.+?[\\-\\*] )(.+)",
Expand Down Expand Up @@ -371,8 +377,10 @@ When using `*` values are joined by `,`.
| `${{REVIEWERS[*]}}` | GitHub Login names of specified reviewers. Requires `fetchReviewers` to be enabled. |
| `${{APPROVERS[*]}}` | GitHub Login names of users who approved the PR. |

Additionally there is a special array placeholder `REVIEWS` which allows access to it's properties:
`(KEY)[(*/index)].(property)` for example: `REVIEWS[*].author` or `REVIEWS[*].body`
Additionally there are special array placeholders like `REVIEWS` which allows access to it's properties via
`(KEY)[(*/index)].(property)`.

For example: `REVIEWS[*].author` or `REVIEWS[*].body`

| **Placeholder** | **Description** |
|-------------------------------|--------------------------------------------|
Expand All @@ -382,6 +390,14 @@ Additionally there is a special array placeholder `REVIEWS` which allows access
| `${{REVIEWS[*].submittedAt}}` | The date whent he review was submitted. |
| `${{REVIEWS[*].state}}` | The state of the given review. |

Similar to `REVIEWS`, `REFERENCED` PRs also offer special placeholders.

| **Placeholder** | **Description** |
|-------------------------------|---------------------------------------------------------------------------|
| `${{REFERENCED[*].number}}` | The PR number of the referenced PR. |
| `${{REFERENCED[*].title}}` | The title of the referenced PR. |
| `${{REFERENCED[*]."..."}}` | Allows to use most other PR properties as placeholder. |

</p>
</details>

Expand Down Expand Up @@ -448,6 +464,7 @@ Table of descriptions for the `configuration.json` options to configure the resu
| label_extractor.flags | Defines the regex flags specified for the pattern. Default: `gu`. |
| label_extractor.on_empty | Defines the placeholder to be filled in, if the regex does not lead to a result. |
| duplicate_filter | Defines the `Extractor` to use for retrieving the identifier for a PR. In case of duplicates will keep the last matching pull request (depends on `sort`). See `label_extractor` for details on `Extractor` properties. |
| reference | Defines the `Extractor` to use for resolving the "PR-number" for a parent PR. In case of a match, the child PR will not be included in the release notes. See `label_extractor` for details on `Extractor` properties. |
| transformers | An array of `transform` specifications, offering a flexible API to modify the text per pull request. This is applied on the change text created with `pr_template`. `transformers` are executed per change, in the order specified |
| transformer.pattern | A `regex` pattern, extracting values of the change message. |
| transformer.target | The result pattern, the regex groups will be filled into. Allows for full transformation of a pull request message. Including potentially specified texts |
Expand Down
22 changes: 21 additions & 1 deletion __tests__/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ pullRequestsWithLabels.push(
repoName: 'test-repo',
labels: ['issue', 'fix'],
milestone: '',
body: 'no magic body for this matter',
body: 'no magic body for this matter - #1',
assignees: [],
requestedReviewers: [],
approvedReviewers: [],
Expand Down Expand Up @@ -399,6 +399,26 @@ it('Deduplicate duplicated PRs DESC', async () => {
)
})

it('Reference PRs', async () => {
const customConfig = Object.assign({}, DefaultConfiguration)
customConfig.categories = [
{
title: '',
labels: []
}
]
customConfig.pr_template = "${{NUMBER}} -- ${{REFERENCED[*].number}}"
customConfig.reference = {
pattern: '.*\ \#(.).*', // matches the 1 from "abcdefg #1 adfasdf"
on_property: 'body',
method: 'replace',
target: '$1'
}
expect(buildChangelogTest(customConfig, pullRequestsWithLabels)).toStrictEqual(
`1 -- 2\n4 -- \n3 -- \n\n`
)
})

it('Use empty_content for empty category', async () => {
const customConfig = Object.assign({}, DefaultConfiguration)
customConfig.categories = [
Expand Down
88 changes: 85 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions pr-collector/src/pullRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@ export interface CommentInfo {
state: string | undefined
}

export const EMPTY_PULL_REQUEST_INFO: PullRequestInfo = {
number: 0,
title: "",
htmlURL: "",
baseBranch: "",
mergedAt: undefined,
createdAt: moment(),
mergeCommitSha: "",
author: "",
repoName: "",
labels: [],
milestone: "",
body: "",
assignees: [],
requestedReviewers: [],
approvedReviewers: [],
status: 'open'
}

export const EMPTY_COMMENT_INFO: CommentInfo = {
id: 0,
htmlURL: '',
Expand Down
1 change: 1 addition & 0 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface Configuration extends PullConfiguration {
ignore_labels: string[]
label_extractor: Extractor[]
duplicate_filter?: Extractor // extract an identifier from a PR used to detect duplicates, will keep the last match (depends on `sort`)
reference?: Extractor // extracts a reference from a PR, used to establish parent child relations. This will remove the child from the main PR list.
transformers: Transformer[]
tag_resolver: TagResolver
base_branches: string[]
Expand Down

0 comments on commit e4b8b13

Please sign in to comment.