- Notifications
You must be signed in to change notification settings - Fork676
feat(api): add support for external status check#3098
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletionsdocs/api-objects.rst
This file contains hidden or 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
57 changes: 57 additions & 0 deletionsdocs/gl_objects/status_checks.rst
This file contains hidden or 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,57 @@ | ||
####################### | ||
External Status Checks | ||
####################### | ||
Manage external status checks for projects and merge requests. | ||
Project external status checks | ||
=============================== | ||
Reference | ||
--------- | ||
* v4 API: | ||
+ :class:`gitlab.v4.objects.ProjectExternalStatusCheck` | ||
+ :class:`gitlab.v4.objects.ProjectExternalStatusCheckManager` | ||
+ :attr:`gitlab.v4.objects.Project.external_status_checks` | ||
* GitLab API: https://docs.gitlab.com/ee/api/status_checks.html | ||
Examples | ||
--------- | ||
List external status checks for a project:: | ||
status_checks = project.external_status_checks.list() | ||
Create an external status check with shared secret:: | ||
status_checks = project.external_status_checks.create({ | ||
"name": "mr_blocker", | ||
"external_url": "https://example.com/mr-status-check", | ||
"shared_secret": "secret-string" | ||
}) | ||
Create an external status check with shared secret for protected branches:: | ||
protected_branch = project.protectedbranches.get('main') | ||
status_check = project.external_status_checks.create({ | ||
"name": "mr_blocker", | ||
"external_url": "https://example.com/mr-status-check", | ||
"shared_secret": "secret-string", | ||
"protected_branch_ids": [protected_branch.id] | ||
}) | ||
Update an external status check:: | ||
status_check.external_url = "https://example.com/mr-blocker" | ||
status_check.save() | ||
Delete an external status check:: | ||
status_check.delete(status_check_id) | ||
1 change: 1 addition & 0 deletionsgitlab/v4/objects/__init__.py
This file contains hidden or 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
2 changes: 2 additions & 0 deletionsgitlab/v4/objects/merge_requests.py
This file contains hidden or 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
2 changes: 2 additions & 0 deletionsgitlab/v4/objects/projects.py
This file contains hidden or 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
52 changes: 52 additions & 0 deletionsgitlab/v4/objects/status_checks.py
This file contains hidden or 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,52 @@ | ||
from gitlab.base import RESTManager, RESTObject | ||
from gitlab.mixins import ( | ||
CreateMixin, | ||
DeleteMixin, | ||
ListMixin, | ||
ObjectDeleteMixin, | ||
SaveMixin, | ||
UpdateMethod, | ||
UpdateMixin, | ||
) | ||
from gitlab.types import ArrayAttribute, RequiredOptional | ||
__all__ = [ | ||
"ProjectExternalStatusCheck", | ||
"ProjectExternalStatusCheckManager", | ||
"ProjectMergeRequestStatusCheck", | ||
"ProjectMergeRequestStatusCheckManager", | ||
] | ||
class ProjectExternalStatusCheck(SaveMixin, ObjectDeleteMixin, RESTObject): | ||
pass | ||
class ProjectExternalStatusCheckManager( | ||
ListMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTManager | ||
): | ||
_path = "/projects/{project_id}/external_status_checks" | ||
_obj_cls = ProjectExternalStatusCheck | ||
_from_parent_attrs = {"project_id": "id"} | ||
_create_attrs = RequiredOptional( | ||
required=("name", "external_url"), | ||
optional=("shared_secret", "protected_branch_ids"), | ||
) | ||
_update_attrs = RequiredOptional( | ||
optional=("name", "external_url", "shared_secret", "protected_branch_ids") | ||
) | ||
_types = {"protected_branch_ids": ArrayAttribute} | ||
class ProjectMergeRequestStatusCheck(SaveMixin, RESTObject): | ||
pass | ||
class ProjectMergeRequestStatusCheckManager(ListMixin, RESTManager): | ||
_path = "/projects/{project_id}/merge_requests/{merge_request_iid}/status_checks" | ||
_obj_cls = ProjectMergeRequestStatusCheck | ||
_from_parent_attrs = {"project_id": "project_id", "merge_request_iid": "iid"} | ||
_update_attrs = RequiredOptional( | ||
required=("sha", "external_status_check_id", "status") | ||
) | ||
_update_method = UpdateMethod.POST |
16 changes: 16 additions & 0 deletionstests/functional/api/test_projects.py
This file contains hidden or 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
127 changes: 127 additions & 0 deletionstests/unit/objects/test_status_checks.py
This file contains hidden or 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,127 @@ | ||
""" | ||
GitLab API: https://docs.gitlab.com/ee/api/status_checks.html | ||
""" | ||
import pytest | ||
import responses | ||
@pytest.fixture | ||
def external_status_check(): | ||
return { | ||
"id": 1, | ||
"name": "MR blocker", | ||
"project_id": 1, | ||
"external_url": "https://example.com/mr-blocker", | ||
"hmac": True, | ||
"protected_branches": [ | ||
{ | ||
"id": 1, | ||
"project_id": 1, | ||
"name": "main", | ||
"created_at": "2020-10-12T14:04:50.787Z", | ||
"updated_at": "2020-10-12T14:04:50.787Z", | ||
"code_owner_approval_required": False, | ||
} | ||
], | ||
} | ||
@pytest.fixture | ||
def updated_external_status_check(): | ||
return { | ||
"id": 1, | ||
"name": "Updated MR blocker", | ||
"project_id": 1, | ||
"external_url": "https://example.com/mr-blocker", | ||
"hmac": True, | ||
"protected_branches": [ | ||
{ | ||
"id": 1, | ||
"project_id": 1, | ||
"name": "main", | ||
"created_at": "2020-10-12T14:04:50.787Z", | ||
"updated_at": "2020-10-12T14:04:50.787Z", | ||
"code_owner_approval_required": False, | ||
} | ||
], | ||
} | ||
@pytest.fixture | ||
def resp_list_external_status_checks(external_status_check): | ||
with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps: | ||
rsps.add( | ||
method=responses.GET, | ||
url="http://localhost/api/v4/projects/1/external_status_checks", | ||
json=[external_status_check], | ||
content_type="application/json", | ||
status=200, | ||
) | ||
yield rsps | ||
@pytest.fixture | ||
def resp_create_external_status_checks(external_status_check): | ||
with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps: | ||
rsps.add( | ||
method=responses.POST, | ||
url="http://localhost/api/v4/projects/1/external_status_checks", | ||
json=external_status_check, | ||
content_type="application/json", | ||
status=200, | ||
) | ||
yield rsps | ||
@pytest.fixture | ||
def resp_update_external_status_checks(updated_external_status_check): | ||
with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps: | ||
rsps.add( | ||
method=responses.PUT, | ||
url="http://localhost/api/v4/groups/1/external_status_checks", | ||
json=updated_external_status_check, | ||
content_type="application/json", | ||
status=200, | ||
) | ||
yield rsps | ||
@pytest.fixture | ||
def resp_delete_external_status_checks(): | ||
content = [] | ||
with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps: | ||
rsps.add( | ||
method=responses.DELETE, | ||
url="http://localhost/api/v4/projects/1/external_status_checks/1", | ||
status=204, | ||
) | ||
rsps.add( | ||
method=responses.GET, | ||
url="http://localhost/api/v4/projects/1/external_status_checks", | ||
json=content, | ||
content_type="application/json", | ||
status=200, | ||
) | ||
yield rsps | ||
def test_list_external_status_checks(gl, resp_list_external_status_checks): | ||
status_checks = gl.projects.get(1, lazy=True).external_status_checks.list() | ||
assert len(status_checks) == 1 | ||
assert status_checks[0].name == "MR blocker" | ||
def test_create_external_status_checks(gl, resp_create_external_status_checks): | ||
access_token = gl.projects.get(1, lazy=True).external_status_checks.create( | ||
{"name": "MR blocker", "external_url": "https://example.com/mr-blocker"} | ||
) | ||
assert access_token.name == "MR blocker" | ||
assert access_token.external_url == "https://example.com/mr-blocker" | ||
def test_delete_external_status_checks(gl, resp_delete_external_status_checks): | ||
gl.projects.get(1, lazy=True).external_status_checks.delete(1) | ||
status_checks = gl.projects.get(1, lazy=True).external_status_checks.list() | ||
assert len(status_checks) == 0 |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.