Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1314 from python-gitlab/feat/release-links
feat: add release links API support
- Loading branch information
Showing
12 changed files
with
329 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
######## | ||
Releases | ||
######## | ||
|
||
Project releases | ||
================ | ||
|
||
Reference | ||
--------- | ||
|
||
* v4 API: | ||
|
||
+ :class:`gitlab.v4.objects.ProjectRelease` | ||
+ :class:`gitlab.v4.objects.ProjectReleaseManager` | ||
+ :attr:`gitlab.v4.objects.Project.releases` | ||
|
||
* Gitlab API: https://docs.gitlab.com/ee/api/releases/index.html | ||
|
||
Examples | ||
-------- | ||
|
||
Get a list of releases from a project:: | ||
|
||
release = project.releases.list() | ||
|
||
Get a single release:: | ||
|
||
release = project.releases.get('v1.2.3') | ||
|
||
Create a release for a project tag:: | ||
|
||
release = project.releases.create({'name':'Demo Release', 'tag_name':'v1.2.3', 'description':'release notes go here'}) | ||
|
||
Delete a release:: | ||
|
||
# via its tag name from project attributes | ||
release = project.releases.delete('v1.2.3') | ||
|
||
# delete object directly | ||
release.delete() | ||
|
||
Project release links | ||
===================== | ||
|
||
Reference | ||
--------- | ||
|
||
* v4 API: | ||
|
||
+ :class:`gitlab.v4.objects.ProjectReleaseLink` | ||
+ :class:`gitlab.v4.objects.ProjectReleaseLinkManager` | ||
+ :attr:`gitlab.v4.objects.ProjectRelease.links` | ||
|
||
* Gitlab API: https://docs.gitlab.com/ee/api/releases/links.html | ||
|
||
Examples | ||
-------- | ||
|
||
Get a list of releases from a project:: | ||
|
||
links = release.links.list() | ||
|
||
Get a single release link:: | ||
|
||
link = release.links.get(1) | ||
|
||
Create a release link for a release:: | ||
|
||
link = release.links.create({"url": "https://example.com/asset", "name": "asset"}) | ||
|
||
Delete a release link:: | ||
|
||
# via its ID from release attributes | ||
release.links.delete(1) | ||
|
||
# delete object directly | ||
link.delete() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
""" | ||
GitLab API: | ||
https://docs.gitlab.com/ee/api/releases/index.html | ||
https://docs.gitlab.com/ee/api/releases/links.html | ||
""" | ||
import re | ||
|
||
import pytest | ||
import responses | ||
|
||
from gitlab.v4.objects import ProjectReleaseLink | ||
|
||
encoded_tag_name = "v1%2E0%2E0" | ||
link_name = "hello-world" | ||
link_url = "https://gitlab.example.com/group/hello/-/jobs/688/artifacts/raw/bin/hello-darwin-amd64" | ||
direct_url = f"https://gitlab.example.com/group/hello/-/releases/{encoded_tag_name}/downloads/hello-world" | ||
new_link_type = "package" | ||
link_content = { | ||
"id": 2, | ||
"name": link_name, | ||
"url": link_url, | ||
"direct_asset_url": direct_url, | ||
"external": False, | ||
"link_type": "other", | ||
} | ||
|
||
links_url = re.compile( | ||
rf"http://localhost/api/v4/projects/1/releases/{encoded_tag_name}/assets/links" | ||
) | ||
link_id_url = re.compile( | ||
rf"http://localhost/api/v4/projects/1/releases/{encoded_tag_name}/assets/links/1" | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def resp_list_links(): | ||
with responses.RequestsMock() as rsps: | ||
rsps.add( | ||
method=responses.GET, | ||
url=links_url, | ||
json=[link_content], | ||
content_type="application/json", | ||
status=200, | ||
) | ||
yield rsps | ||
|
||
|
||
@pytest.fixture | ||
def resp_get_link(): | ||
with responses.RequestsMock() as rsps: | ||
rsps.add( | ||
method=responses.GET, | ||
url=link_id_url, | ||
json=link_content, | ||
content_type="application/json", | ||
status=200, | ||
) | ||
yield rsps | ||
|
||
|
||
@pytest.fixture | ||
def resp_create_link(): | ||
with responses.RequestsMock() as rsps: | ||
rsps.add( | ||
method=responses.POST, | ||
url=links_url, | ||
json=link_content, | ||
content_type="application/json", | ||
status=200, | ||
) | ||
yield rsps | ||
|
||
|
||
@pytest.fixture | ||
def resp_update_link(): | ||
updated_content = dict(link_content) | ||
updated_content["link_type"] = new_link_type | ||
|
||
with responses.RequestsMock() as rsps: | ||
rsps.add( | ||
method=responses.PUT, | ||
url=link_id_url, | ||
json=updated_content, | ||
content_type="application/json", | ||
status=200, | ||
) | ||
yield rsps | ||
|
||
|
||
@pytest.fixture | ||
def resp_delete_link(no_content): | ||
with responses.RequestsMock() as rsps: | ||
rsps.add( | ||
method=responses.DELETE, | ||
url=link_id_url, | ||
json=link_content, | ||
content_type="application/json", | ||
status=204, | ||
) | ||
yield rsps | ||
|
||
|
||
def test_list_release_links(release, resp_list_links): | ||
links = release.links.list() | ||
assert isinstance(links, list) | ||
assert isinstance(links[0], ProjectReleaseLink) | ||
assert links[0].url == link_url | ||
|
||
|
||
def test_get_release_link(release, resp_get_link): | ||
link = release.links.get(1) | ||
assert isinstance(link, ProjectReleaseLink) | ||
assert link.url == link_url | ||
|
||
|
||
def test_create_release_link(release, resp_create_link): | ||
link = release.links.create({"url": link_url, "name": link_name}) | ||
assert isinstance(link, ProjectReleaseLink) | ||
assert link.url == link_url | ||
|
||
|
||
def test_update_release_link(release, resp_update_link): | ||
link = release.links.get(1, lazy=True) | ||
link.link_type = new_link_type | ||
link.save() | ||
assert link.link_type == new_link_type | ||
|
||
|
||
def test_delete_release_link(release, resp_delete_link): | ||
link = release.links.get(1, lazy=True) | ||
link.delete() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from gitlab import cli | ||
from gitlab import exceptions as exc | ||
from gitlab.base import * # noqa | ||
from gitlab.mixins import * # noqa | ||
|
||
|
||
__all__ = [ | ||
"ProjectRelease", | ||
"ProjectReleaseManager", | ||
"ProjectReleaseLink", | ||
"ProjectReleaseLinkManager", | ||
] | ||
|
||
|
||
class ProjectRelease(RESTObject): | ||
_id_attr = "tag_name" | ||
_managers = (("links", "ProjectReleaseLinkManager"),) | ||
|
||
|
||
class ProjectReleaseManager(NoUpdateMixin, RESTManager): | ||
_path = "/projects/%(project_id)s/releases" | ||
_obj_cls = ProjectRelease | ||
_from_parent_attrs = {"project_id": "id"} | ||
_create_attrs = (("name", "tag_name", "description"), ("ref", "assets")) | ||
|
||
|
||
class ProjectReleaseLink(RESTObject, ObjectDeleteMixin, SaveMixin): | ||
pass | ||
|
||
|
||
class ProjectReleaseLinkManager(CRUDMixin, RESTManager): | ||
_path = "/projects/%(project_id)s/releases/%(tag_name)s/assets/links" | ||
_obj_cls = ProjectReleaseLink | ||
_from_parent_attrs = {"project_id": "project_id", "tag_name": "tag_name"} | ||
_create_attrs = (("name", "url"), ("filepath", "link_type")) | ||
_update_attrs = ((), ("name", "url", "filepath", "link_type")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.