Skip to content

git_changelog ¤

git-changelog package.

Automatic Changelog generator using Jinja2 templates.

Modules:

  • build

    The module responsible for building the data.

  • cli

    Module that contains the command line application.

  • commit

    Module containing the commit logic.

  • debug

    Debugging utilities.

  • providers

    Module containing the parsing utilities for git providers.

  • templates

    The subpackage containing the builtin templates.

  • versioning

    Utilities to handle different versioning schemes such as SemVer and PEP 440.

Classes:

  • Bitbucket

    A parser for the Bitbucket references.

  • Changelog

    The main changelog class.

  • Commit

    A class to represent a commit.

  • GitHub

    A parser for the GitHub references.

  • GitLab

    A parser for the GitLab references.

Bitbucket ¤

Bitbucket(
    namespace: str, project: str, url: str | None = None
)

Bases: ProviderRefParser

A parser for the Bitbucket references.

Parameters:

  • namespace (str) –

    The Bitbucket namespace.

  • project (str) –

    The Bitbucket project.

  • url (str | None, default: None ) –

    The Bitbucket URL.

Methods:

  • get_refs

    Find all references in the given text.

  • parse_refs

    Parse references in the given text.

Source code in src/git_changelog/providers.py
64
65
66
67
68
69
70
71
72
73
74
def __init__(self, namespace: str, project: str, url: str | None = None):
    """Initialization method.

    Arguments:
        namespace: The Bitbucket namespace.
        project: The Bitbucket project.
        url: The Bitbucket URL.
    """
    self.namespace: str = namespace
    self.project: str = project
    self.url: str = url or self.url

get_refs ¤

get_refs(ref_type: str, text: str) -> list[Ref]

Find all references in the given text.

Parameters:

  • ref_type (str) –

    The reference type.

  • text (str) –

    The text in which to search references.

Returns:

  • list[Ref]

    A list of references (instances of Ref).

Source code in src/git_changelog/providers.py
76
77
78
79
80
81
82
83
84
85
86
87
88
89
def get_refs(self, ref_type: str, text: str) -> list[Ref]:
    """Find all references in the given text.

    Arguments:
        ref_type: The reference type.
        text: The text in which to search references.

    Returns:
        A list of references (instances of [Ref][git_changelog.providers.Ref]).
    """
    return [
        Ref(ref=match.group().strip(), url=self.build_ref_url(ref_type, match.groupdict()))
        for match in self.parse_refs(ref_type, text)
    ]

parse_refs ¤

parse_refs(ref_type: str, text: str) -> list[Match]

Parse references in the given text.

Parameters:

  • ref_type (str) –

    The reference type.

  • text (str) –

    The text to parse.

Returns:

  • list[Match]

    A list of regular expressions matches.

Source code in src/git_changelog/providers.py
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
def parse_refs(self, ref_type: str, text: str) -> list[Match]:
    """Parse references in the given text.

    Arguments:
        ref_type: The reference type.
        text: The text to parse.

    Returns:
        A list of regular expressions matches.
    """
    if ref_type not in self.REF:
        refs = [key for key in self.REF if key.startswith(ref_type)]
        return [match for ref in refs for match in self.REF[ref].regex.finditer(text)]
    return list(self.REF[ref_type].regex.finditer(text))

Changelog ¤

Changelog(
    repository: str | Path,
    *,
    provider: (
        ProviderRefParser | type[ProviderRefParser] | None
    ) = None,
    convention: ConventionType | None = None,
    parse_provider_refs: bool = False,
    parse_trailers: bool = False,
    sections: list[str] | None = None,
    bump_latest: bool = False,
    bump: str | None = None,
    zerover: bool = True,
    filter_commits: str | None = None,
    versioning: Literal["semver", "pep440"] = "semver"
)

The main changelog class.

Parameters:

  • repository (str | Path) –

    The repository (directory) for which to build the changelog.

  • provider (ProviderRefParser | type[ProviderRefParser] | None, default: None ) –

    The provider to use (github.com, gitlab.com, etc.).

  • convention (ConventionType | None, default: None ) –

    The commit convention to use (angular, etc.).

  • parse_provider_refs (bool, default: False ) –

    Whether to parse provider-specific references in the commit messages.

  • parse_trailers (bool, default: False ) –

    Whether to parse Git trailers in the commit messages.

  • sections (list[str] | None, default: None ) –

    The sections to render (features, bug fixes, etc.).

  • bump_latest (bool, default: False ) –

    Deprecated, use bump="auto" instead. Whether to try and bump latest version to guess new one.

  • bump (str | None, default: None ) –

    Whether to try and bump to a given version.

  • zerover (bool, default: True ) –

    Keep major version at zero, even for breaking changes.

  • filter_commits (str | None, default: None ) –

    The Git revision-range used to filter commits in git-log (e.g: v1.0.1..).

Methods:

  • get_log

    Get the git log output.

  • get_remote_url

    Get the git remote URL for the repository.

  • parse_commits

    Parse the output of 'git log' into a list of commits.

  • run_git

    Run a git command in the chosen repository.

Source code in src/git_changelog/build.py
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
def __init__(
    self,
    repository: str | Path,
    *,
    provider: ProviderRefParser | type[ProviderRefParser] | None = None,
    convention: ConventionType | None = None,
    parse_provider_refs: bool = False,
    parse_trailers: bool = False,
    sections: list[str] | None = None,
    bump_latest: bool = False,
    bump: str | None = None,
    zerover: bool = True,
    filter_commits: str | None = None,
    versioning: Literal["semver", "pep440"] = "semver",
):
    """Initialization method.

    Arguments:
        repository: The repository (directory) for which to build the changelog.
        provider: The provider to use (github.com, gitlab.com, etc.).
        convention: The commit convention to use (angular, etc.).
        parse_provider_refs: Whether to parse provider-specific references in the commit messages.
        parse_trailers: Whether to parse Git trailers in the commit messages.
        sections: The sections to render (features, bug fixes, etc.).
        bump_latest: Deprecated, use `bump="auto"` instead. Whether to try and bump latest version to guess new one.
        bump: Whether to try and bump to a given version.
        zerover: Keep major version at zero, even for breaking changes.
        filter_commits: The Git revision-range used to filter commits in git-log (e.g: `v1.0.1..`).
    """
    self.repository: str | Path = repository
    self.parse_provider_refs: bool = parse_provider_refs
    self.parse_trailers: bool = parse_trailers
    self.zerover: bool = zerover
    self.filter_commits: str | None = filter_commits

    # set provider
    if not isinstance(provider, ProviderRefParser):
        remote_url = self.get_remote_url()
        split = remote_url.split("/")
        provider_url = "/".join(split[:3])
        namespace, project = "/".join(split[3:-1]), split[-1]
        if callable(provider):
            provider = provider(namespace, project, url=provider_url)
        elif "github" in provider_url:
            provider = GitHub(namespace, project, url=provider_url)
        elif "gitlab" in provider_url:
            provider = GitLab(namespace, project, url=provider_url)
        elif "bitbucket" in provider_url:
            provider = Bitbucket(namespace, project, url=provider_url)
        else:
            provider = None
        self.remote_url: str = remote_url
    self.provider = provider

    # set convention
    if isinstance(convention, str):
        try:
            convention = self.CONVENTION[convention]()
        except KeyError:
            print(  # noqa: T201
                f"git-changelog: no such convention available: {convention}, using default convention",
                file=sys.stderr,
            )
            convention = BasicConvention()
    elif convention is None:
        convention = BasicConvention()
    elif not isinstance(convention, CommitConvention) and issubclass(convention, CommitConvention):
        convention = convention()
    self.convention: CommitConvention = convention

    # set sections
    sections = (
        [self.convention.TYPES[section] for section in sections] if sections else self.convention.DEFAULT_RENDER
    )
    self.sections = sections

    # get version parser based on selected versioning scheme
    self.version_parser, self.version_bumper = {
        "semver": (parse_semver, bump_semver),
        "pep440": (parse_pep440, bump_pep440),
    }[versioning]

    # get git log and parse it into list of commits
    self.raw_log: str = self.get_log()
    self.commits: list[Commit] = self.parse_commits()
    self.tag_commits: list[Commit] = [commit for commit in self.commits[1:] if commit.tag]
    self.tag_commits.insert(0, self.commits[0])

    # apply dates to commits and group them by version
    v_list, v_dict = self._group_commits_by_version()
    self.versions_list = v_list
    self.versions_dict = v_dict

    # TODO: remove at some point
    if bump_latest:
        warnings.warn(
            "`bump_latest=True` is deprecated in favor of `bump='auto'`",
            DeprecationWarning,
            stacklevel=1,
        )
        if bump is None:
            bump = "auto"
    if bump:
        self._bump(bump)

get_log ¤

get_log() -> str

Get the git log output.

Returns:

  • str

    The output of the git log command, with a particular format.

Source code in src/git_changelog/build.py
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
def get_log(self) -> str:
    """Get the `git log` output.

    Returns:
        The output of the `git log` command, with a particular format.
    """
    if self.filter_commits:
        try:
            return self.run_git("log", "--date=unix", "--format=" + self.FORMAT, self.filter_commits)
        except CalledProcessError as e:
            raise ValueError(
                f"An error ocurred. Maybe the provided git-log revision-range is not valid: '{self.filter_commits}'",
            ) from e

    # No revision-range provided. Call normally
    return self.run_git("log", "--date=unix", "--format=" + self.FORMAT)

get_remote_url ¤

get_remote_url() -> str

Get the git remote URL for the repository.

Returns:

  • str

    The origin remote URL.

Source code in src/git_changelog/build.py
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
def get_remote_url(self) -> str:
    """Get the git remote URL for the repository.

    Returns:
        The origin remote URL.
    """
    remote = "remote." + os.environ.get("GIT_CHANGELOG_REMOTE", "origin") + ".url"
    git_url = self.run_git("config", "--default", "", "--get", remote).rstrip("\n")
    if git_url.startswith("git@"):
        git_url = git_url.replace(":", "/", 1).replace("git@", "https://", 1)
    if git_url.endswith(".git"):
        git_url = git_url[:-4]

    # Remove credentials from the URL.
    if git_url.startswith(("http://", "https://")):
        # (addressing scheme, network location, path, query, fragment identifier)
        urlparts = list(urlsplit(git_url))
        urlparts[1] = urlparts[1].split("@", 1)[-1]
        git_url = urlunsplit(urlparts)

    return git_url

parse_commits ¤

parse_commits() -> list[Commit]

Parse the output of 'git log' into a list of commits.

The commits build a Git commit graph by referencing their parent commits. Commits are ordered from newest to oldest.

Returns:

Source code in src/git_changelog/build.py
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
def parse_commits(self) -> list[Commit]:
    """Parse the output of 'git log' into a list of commits.

    The commits build a Git commit graph by referencing their parent commits.
    Commits are ordered from newest to oldest.

    Returns:
        The list of commits.
    """
    lines = self.raw_log.split("\n")
    size = len(lines) - 1  # Don't count last blank line.
    pos = 0

    commits_map: dict[str, Commit] = {}

    while pos < size:
        # Build message body.
        nbl_index = 10
        body = []
        while lines[pos + nbl_index] != self.MARKER:
            body.append(lines[pos + nbl_index].strip("\r"))
            nbl_index += 1

        # Build commit object.
        commit = Commit(
            commit_hash=lines[pos],
            author_name=lines[pos + 1],
            author_email=lines[pos + 2],
            author_date=lines[pos + 3],
            committer_name=lines[pos + 4],
            committer_email=lines[pos + 5],
            committer_date=lines[pos + 6],
            refs=lines[pos + 7],
            parent_hashes=lines[pos + 8],
            commits_map=commits_map,
            subject=lines[pos + 9],
            body=body,
            parse_trailers=self.parse_trailers,
            version_parser=self.version_parser,
        )

        pos += nbl_index + 1

        # Expand commit object with provider parsing.
        if self.provider:
            commit.update_with_provider(self.provider, parse_refs=self.parse_provider_refs)

        # Set the commit url based on remote_url (could be wrong).
        elif self.remote_url:
            commit.url = self.remote_url + "/commit/" + commit.hash

        # Expand commit object with convention parsing.
        if self.convention:
            commit.update_with_convention(self.convention)

        commits_map[commit.hash] = commit

    return list(commits_map.values())

