Открыть боковую панель
Минаков Марк Александрович
git-changelog
Коммиты
cf41a97d
Коммит
cf41a97d
создал
Янв 29, 2023
по автору
Timothée Mazzucotelli
Просмотр файлов
feat: Allow disabling parsing of provider-specific references
владелец
6520cbac
Изменения
3
Скрыть пробелы
Построчно
Рядом
src/git_changelog/build.py
Просмотр файла @
cf41a97d
...
...
@@ -158,6 +158,7 @@ class Changelog:
repository
:
str
,
provider
:
ProviderRefParser
|
None
=
None
,
style
:
StyleType
|
None
=
None
,
parse_provider_refs
:
bool
=
True
,
):
"""
Initialization method.
...
...
@@ -166,8 +167,10 @@ class Changelog:
repository: The repository (directory) for which to build the changelog.
provider: The provider to use (github.com, gitlab.com, etc.).
style: The commit style to use (angular, atom, etc.).
parse_provider_refs: Whether to parse provider-specific references in the commit messages.
"""
self
.
repository
:
str
=
repository
self
.
parse_provider_refs
:
bool
=
parse_provider_refs
# set provider
if
not
provider
:
...
...
@@ -298,7 +301,7 @@ class Changelog:
# expand commit object with provider parsing
if
self
.
provider
:
commit
.
update_with_provider
(
self
.
provider
)
commit
.
update_with_provider
(
self
.
provider
,
self
.
parse_provider_refs
)
elif
self
.
remote_url
:
# set the commit url based on remote_url (could be wrong)
...
...
src/git_changelog/cli.py
Просмотр файла @
cf41a97d
...
...
@@ -75,6 +75,14 @@ def get_parser() -> argparse.ArgumentParser:
default
=
sys
.
stdout
,
help
=
"Output to given file. Default: stdout."
,
)
parser
.
add_argument
(
"-R"
,
"--no-parse-refs"
,
action
=
"store_false"
,
dest
=
"parse_refs"
,
default
=
True
,
help
=
"Do not parse provider-specific references in commit messages (issues, PRs, etc.)."
,
)
parser
.
add_argument
(
"-s"
,
"--style"
,
choices
=
STYLES
,
default
=
"basic"
,
dest
=
"style"
,
help
=
"The commit style to match against."
)
...
...
@@ -124,7 +132,11 @@ def main(args: list[str] | None = None) -> int:
template
=
templates
.
get_template
(
opts
.
template
)
# build data
changelog
=
Changelog
(
opts
.
repository
,
style
=
opts
.
style
)
changelog
=
Changelog
(
opts
.
repository
,
style
=
opts
.
style
,
parse_provider_refs
=
opts
.
parse_refs
,
)
# get rendered contents
rendered
=
template
.
render
(
changelog
=
changelog
)
...
...
src/git_changelog/commit.py
Просмотр файла @
cf41a97d
...
...
@@ -84,12 +84,13 @@ class Commit:
"""
self
.
style
.
update
(
style
.
parse_commit
(
self
))
def
update_with_provider
(
self
,
provider
:
ProviderRefParser
)
->
None
:
def
update_with_provider
(
self
,
provider
:
ProviderRefParser
,
parse_refs
:
bool
=
True
)
->
None
:
# noqa: WPS231
"""
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'
...
...
@@ -100,14 +101,15 @@ class Commit:
self
.
url
=
f
"
{
provider
.
url
}
/
{
provider
.
namespace
}
/
{
provider
.
project
}
/commit/
{
self
.
hash
}
"
# build commit text references from its subject and body
for
ref_type
in
provider
.
REF
.
keys
():
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
)
if
parse_refs
:
for
ref_type
in
provider
.
REF
.
keys
():
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
)
class
CommitStyle
(
ABC
):
...
...
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать