diff --git a/README.md b/README.md index 3f91056..fbac336 100644 --- a/README.md +++ b/README.md @@ -38,17 +38,20 @@ This tap: - API URL for your GitLab account. If you are using the public gitlab.com this will be `https://gitlab.com/api/v3` - Groups to track (space separated) - Projects to track (space separated) + - Recurse through subgroups (boolean). If true, all subgroups will be tracked of the groups specified in the Groups setting will be tracked Notes: - either groups or projects need to be provided - filling in 'groups' but leaving 'projects' empty will sync all group projects. + - filling in 'groups' and setting 'recurse' to true will sync all group projects and all subgroups projects. - filling in 'projects' but leaving 'groups' empty will sync selected projects. - filling in 'groups' and 'groups' will sync selected projects of those groups. ```json {"api_url": "https://gitlab.com/api/v3", "private_token": "your-access-token", - "groups": "myorg mygroup", + "groups": "myorg mygroup", + "recurse_groups": false, "projects": "myorg/repo-a myorg/repo-b", "start_date": "2018-01-01T00:00:00Z"} ``` diff --git a/tap_gitlab/__init__.py b/tap_gitlab/__init__.py index d8d1277..20291e8 100644 --- a/tap_gitlab/__init__.py +++ b/tap_gitlab/__init__.py @@ -16,6 +16,7 @@ 'api_url': "https://gitlab.com/api/v3", 'private_token': None, 'start_date': None, + 'recurse_groups': False, 'groups': '' } STATE = {} @@ -57,6 +58,11 @@ def load_schema(entity): 'schema': load_schema('milestones'), 'key_properties': ['id'], }, + 'group_subgroups': { + 'url': '/groups/{}/subgroups', + 'schema': load_schema('groups'), + 'key_properties': ['id'], + }, 'users': { 'url': '/projects/{}/users', 'schema': load_schema('users'), @@ -211,6 +217,14 @@ def sync_group(gid, pids): if project['id']: pids.append(project['id']) + if CONFIG['recurse_groups'] is True: + group_subgroups_url = get_url("group_subgroups", id=gid) + print(group_subgroups_url) + + for group in gen_request(group_subgroups_url): + if group["name"]: + sync_group(str(group["full_path"].replace("/", "%2F")), []) + for pid in pids: sync_project(pid)