run_git ¤

run_git(*args: str) -> str

Run a git command in the chosen repository.

Parameters:

  • *args (str, default: () ) –

    Arguments passed to the git command.

Returns:

  • str

    The git command output.

Source code in src/git_changelog/build.py
298
299
300
301
302
303
304
305
306
307
def run_git(self, *args: str) -> str:
    """Run a git command in the chosen repository.

    Arguments:
        *args: Arguments passed to the git command.

    Returns:
        The git command output.
    """
    return check_output(["git", *args], cwd=self.repository).decode("utf8")  # noqa: S603,S607

Commit ¤

Commit(
    commit_hash: str,
    author_name: str = "",
    author_email: str = "",
    author_date: str | datetime = "",
    committer_name: str = "",
    committer_email: str = "",
    committer_date: str | datetime = "",
    refs: str = "",
    subject: str = "",
    body: list[str] | None = None,
    url: str = "",
    *,
    parse_trailers: bool = False,
    parent_hashes: str | list[str] = "",
    commits_map: dict[str, Commit] | None = None,
    version_parser: (
        Callable[[str], tuple[ParsedVersion, str]] | None
    ) = None
)

A class to represent a commit.

Parameters:

  • commit_hash (str) –

    The commit hash.

  • author_name (str, default: '' ) –

    The author name.

  • author_email (str, default: '' ) –

    The author email.

  • author_date (str | datetime, default: '' ) –

    The authoring date (datetime or UTC timestamp).

  • committer_name (str, default: '' ) –

    The committer name.

  • committer_email (str, default: '' ) –

    The committer email.

  • committer_date (str | datetime, default: '' ) –

    The committing date (datetime or UTC timestamp).

  • refs (str, default: '' ) –

    The commit refs.

  • subject (str, default: '' ) –

    The commit message subject.

  • body (list[str] | None, default: None ) –

    The commit message body.

  • url (str, default: '' ) –

    The commit URL.

  • parse_trailers (bool, default: False ) –

    Whether to parse Git trailers.

Methods:

Attributes:

Source code in src/git_changelog/commit.py
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
def __init__(
    self,
    commit_hash: str,
    author_name: str = "",
    author_email: str = "",
    author_date: str | datetime = "",
    committer_name: str = "",
    committer_email: str = "",
    committer_date: str | datetime = "",
    refs: str = "",
    subject: str = "",
    body: list[str] | None = None,
    url: str = "",
    *,
    parse_trailers: bool = False,
    parent_hashes: str | list[str] = "",
    commits_map: dict[str, Commit] | None = None,
    version_parser: Callable[[str], tuple[ParsedVersion, str]] | None = None,
):
    """Initialization method.

    Arguments:
        commit_hash: The commit hash.
        author_name: The author name.
        author_email: The author email.
        author_date: The authoring date (datetime or UTC timestamp).
        committer_name: The committer name.
        committer_email: The committer email.
        committer_date: The committing date (datetime or UTC timestamp).
        refs: The commit refs.
        subject: The commit message subject.
        body: The commit message body.
        url: The commit URL.
        parse_trailers: Whether to parse Git trailers.
    """
    if not author_date:
        author_date = datetime.now()  # noqa: DTZ005
    elif isinstance(author_date, str):
        author_date = datetime.fromtimestamp(float(author_date), tz=timezone.utc)
    if not committer_date:
        committer_date = datetime.now()  # noqa: DTZ005
    elif isinstance(committer_date, str):
        committer_date = datetime.fromtimestamp(float(committer_date), tz=timezone.utc)

    self.hash: str = commit_hash
    self.author_name: str = author_name
    self.author_email: str = author_email
    self.author_date: datetime = author_date
    self.committer_name: str = committer_name
    self.committer_email: str = committer_email
    self.committer_date: datetime = committer_date
    self.subject: str = subject
    self.body: list[str] = _clean_body(body) if body else []
    self.url: str = url

    tag = ""
    for ref in refs.split(","):
        ref = ref.strip()  # noqa: PLW2901
        if ref.startswith("tag: "):
            ref = ref.replace("tag: ", "")  # noqa: PLW2901
            if version_parser is None or _is_valid_version(ref, version_parser):
                tag = ref
                break
    self.tag: str = tag
    self.version: str = tag

    if isinstance(parent_hashes, str):
        parent_hashes = parent_hashes.split()
    self.parent_hashes = parent_hashes
    self._commits_map = commits_map

    self.text_refs: dict[str, list[Ref]] = {}
    self.convention: dict[str, Any] = {}

    # YORE: Bump 3: Replace `_Trailers()` with `[]` within line.
    self.trailers: list[tuple[str, str]] = _Trailers()
    self.body_without_trailers = self.body

    if parse_trailers:
        self._parse_trailers()

