Organization: Add create staticmethod

parent 38c66a6e
Pipeline #27950058 passed with stages
in 32 seconds
......@@ -6,6 +6,7 @@ from typing import Set
from typing import Optional
from urllib.parse import quote_plus
from IGitt.GitHub import GitHubToken
from IGitt.GitHub import GH_INSTANCE_URL
from IGitt.GitHub import GitHubMixin
from IGitt.GitHub.GitHubIssue import GitHubIssue
......@@ -139,3 +140,18 @@ class GitHubOrganization(GitHubMixin, Organization):
Returns the set of Issues in this organization.
"""
return self.filter_issues(state='opened')
@staticmethod
def create(token: GitHubToken,
name: str,
path: str,
parent_id: Optional[int]=None,
description: Optional[str]=None,
visibility: str='private',
lfs_enabled: bool=False,
request_access_enabled: bool=False) -> Organization:
"""
GitHub does not allow creating new organizations via the API.
"""
raise NotImplementedError('GitHub does not allow creating '
'new organizations via the API as of now.')
......@@ -6,13 +6,17 @@ import re
from functools import lru_cache
from typing import Set
from typing import Optional
from typing import Union
from urllib.parse import quote_plus
from IGitt.GitLab import GitLabPrivateToken
from IGitt.GitLab import GitLabOAuthToken
from IGitt.GitLab import GL_INSTANCE_URL
from IGitt.GitLab import GitLabMixin
from IGitt.GitLab.GitLabUser import GitLabUser
from IGitt.GitLab.GitLabIssue import GitLabIssue
from IGitt.Interfaces import get
from IGitt.Interfaces import post
from IGitt.Interfaces import AccessLevel
from IGitt.Interfaces.Organization import Organization
from IGitt.Interfaces.Repository import Repository
......@@ -184,3 +188,47 @@ class GitLabOrganization(GitLabMixin, Organization):
Returns the list of issue objects in this organization.
"""
return self.filter_issues(state='opened')
@staticmethod
def create(token: Union[GitLabOAuthToken, GitLabPrivateToken],
name: str,
path: str,
parent_id: Optional[int]=None,
description: Optional[str]=None,
visibility: str='private',
lfs_enabled: bool=False,
request_access_enabled: bool=False) -> Organization:
"""
Creates a new organization from the given parameters.
:param token:
The credentials to be used for authorization.
:param name:
The name of the organization.
:param path:
The path of the organization.
:param parent_id:
The parent organization id to create nested organization.
:param description:
The description of the organization.
:param visibility:
Controls the visibility of the organization. Can be either
'private', 'public' or 'internal'.
:param lfs_enabled:
Enables Git Large File System for projects in this organization.
:param request_access_enabled:
Allow users to request member access on the organization.
"""
url = '/groups'
org = post(
token,
GitLabOrganization.absolute_url(url),
{'name': name,
'path': path,
'description': description,
'visibility': visibility,
'lfs_enabled': lfs_enabled,
'request_access_enabled': request_access_enabled,
'parent_id': parent_id}
)
return GitLabOrganization.from_data(org, token, org['name'])
......@@ -5,6 +5,7 @@ actions related to issues and bug reports.
from typing import Set
from typing import Optional
from IGitt.Interfaces import Token
from IGitt.Interfaces import IGittObject
from IGitt.Interfaces.User import User
from IGitt.Interfaces.Issue import Issue
......@@ -92,3 +93,35 @@ class Organization(IGittObject):
Returns set of issue objects in this organization.
"""
raise NotImplementedError
@staticmethod
def create(token: Token,
name: str,
path: str,
parent_id: Optional[int]=None,
description: Optional[str]=None,
visibility: str='private',
lfs_enabled: bool=False,
request_access_enabled: bool=False):
"""
Creates a new organization from the given parameters.
:param token:
The credentials to be used for authorization.
:param name:
The name of the organization.
:param path:
The path of the organization.
:param parent_id:
The parent organization id to create nested organization.
:param description:
The description of the organization.
:param visibility:
Controls the visibility of the organization. Can be either
'private', 'public' or 'internal'.
:param lfs_enabled:
Enables Git Large File System for projects in this organization.
:param request_access_enabled:
Allow users to request member access on the organization.
"""
raise NotImplementedError
......@@ -62,3 +62,7 @@ class GitHubOrganizationTest(IGittTestCase):
def test_identifier(self):
self.assertEqual(self.org.identifier, 32204920)
def test_create(self):
with self.assertRaises(NotImplementedError):
GitHubOrganization.create(self.token, 'random', 'random')
interactions:
- request:
body: '{}'
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
Content-Length: ['2']
Content-Type: [application/json]
User-Agent: [IGitt]
method: GET
uri: https://gitlab.com/api/v4/groups/gitmate-test-org?per_page=100
response:
body: {string: '{"id":1999111,"web_url":"https://gitlab.com/groups/gitmate-test-org","name":"gitmate-test-org","path":"gitmate-test-org","description":"","visibility":"public","lfs_enabled":true,"avatar_url":null,"request_access_enabled":false,"full_name":"gitmate-test-org","full_path":"gitmate-test-org","parent_id":null,"projects":[{"id":5731027,"description":"","name":"test","name_with_namespace":"gitmate-test-org
/ test","path":"test","path_with_namespace":"gitmate-test-org/test","created_at":"2018-03-12T19:21:26.165Z","default_branch":null,"tag_list":[],"ssh_url_to_repo":"[email protected]:gitmate-test-org/test.git","http_url_to_repo":"https://gitlab.com/gitmate-test-org/test.git","web_url":"https://gitlab.com/gitmate-test-org/test","readme_url":null,"avatar_url":null,"star_count":0,"forks_count":0,"last_activity_at":"2018-07-07T14:26:12.700Z","namespace":{"id":1999111,"name":"gitmate-test-org","path":"gitmate-test-org","kind":"group","full_path":"gitmate-test-org","parent_id":null},"_links":{"self":"https://gitlab.com/api/v4/projects/5731027","issues":"https://gitlab.com/api/v4/projects/5731027/issues","merge_requests":"https://gitlab.com/api/v4/projects/5731027/merge_requests","repo_branches":"https://gitlab.com/api/v4/projects/5731027/repository/branches","labels":"https://gitlab.com/api/v4/projects/5731027/labels","events":"https://gitlab.com/api/v4/projects/5731027/events","members":"https://gitlab.com/api/v4/projects/5731027/members"},"archived":false,"visibility":"public","resolve_outdated_diff_discussions":false,"container_registry_enabled":true,"issues_enabled":true,"merge_requests_enabled":true,"wiki_enabled":true,"jobs_enabled":true,"snippets_enabled":true,"shared_runners_enabled":true,"lfs_enabled":true,"creator_id":889700,"import_status":"none","open_issues_count":2,"public_jobs":true,"ci_config_path":null,"shared_with_groups":[],"only_allow_merge_if_pipeline_succeeds":false,"request_access_enabled":false,"only_allow_merge_if_all_discussions_are_resolved":false,"printing_merge_request_link_enabled":true,"merge_method":"merge","approvals_before_merge":0,"mirror":false}],"shared_projects":[],"ldap_cn":null,"ldap_access":null,"shared_runners_minutes_limit":null}'}
headers:
Cache-Control: ['max-age=0, private, must-revalidate']
Content-Length: ['2195']
Content-Type: [application/json]
Date: ['Wed, 15 Aug 2018 11:33:28 GMT']
Etag: [W/"5ab4ea8a633789c9226fe8178e060b15"]
RateLimit-Limit: ['600']
RateLimit-Observed: ['3']
RateLimit-Remaining: ['597']
RateLimit-Reset: ['1534332868']
RateLimit-ResetTime: ['Thu, 15 Aug 2018 11:34:28 GMT']
Server: [nginx]
Strict-Transport-Security: [max-age=31536000]
Vary: [Origin]
X-Content-Type-Options: [nosniff]
X-Frame-Options: [SAMEORIGIN]
X-Request-Id: [97b5c300-7fd9-4b31-a9df-a24a5cd199cf]
X-Runtime: ['0.081811']
status: {code: 200, message: OK}
- request:
body: '{"name": "ya-group", "path": "ya-group", "description": "yet another test
organization", "visibility": "public", "lfs_enabled": false, "request_access_enabled":
false, "parent_id": 1999111}'
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
Content-Length: ['189']
Content-Type: [application/json]
User-Agent: [IGitt]
method: POST
uri: https://gitlab.com/api/v4/groups
response:
body: {string: '{"id":3444522,"web_url":"https://gitlab.com/groups/gitmate-test-org/ya-group","name":"ya-group","path":"ya-group","description":"yet
another test organization","visibility":"public","lfs_enabled":false,"avatar_url":null,"request_access_enabled":false,"full_name":"gitmate-test-org
/ ya-group","full_path":"gitmate-test-org/ya-group","parent_id":1999111,"projects":[],"shared_projects":[],"ldap_cn":null,"ldap_access":null,"shared_runners_minutes_limit":null}'}
headers:
Cache-Control: ['max-age=0, private, must-revalidate']
Content-Length: ['458']
Content-Type: [application/json]
Date: ['Wed, 15 Aug 2018 11:33:30 GMT']
Etag: [W/"956481e380f57111ec5439d0c2b79f89"]
RateLimit-Limit: ['600']
RateLimit-Observed: ['1']
RateLimit-Remaining: ['599']
RateLimit-Reset: ['1534332870']
RateLimit-ResetTime: ['Thu, 15 Aug 2018 11:34:30 GMT']
Server: [nginx]
Strict-Transport-Security: [max-age=31536000]
Vary: [Origin]
X-Content-Type-Options: [nosniff]
X-Frame-Options: [SAMEORIGIN]
X-Request-Id: [646dfe3d-e3d4-4e24-8a64-ed1a58d9dd3e]
X-Runtime: ['0.503022']
status: {code: 201, message: Created}
version: 1
......@@ -78,3 +78,13 @@ class GitLabOrganizationTest(IGittTestCase):
def test_identifier(self):
self.assertEqual(self.org.identifier, 1999111)
def test_create(self):
org = GitLabOrganization.create(self.token,
'ya-group',
'ya-group',
self.org.identifier,
'yet another test organization',
'public')
self.assertEqual(org.name, 'ya-group')
self.assertEqual(org.description, 'yet another test organization')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment