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

Use regex when comparing header types #220

Open
sidlatau opened this issue Dec 8, 2022 · 0 comments
Open

Use regex when comparing header types #220

sidlatau opened this issue Dec 8, 2022 · 0 comments

Comments

@sidlatau
Copy link

sidlatau commented Dec 8, 2022

Is your feature request related to a problem? Please describe.

I am using custom regex for allowed types:

headerPattern: '^(feat:|fix:|chore:|refact:|ci:|docs:|\[axof: \d+\]|\[axod: \d+\]) (.*)$'

As I understand I need to list all available types. But some of the types are regexes. The list looks like this:

          types: |
            feat:
            fix:
            chore:
            refact:
            ci:
            docs:
            [axof: \d+]
            [axod: \d+]

The problem is that regexes does not work for types, because types.includes(result.type) is used for the check.

Describe the solution you'd like

I would want to treat types as regexes:

function isUnknownType(type) {
    for (type of types) {
      const regex = new RegExp(type);
      if (regex.test(result.type)) {
        return false;
      }
    }
    return true;
  }
 ...
   if (isUnknownType(result.type)) {
    raiseError(
      `Unknown release type "${
      result.type
      }" found in pull request title "${prTitle}". \n\n${printAvailableTypes()}`
    );
  }

I have a working code in forked repository:
https://github.com/amannn/action-semantic-pull-request/compare/main...sidlatau:regex-title?expand=1

Would it be possible/useful for others to add such functionality in this action? Or maybe there is an other way how to do it without code changes?

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

1 participant