parent_commits property ¤

parent_commits: list[Commit]

Parent commits of this commit.

update_with_convention ¤

update_with_convention(
    convention: CommitConvention,
) -> None

Apply the convention-parsed data to this commit.

Parameters:

Source code in src/git_changelog/commit.py
215
216
217
218
219
220
221
def update_with_convention(self, convention: CommitConvention) -> None:
    """Apply the convention-parsed data to this commit.

    Arguments:
        convention: The convention to use.
    """
    self.convention.update(convention.parse_commit(self))

update_with_provider ¤

update_with_provider(
    provider: ProviderRefParser, parse_refs: bool = True
) -> None

Apply the provider-parsed data to this commit.

Parameters:

  • provider (ProviderRefParser) –

    The provider to use.

  • parse_refs (bool, default: True ) –

    Whether to parse references for this provider.

Source code in src/git_changelog/commit.py
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
def update_with_provider(
    self,
    provider: ProviderRefParser,
    parse_refs: bool = True,  # noqa: FBT001,FBT002
) -> None:
    """Apply the provider-parsed data to this commit.

    Arguments:
        provider: The provider to use.
        parse_refs: Whether to parse references for this provider.
    """
    # set the commit url based on provider
    # FIXME: hardcoded 'commits'
    if "commits" in provider.REF:
        self.url = provider.build_ref_url("commits", {"ref": self.hash})
    else:
        # use default "commit" url (could be wrong)
        self.url = f"{provider.url}/{provider.namespace}/{provider.project}/commit/{self.hash}"

    # build commit text references from its subject and body
    if parse_refs:
        for ref_type in provider.REF:
            self.text_refs[ref_type] = provider.get_refs(
                ref_type,
                "\n".join([self.subject, *self.body]),
            )

        if "issues" in self.text_refs:
            self.text_refs["issues_not_in_subject"] = []
            for issue in self.text_refs["issues"]:
                if issue.ref not in self.subject:
                    self.text_refs["issues_not_in_subject"].append(issue)

GitHub ¤

GitHub(
    namespace: str, project: str, url: str | None = None
)

Bases: ProviderRefParser

A parser for the GitHub references.

Parameters:

  • namespace (str) –

    The Bitbucket namespace.

  • project (str) –

    The Bitbucket project.

  • url (str | None, default: None ) –

    The Bitbucket URL.

Methods:

  • get_refs

    Find all references in the given text.

  • parse_refs

    Parse references in the given text.

Source code in src/git_changelog/providers.py
64
65
66
67
68
69
70
71
72
73
74
def __init__(self, namespace: str, project: str, url: str | None = None):
    """Initialization method.

    Arguments:
        namespace: The Bitbucket namespace.
        project: The Bitbucket project.
        url: The Bitbucket URL.
    """
    self.namespace: str = namespace
    self.project: str = project
    self.url: str = url or self.url

get_refs ¤

get_refs(ref_type: str, text: str) -> list[Ref]

Find all references in the given text.

Parameters:

  • ref_type (str) –

    The reference type.

  • text (str) –

    The text in which to search references.

Returns:

  • list[Ref]

    A list of references (instances of Ref).

Source code in src/git_changelog/providers.py
76
77
78
79
80
81
82
83
84
85
86
87
88
89
def get_refs(self, ref_type: str, text: str) -> list[Ref]:
    """Find all references in the given text.

    Arguments:
        ref_type: The reference type.
        text: The text in which to search references.

    Returns:
        A list of references (instances of [Ref][git_changelog.providers.Ref]).
    """
    return [
        Ref(ref=match.group().strip(), url=self.build_ref_url(ref_type, match.groupdict()))
        for match in self.parse_refs(ref_type, text)
    ]

parse_refs ¤

parse_refs(ref_type: str, text: str) -> list[Match]

Parse references in the given text.

Parameters:

  • ref_type (str) –

    The reference type.

  • text (str) –

    The text to parse.

Returns:

  • list[Match]

    A list of regular expressions matches.

Source code in src/git_changelog/providers.py
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
def parse_refs(self, ref_type: str, text: str) -> list[Match]:
    """Parse references in the given text.

    Arguments:
        ref_type: The reference type.
        text: The text to parse.

    Returns:
        A list of regular expressions matches.
    """
    if ref_type not in self.REF:
        refs = [key for key in self.REF if key.startswith(ref_type)]
        return [match for ref in refs for match in self.REF[ref].regex.finditer(text)]
    return list(self.REF[ref_type].regex.finditer(text))

GitLab ¤

GitLab(
    namespace: str, project: str, url: str | None = None
)

Bases: ProviderRefParser

A parser for the GitLab references.

Parameters:

  • namespace (str) –

    The Bitbucket namespace.

  • project (str) –

    The Bitbucket project.

  • url (str | None, default: None ) –

    The Bitbucket URL.

Methods:

  • get_refs

    Find all references in the given text.

  • parse_refs

    Parse references in the given text.

Source code in src/git_changelog/providers.py
64
65
66
67
68
69
70
71
72
73
74
def __init__(self, namespace: str, project: str, url: str | None = None):
    """Initialization method.

    Arguments:
        namespace: The Bitbucket namespace.
        project: The Bitbucket project.
        url: The Bitbucket URL.
    """
    self.namespace: str = namespace
    self.project: str = project
    self.url: str = url or self.url

get_refs ¤

get_refs(ref_type: str, text: str) -> list[Ref]

Find all references in the given text.

Parameters:

  • ref_type (str) –

    The reference type.

  • text (str) –

    The text in which to search references.

Returns:

  • list[Ref]

    A list of references (instances of Ref).

Source code in src/git_changelog/providers.py
76
77
78
79
80
81
82
83
84
85
86
87
88
89
def get_refs(self, ref_type: str, text: str) -> list[Ref]:
    """Find all references in the given text.

    Arguments:
        ref_type: The reference type.
        text: The text in which to search references.

    Returns:
        A list of references (instances of [Ref][git_changelog.providers.Ref]).
    """
    return [
        Ref(ref=match.group().strip(), url=self.build_ref_url(ref_type, match.groupdict()))
        for match in self.parse_refs(ref_type, text)
    ]

parse_refs ¤

parse_refs(ref_type: str, text: str) -> list[Match]

Parse references in the given text.

Parameters:

  • ref_type (str) –

    The reference type.

  • text (str) –

    The text to parse.

Returns:

  • list[Match]

    A list of regular expressions matches.

Source code in src/git_changelog/providers.py
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
def parse_refs(self, ref_type: str, text: str) -> list[Match]:
    """Parse references in the given text.

    Arguments:
        ref_type: The reference type.
        text: The text to parse.

    Returns:
        A list of regular expressions matches.
    """
    if ref_type not in self.REF:
        refs = [key for key in self.REF if key.startswith(ref_type)]
        return [match for ref in refs for match in self.REF[ref].regex.finditer(text)]
    return list(self.REF[ref_type].regex.finditer(text))