From 472add7bb98177f9d20886ff38242812107a125c Mon Sep 17 00:00:00 2001 From: Nejc Habjan Date: Sun, 28 Feb 2021 11:41:19 +0100 Subject: [PATCH 1/3] feat(api,cli): add support for changelog generation --- gitlab/v4/objects/repositories.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/gitlab/v4/objects/repositories.py b/gitlab/v4/objects/repositories.py index 6a04174b9..0fd99a0b7 100644 --- a/gitlab/v4/objects/repositories.py +++ b/gitlab/v4/objects/repositories.py @@ -204,3 +204,25 @@ def delete_merged_branches(self, **kwargs): """ path = "/projects/%s/repository/merged_branches" % self.get_id() self.manager.gitlab.http_delete(path, **kwargs) + + @cli.register_custom_action( + "Project", + ("version_tag",), + ("from", "to", "date", "branch", "trailer", "file", "message"), + ) + @exc.on_http_error(exc.GitlabCreateError) + def changelog(self, data=None, **kwargs): + """Create a changelog entry in the repository. + + Args: + **kwargs: Extra options to send to the server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabCreateError: If the server failed to perform the request + """ + path = "/projects/%s/repository/changelog" % self.get_id() + + # This is here to avoid clashing with the CLI's `--version` flag + + self.manager.gitlab.http_post(path, data=data, **kwargs) From 51b6de1c26f28778d05d5a21be6e93f0a7c97b80 Mon Sep 17 00:00:00 2001 From: Nejc Habjan Date: Sun, 28 Feb 2021 14:34:56 +0100 Subject: [PATCH 2/3] chore(cli): only take version as CLI version if first arg --- gitlab/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitlab/cli.py b/gitlab/cli.py index 1e98a3855..af8432afa 100644 --- a/gitlab/cli.py +++ b/gitlab/cli.py @@ -172,7 +172,7 @@ def main(): # otherwise it will cause circular import errors import gitlab.v4.cli - if "--version" in sys.argv: + if "--version" == sys.argv[1]: print(gitlab.__version__) sys.exit(0) From ea5d358a6b0262055b10d82d7c0e998b26bf4aaa Mon Sep 17 00:00:00 2001 From: Nejc Habjan Date: Sun, 28 Feb 2021 14:45:09 +0100 Subject: [PATCH 3/3] chore(api): turn changelog into its own manager --- gitlab/v4/objects/__init__.py | 1 + gitlab/v4/objects/projects.py | 7 ++++++- gitlab/v4/objects/repositories.py | 35 +++++++++++++++---------------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/gitlab/v4/objects/__init__.py b/gitlab/v4/objects/__init__.py index 8a2ed7c37..9ca0f92fd 100644 --- a/gitlab/v4/objects/__init__.py +++ b/gitlab/v4/objects/__init__.py @@ -57,6 +57,7 @@ from .projects import * from .push_rules import * from .releases import * +from .repositories import * from .runners import * from .services import * from .settings import * diff --git a/gitlab/v4/objects/projects.py b/gitlab/v4/objects/projects.py index c187ba95f..9f601dd79 100644 --- a/gitlab/v4/objects/projects.py +++ b/gitlab/v4/objects/projects.py @@ -47,7 +47,11 @@ ) from .push_rules import ProjectPushRulesManager from .releases import ProjectReleaseManager -from .repositories import RepositoryMixin +from .repositories import ( + RepositoryMixin, + ProjectRepositoryChangelog, + ProjectRepositoryChangelogManager, +) from .runners import ProjectRunnerManager from .services import ProjectServiceManager from .snippets import ProjectSnippetManager @@ -112,6 +116,7 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO ("boards", "ProjectBoardManager"), ("branches", "ProjectBranchManager"), ("jobs", "ProjectJobManager"), + ("changelogs", "ProjectRepositoryChangelogManager"), ("commits", "ProjectCommitManager"), ("customattributes", "ProjectCustomAttributeManager"), ("deployments", "ProjectDeploymentManager"), diff --git a/gitlab/v4/objects/repositories.py b/gitlab/v4/objects/repositories.py index 0fd99a0b7..1b844f9a8 100644 --- a/gitlab/v4/objects/repositories.py +++ b/gitlab/v4/objects/repositories.py @@ -6,6 +6,13 @@ from gitlab import cli, types, utils from gitlab import exceptions as exc +from gitlab.base import RESTManager, RESTObject +from gitlab.mixins import CreateMixin + +__all__ = [ + "ProjectRepositoryChangelog", + "ProjectRepositoryChangelogManager", +] class RepositoryMixin: @@ -205,24 +212,16 @@ def delete_merged_branches(self, **kwargs): path = "/projects/%s/repository/merged_branches" % self.get_id() self.manager.gitlab.http_delete(path, **kwargs) - @cli.register_custom_action( - "Project", - ("version_tag",), - ("from", "to", "date", "branch", "trailer", "file", "message"), - ) - @exc.on_http_error(exc.GitlabCreateError) - def changelog(self, data=None, **kwargs): - """Create a changelog entry in the repository. - Args: - **kwargs: Extra options to send to the server (e.g. sudo) +class ProjectRepositoryChangelog(RESTObject): + pass - Raises: - GitlabAuthenticationError: If authentication is not correct - GitlabCreateError: If the server failed to perform the request - """ - path = "/projects/%s/repository/changelog" % self.get_id() - # This is here to avoid clashing with the CLI's `--version` flag - - self.manager.gitlab.http_post(path, data=data, **kwargs) +class ProjectRepositoryChangelogManager(CreateMixin, RESTManager): + _obj_cls = ProjectRepositoryChangelog + _path = "/projects/%(project_id)s/repository/changelog" + _from_parent_attrs = {"project_id": "id"} + _create_attrs = ( + ("version",), + ("from_commit", "to_commit", "date", "branch", "trailer", "file", "message"), + )