- Notifications
You must be signed in to change notification settings - Fork673
feat(api): add project templates#3057
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
Show all changes
5 commits Select commitHold shift + click to select a range
a094e49
feat(api): Added project template classes to templates.py
gerry-pratama9e9f706
feat(api): Added project template managers to Project in project.py
gerry-pratama24724f3
docs(merge_requests): Add example of creating mr with description tem…
gerry-pratamaa71be72
test(templates): Added unit tests for templates
gerry-pratama24af304
docs(templates): added section for project templates
gerry-pratamaFile 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
8 changes: 8 additions & 0 deletionsdocs/gl_objects/merge_requests.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
72 changes: 71 additions & 1 deletiondocs/gl_objects/templates.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
14 changes: 14 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
104 changes: 104 additions & 0 deletionsgitlab/v4/objects/templates.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
106 changes: 106 additions & 0 deletionstests/unit/objects/test_templates.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,106 @@ | ||
""" | ||
Gitlab API: | ||
https://docs.gitlab.com/ce/api/templates/dockerfiles.html | ||
https://docs.gitlab.com/ce/api/templates/gitignores.html | ||
https://docs.gitlab.com/ce/api/templates/gitlab_ci_ymls.html | ||
https://docs.gitlab.com/ce/api/templates/licenses.html | ||
https://docs.gitlab.com/ce/api/project_templates.html | ||
""" | ||
import pytest | ||
import responses | ||
from gitlab.v4.objects import ( | ||
Dockerfile, | ||
Gitignore, | ||
Gitlabciyml, | ||
License, | ||
ProjectDockerfileTemplate, | ||
ProjectGitignoreTemplate, | ||
ProjectGitlabciymlTemplate, | ||
ProjectIssueTemplate, | ||
ProjectLicenseTemplate, | ||
ProjectMergeRequestTemplate, | ||
) | ||
@pytest.mark.parametrize( | ||
"tmpl, tmpl_mgr, tmpl_path", | ||
[ | ||
(Dockerfile, "dockerfiles", "dockerfiles"), | ||
(Gitignore, "gitignores", "gitignores"), | ||
(Gitlabciyml, "gitlabciymls", "gitlab_ci_ymls"), | ||
(License, "licenses", "licenses"), | ||
], | ||
ids=[ | ||
"dockerfile", | ||
"gitignore", | ||
"gitlabciyml", | ||
"license", | ||
], | ||
) | ||
def test_get_template(gl, tmpl, tmpl_mgr, tmpl_path): | ||
tmpl_id = "sample" | ||
tmpl_content = {"name": tmpl_id, "content": "Sample template content"} | ||
# License templates have 'key' as the id attribute, so ensure | ||
# this is included in the response content | ||
if tmpl == License: | ||
tmpl_id = "smpl" | ||
tmpl_content.update({"key": tmpl_id}) | ||
path = f"templates/{tmpl_path}/{tmpl_id}" | ||
with responses.RequestsMock() as rsps: | ||
rsps.add( | ||
method=responses.GET, | ||
url=f"http://localhost/api/v4/{path}", | ||
json=tmpl_content, | ||
) | ||
template = getattr(gl, tmpl_mgr).get(tmpl_id) | ||
assert isinstance(template, tmpl) | ||
assert getattr(template, template._id_attr) == tmpl_id | ||
@pytest.mark.parametrize( | ||
"tmpl, tmpl_mgr, tmpl_path", | ||
[ | ||
(ProjectDockerfileTemplate, "dockerfile_templates", "dockerfiles"), | ||
(ProjectGitignoreTemplate, "gitignore_templates", "gitignores"), | ||
(ProjectGitlabciymlTemplate, "gitlabciyml_templates", "gitlab_ci_ymls"), | ||
(ProjectLicenseTemplate, "license_templates", "licenses"), | ||
(ProjectIssueTemplate, "issue_templates", "issues"), | ||
(ProjectMergeRequestTemplate, "merge_request_templates", "merge_requests"), | ||
], | ||
ids=[ | ||
"dockerfile", | ||
"gitignore", | ||
"gitlabciyml", | ||
"license", | ||
"issue", | ||
"mergerequest", | ||
], | ||
) | ||
def test_get_project_template(project, tmpl, tmpl_mgr, tmpl_path): | ||
tmpl_id = "sample" | ||
tmpl_content = {"name": tmpl_id, "content": "Sample template content"} | ||
# ProjectLicenseTemplate templates have 'key' as the id attribute, so ensure | ||
# this is included in the response content | ||
if tmpl == ProjectLicenseTemplate: | ||
tmpl_id = "smpl" | ||
tmpl_content.update({"key": tmpl_id}) | ||
path = f"projects/{project.id}/templates/{tmpl_path}/{tmpl_id}" | ||
with responses.RequestsMock() as rsps: | ||
rsps.add( | ||
method=responses.GET, | ||
url=f"http://localhost/api/v4/{path}", | ||
json=tmpl_content, | ||
) | ||
template = getattr(project, tmpl_mgr).get(tmpl_id) | ||
assert isinstance(template, tmpl) | ||
assert getattr(template, template._id_attr) == tmpl_id |
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.