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

Label extractor question #607

Closed
Topi99 opened this issue Dec 2, 2021 · 2 comments
Closed

Label extractor question #607

Topi99 opened this issue Dec 2, 2021 · 2 comments
Assignees

Comments

@Topi99
Copy link

Topi99 commented Dec 2, 2021

Hi! I am experimenting with this action, but I'm having troubles while extracting the labels from my PR titles. I have the following naming convention: <type>: <title>. Some examples: feat: Add new button to menu, fix: Remove line causing bug. What could be the right pattern for my case?

Here is my current configuration:

{
  "categories": [
    {
      "title": "## 🚀 New Features",
      "labels": ["feat"]
    },
    {
      "title": "## 🐛 Fixes",
      "labels": ["fix"]
    },
    {
      "title": "## 🧪 Tests",
      "labels": ["test"]
    },
    {
        "title": "## 📦 Dependencies",
        "labels": ["deps"]
    },
    {
      "title": "## 📖 Documentation",
      "labels": ["docs"]
    },
    {
      "title": "## 🧹 Chores",
      "labels": ["chore"]
    }
  ],
  "ignore_labels": [
    "ignore"
  ],
  "sort": "ASC",
  "template": "${{CHANGELOG}}\n\n<details>\n<summary>Uncategorized</summary>\n\n${{UNCATEGORIZED}}\n</details>",
  "pr_template": "- ${{TITLE}}\n   - PR: #${{NUMBER}} labels: ${{LABELS}}",
  "empty_template": "- no changes",
  "label_extractor": [
    {
      "pattern": "^feat",
      "target": "feat",
      "on_property": "title"
    },
    {
      "pattern": "^test",
      "target": "test",
      "on_property": "title"
    },
    {
      "pattern": "^build",
      "target": "deps",
      "on_property": "title"
    },
    {
      "pattern": "^fix",
      "target": "fix",
      "on_property": "title"
    },
    {
      "pattern": "^docs",
      "target": "docs",
      "on_property": "title"
    },
    {
      "pattern": "^doc",
      "target": "docs",
      "on_property": "title"
    },
    {
      "pattern": "^chore",
      "target": "chore",
      "on_property": "title"
    }
  ]
}

I have tried several patterns but none seems to work (I'm new with regex).

Thanks in advance.

@mikepenz
Copy link
Owner

mikepenz commented Dec 3, 2021

@Topi99 you were already very close to the solution.

There are 2 variants the action offers the extractor to be used. One is replace and the other is match.
By default replace is used:

https://github.com/mikepenz/release-changelog-builder-action/blob/develop/src/transform.ts#L351-L361

Replace uses the title and replaces the section matched by the regex with the target.

In your case you want to use match instead though, which doesn't need a target and instead extracts the label from the title. ( It does: onValue.match(extractor.pattern))

So to solve your setup you want to adjust the transformers to:

{
      "pattern": "^feat",
      "on_property": "title"
      "method": "match"
}

Created also a sample testcase for you to quickly try things out:
https://github.com/mikepenz/release-changelog-builder-action/tree/feature/607_test

Checkout this branch, and after having done the normal node setup, you can run the test case via:

npm test -- extractor.test.ts

@mikepenz mikepenz self-assigned this Dec 3, 2021
@Topi99
Copy link
Author

Topi99 commented Dec 3, 2021

Thank you @mikepenz, it is working now. I also ran the tests and it is looking good. Now I am going to work on my transformers so I can get rid of the type of the PRs in the change log.

@Topi99 Topi99 closed this as completed Dec 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants