| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,6 +7,7 @@ API examples | |||
| 7 | 7 | ||
| 8 | 8 | gl_objects/access_requests | |
| 9 | 9 | gl_objects/emojis | |
| 10 | + gl_objects/badges | ||
| 10 | 11 | gl_objects/branches | |
| 11 | 12 | gl_objects/protected_branches | |
| 12 | 13 | gl_objects/messages | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,52 @@ | |||
| 1 | + ###### | ||
| 2 | + Badges | ||
| 3 | + ###### | ||
| 4 | + | ||
| 5 | + Badges can be associated with groups and projects. | ||
| 6 | + | ||
| 7 | + Reference | ||
| 8 | + --------- | ||
| 9 | + | ||
| 10 | + * v4 API: | ||
| 11 | + | ||
| 12 | + + :class:`gitlab.v4.objects.GroupBadge` | ||
| 13 | + + :class:`gitlab.v4.objects.GroupBadgeManager` | ||
| 14 | + + :attr:`gitlab.v4.objects.Group.badges` | ||
| 15 | + + :class:`gitlab.v4.objects.ProjectBadge` | ||
| 16 | + + :class:`gitlab.v4.objects.ProjectBadgeManager` | ||
| 17 | + + :attr:`gitlab.v4.objects.Project.badges` | ||
| 18 | + | ||
| 19 | + * GitLab API: | ||
| 20 | + | ||
| 21 | + + https://docs.gitlab.com/ce/api/group_badges.html | ||
| 22 | + + https://docs.gitlab.com/ce/api/project_badges.html | ||
| 23 | + | ||
| 24 | + Examples | ||
| 25 | + -------- | ||
| 26 | + | ||
| 27 | + List badges:: | ||
| 28 | + | ||
| 29 | + badges = group_or_project.badges.list() | ||
| 30 | + | ||
| 31 | + Get ad badge:: | ||
| 32 | + | ||
| 33 | + badge = group_or_project.badges.get(badge_id) | ||
| 34 | + | ||
| 35 | + Create a badge:: | ||
| 36 | + | ||
| 37 | + badge = group_or_project.badges.create({'link_url': link, 'image_url': image_link}) | ||
| 38 | + | ||
| 39 | + Update a badge:: | ||
| 40 | + | ||
| 41 | + badge.image_link = new_link | ||
| 42 | + badge.save() | ||
| 43 | + | ||
| 44 | + Delete a badge:: | ||
| 45 | + | ||
| 46 | + badge.delete() | ||
| 47 | + | ||
| 48 | + Render a badge (preview the generate URLs):: | ||
| 49 | + | ||
| 50 | + output = group_or_project.badges.render(link, image_link) | ||
| 51 | + print(output['rendered_link_url']) | ||
| 52 | + print(output['rendered_image_url']) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -213,6 +213,10 @@ class GitlabVerifyError(GitlabOperationError): | |||
| 213 | 213 | pass | |
| 214 | 214 | ||
| 215 | 215 | ||
| 216 | + class GitlabRenderError(GitlabOperationError): | ||
| 217 | + pass | ||
| 218 | + | ||
| 219 | + | ||
| 216 | 220 | def on_http_error(error): | |
| 217 | 221 | """Manage GitlabHttpError exceptions. | |
| 218 | 222 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -571,3 +571,27 @@ def participants(self, **kwargs): | |||
| 571 | 571 | ||
| 572 | 572 | path = '%s/%s/participants' % (self.manager.path, self.get_id()) | |
| 573 | 573 | return self.manager.gitlab.http_get(path, **kwargs) | |
| 574 | + | ||
| 575 | + | ||
| 576 | + class BadgeRenderMixin(object): | ||
| 577 | + @cli.register_custom_action(('GroupBadgeManager', 'ProjectBadgeManager'), | ||
| 578 | + ('link_url', 'image_url')) | ||
| 579 | + @exc.on_http_error(exc.GitlabRenderError) | ||
| 580 | + def render(self, link_url, image_url, **kwargs): | ||
| 581 | + """Preview link_url and image_url after interpolation. | ||
| 582 | + | ||
| 583 | + Args: | ||
| 584 | + link_url (str): URL of the badge link | ||
| 585 | + image_url (str): URL of the badge image | ||
| 586 | + **kwargs: Extra options to send to the server (e.g. sudo) | ||
| 587 | + | ||
| 588 | + Raises: | ||
| 589 | + GitlabAuthenticationError: If authentication is not correct | ||
| 590 | + GitlabRenderError: If the rendering failed | ||
| 591 | + | ||
| 592 | + Returns: | ||
| 593 | + dict: The rendering properties | ||
| 594 | + """ | ||
| 595 | + path = '%s/render' % self.path | ||
| 596 | + data = {'link_url': link_url, 'image_url': image_url} | ||
| 597 | + return self.gitlab.http_get(path, data, **kwargs) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -555,6 +555,18 @@ class GroupAccessRequestManager(ListMixin, CreateMixin, DeleteMixin, | |||
| 555 | 555 | _from_parent_attrs = {'group_id': 'id'} | |
| 556 | 556 | ||
| 557 | 557 | ||
| 558 | + class GroupBadge(SaveMixin, ObjectDeleteMixin, RESTObject): | ||
| 559 | + pass | ||
| 560 | + | ||
| 561 | + | ||
| 562 | + class GroupBadgeManager(BadgeRenderMixin, CRUDMixin, RESTManager): | ||
| 563 | + _path = '/groups/%(group_id)s/badges' | ||
| 564 | + _obj_cls = GroupBadge | ||
| 565 | + _from_parent_attrs = {'group_id': 'id'} | ||
| 566 | + _create_attrs = (('link_url', 'image_url'), tuple()) | ||
| 567 | + _update_attrs = (tuple(), ('link_url', 'image_url')) | ||
| 568 | + | ||
| 569 | + | ||
| 558 | 570 | class GroupBoardList(SaveMixin, ObjectDeleteMixin, RESTObject): | |
| 559 | 571 | pass | |
| 560 | 572 | ||
@@ -746,6 +758,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject): | |||
| 746 | 758 | _short_print_attr = 'name' | |
| 747 | 759 | _managers = ( | |
| 748 | 760 | ('accessrequests', 'GroupAccessRequestManager'), | |
| 761 | + ('badges', 'GroupBadgeManager'), | ||
| 749 | 762 | ('boards', 'GroupBoardManager'), | |
| 750 | 763 | ('customattributes', 'GroupCustomAttributeManager'), | |
| 751 | 764 | ('issues', 'GroupIssueManager'), | |
@@ -1398,12 +1411,12 @@ class ProjectBadge(SaveMixin, ObjectDeleteMixin, RESTObject): | |||
| 1398 | 1411 | pass | |
| 1399 | 1412 | ||
| 1400 | 1413 | ||
| 1401 | - class ProjectBadgeManager(CRUDMixin, RESTManager): | ||
| 1414 | + class ProjectBadgeManager(BadgeRenderMixin, CRUDMixin, RESTManager): | ||
| 1402 | 1415 | _path = '/projects/%(project_id)s/badges' | |
| 1403 | 1416 | _obj_cls = ProjectBadge | |
| 1404 | 1417 | _from_parent_attrs = {'project_id': 'id'} | |
| 1405 | 1418 | _create_attrs = (('link_url', 'image_url'), tuple()) | |
| 1406 | - _update_attrs = (('link_url', 'image_url'), tuple()) | ||
| 1419 | + _update_attrs = (tuple(), ('link_url', 'image_url')) | ||
| 1407 | 1420 | ||
| 1408 | 1421 | ||
| 1409 | 1422 | class ProjectEvent(Event): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -274,6 +274,18 @@ | |||
| 274 | 274 | settings = group2.notificationsettings.get() | |
| 275 | 275 | assert(settings.level == 'disabled') | |
| 276 | 276 | ||
| 277 | + # group badges | ||
| 278 | + badge_image = 'http://example.com' | ||
| 279 | + badge_link = 'http://example/img.svg' | ||
| 280 | + badge = group2.badges.create({'link_url': badge_link, 'image_url': badge_image}) | ||
| 281 | + assert(len(group2.badges.list()) == 1) | ||
| 282 | + badge.image_url = 'http://another.example.com' | ||
| 283 | + badge.save() | ||
| 284 | + badge = group2.badges.get(badge.id) | ||
| 285 | + assert(badge.image_url == 'http://another.example.com') | ||
| 286 | + badge.delete() | ||
| 287 | + assert(len(group2.badges.list()) == 0) | ||
| 288 | + | ||
| 277 | 289 | # group milestones | |
| 278 | 290 | gm1 = group1.milestones.create({'title': 'groupmilestone1'}) | |
| 279 | 291 | assert(len(group1.milestones.list()) == 1) | |
@@ -656,8 +668,14 @@ | |||
| 656 | 668 | # project badges | |
| 657 | 669 | badge_image = 'http://example.com' | |
| 658 | 670 | badge_link = 'http://example/img.svg' | |
| 659 | - bp = admin_project.badges.create({'link_url': badge_link, 'image_url': badge_image}) | ||
| 671 | + badge = admin_project.badges.create({'link_url': badge_link, 'image_url': badge_image}) | ||
| 660 | 672 | assert(len(admin_project.badges.list()) == 1) | |
| 673 | + badge.image_url = 'http://another.example.com' | ||
| 674 | + badge.save() | ||
| 675 | + badge = admin_project.badges.get(badge.id) | ||
| 676 | + assert(badge.image_url == 'http://another.example.com') | ||
| 677 | + badge.delete() | ||
| 678 | + assert(len(admin_project.badges.list()) == 0) | ||
| 661 | 679 | ||
| 662 | 680 | # project wiki | |
| 663 | 681 | wiki_content = 'Wiki page content' | |
| Back | FazBrowse Home | New Git URL |
0 commit comments