Skip to content

providers ¤

Module containing the parsing utilities for git providers.

Classes:

  • Bitbucket

    A parser for the Bitbucket references.

  • GitHub

    A parser for the GitHub references.

  • GitLab

    A parser for the GitLab references.

  • ProviderRefParser

    A base class for specific providers reference parsers.

  • Ref

    A class to represent a reference and its URL.

  • RefDef

    A class to store a reference regular expression and URL building string.

  • RefRe

    An enum helper to store parts of regular expressions for 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
63
64
65
66
67
68
69
70
71
72
73
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
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))

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
63
64
65
66
67
68
69
70
71
72
73
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
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
63
64
65
66
67
68
69
70
71
72
73
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
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))

ProviderRefParser ¤

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

Bases: ABC

A base class for specific providers reference parsers.

Parameters:

  • namespace (str) –

    The Bitbucket namespace.

  • project (str) –

    The Bitbucket project.

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

    The Bitbucket URL.

Methods:

  • build_ref_url

    Build the URL for a reference type and a dictionary of matched groups.

  • get_compare_url

    Get the URL for a tag comparison.

  • get_refs

    Find all references in the given text.

  • get_tag_url

    Get the URL for a git tag.

  • parse_refs

    Parse references in the given text.

Source code in src/git_changelog/providers.py
63
64
65
66
67
68
69
70
71
72
73
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

build_ref_url ¤

build_ref_url(
    ref_type: str, match_dict: dict[str, str]
) -> str

Build the URL for a reference type and a dictionary of matched groups.

Parameters:

  • ref_type (str) –

    The reference type.

  • match_dict (dict[str, str]) –

    The matched groups.

Returns:

  • str

    The built URL.

Source code in src/git_changelog/providers.py
105
106
107
108
109
110
111
112
113
114
115
def build_ref_url(self, ref_type: str, match_dict: dict[str, str]) -> str:
    """Build the URL for a reference type and a dictionary of matched groups.

    Arguments:
        ref_type: The reference type.
        match_dict: The matched groups.

    Returns:
        The built URL.
    """
    return self.REF[ref_type].url_string.format(**match_dict)

get_compare_url abstractmethod ¤

get_compare_url(base: str, target: str) -> str

Get the URL for a tag comparison.

Parameters:

  • base (str) –

    The base tag.

  • target (str) –

    The target tag.

Returns:

  • str

    The comparison URL.

Source code in src/git_changelog/providers.py
129
130
131
132
133
134
135
136
137
138
139
140
@abstractmethod
def get_compare_url(self, base: str, target: str) -> str:
    """Get the URL for a tag comparison.

    Arguments:
        base: The base tag.
        target: The target tag.

    Returns:
        The comparison URL.
    """
    raise NotImplementedError

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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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)
    ]

get_tag_url abstractmethod ¤

get_tag_url(tag: str) -> str

Get the URL for a git tag.

Parameters:

  • tag (str) –

    The git tag.

Returns:

  • str

    The tag URL.

Source code in src/git_changelog/providers.py
117
118
119
120
121
122
123
124
125
126
127
@abstractmethod
def get_tag_url(self, tag: str) -> str:
    """Get the URL for a git tag.

    Arguments:
        tag: The git tag.

    Returns:
        The tag URL.
    """
    raise NotImplementedError

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
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
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))

Ref ¤

Ref(ref: str, url: str)

A class to represent a reference and its URL.

Parameters:

  • ref (str) –

    The reference text.

  • url (str) –

    The reference URL.

Source code in src/git_changelog/providers.py
27
28
29
30
31
32
33
34
35
def __init__(self, ref: str, url: str) -> None:
    """Initialization method.

    Arguments:
        ref: The reference text.
        url: The reference URL.
    """
    self.ref: str = ref
    self.url: str = url

RefDef ¤

RefDef(regex: Pattern, url_string: str)

A class to store a reference regular expression and URL building string.

Parameters:

  • regex (Pattern) –

    The regular expression to match the reference.

  • url_string (str) –

    The URL string to format using matched groups.

Source code in src/git_changelog/providers.py
44
45
46
47
48
49
50
51
52
def __init__(self, regex: Pattern, url_string: str):
    """Initialization method.

    Arguments:
        regex: The regular expression to match the reference.
        url_string: The URL string to format using matched groups.
    """
    self.regex = regex
    self.url_string = url_string

RefRe ¤

An enum helper to store parts of regular expressions for references.