From 0f6897b1e50d0086149f72c242e97f0c119a9fae Mon Sep 17 00:00:00 2001 From: mnv Date: Thu, 19 Jan 2023 18:27:53 +0300 Subject: [PATCH] #114 Import all projects from specified namespaces --- .env.docker.example | 1 + .env.example | 1 + .../Service/Eloquent/EloquentIssueService.php | 13 ------------- .../Service/Eloquent/EloquentProjectService.php | 17 ++++++++++++++--- config/gitlab.php | 5 ++++- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/.env.docker.example b/.env.docker.example index 559ffd1..5ec2a6a 100644 --- a/.env.docker.example +++ b/.env.docker.example @@ -42,3 +42,4 @@ HTTP_PORT=8000 GITLAB_HOST=https://gitlab.com/ GITLAB_PRIVATE_TOKEN=your_gitlab_token GITLAB_RESTRICTIONS_PROJECT_IDS=1111,2222,3333 +GITLAB_RESTRICTIONS_GROUP_IDS=1212,2323 diff --git a/.env.example b/.env.example index d62cea5..59d294f 100644 --- a/.env.example +++ b/.env.example @@ -42,3 +42,4 @@ HTTP_PORT=8000 GITLAB_HOST=https://gitlab.com/ GITLAB_PRIVATE_TOKEN=your_gitlab_token GITLAB_RESTRICTIONS_PROJECT_IDS=1111,2222,3333 +GITLAB_RESTRICTIONS_GROUP_IDS=1212,2323 diff --git a/app/Model/Service/Eloquent/EloquentIssueService.php b/app/Model/Service/Eloquent/EloquentIssueService.php index 5f5cb05..c058836 100644 --- a/app/Model/Service/Eloquent/EloquentIssueService.php +++ b/app/Model/Service/Eloquent/EloquentIssueService.php @@ -15,13 +15,9 @@ class EloquentIssueService extends CrudServiceAbstract use StoreContributorsTrait; use StoreLabelsTrait; - /** @var int[]|null */ - protected $filterProjectIds = null; - public function __construct() { $this->repository = app(AppServiceProvider::ISSUE_REPOSITORY); - $this->filterProjectIds = config('gitlab.restrictions.project_ids'); } /** @@ -29,15 +25,6 @@ public function __construct() */ public function storeList(Collection $list) { - // If selected only concrete projects, we update only them - if ($this->filterProjectIds !== null) { - foreach ($list as $key => $item) { - if (!in_array($item['project_id'], $this->filterProjectIds)) { - $list->pull($key); - } - } - } - $this->storeContributors($list, ['author', 'assignee']); $this->storeLabels($list, 'labels'); parent::storeList($list); diff --git a/app/Model/Service/Eloquent/EloquentProjectService.php b/app/Model/Service/Eloquent/EloquentProjectService.php index c9d3dac..559e258 100644 --- a/app/Model/Service/Eloquent/EloquentProjectService.php +++ b/app/Model/Service/Eloquent/EloquentProjectService.php @@ -16,10 +16,14 @@ class EloquentProjectService extends CrudServiceAbstract /** @var int[]|null */ protected $filterProjectIds = null; + /** @var int[]|null */ + protected $filterGroupIds = null; + public function __construct() { $this->repository = app(AppServiceProvider::PROJECT_REPOSITORY); $this->filterProjectIds = config('gitlab.restrictions.project_ids'); + $this->filterGroupIds = config('gitlab.restrictions.group_ids'); } /** @@ -27,10 +31,17 @@ public function __construct() */ public function storeList(Collection $list) { - // If selected only concrete projects, we update only them - if ($this->filterProjectIds !== null) { + $projectIds = $this->filterProjectIds; + $groupIds = $this->filterGroupIds; + + // If selected only concrete projects or groups, we update only them + if (!empty($projectIds) || !empty($groupIds)) { foreach ($list as $key => $item) { - if (!in_array($item['id'], $this->filterProjectIds)) { + if (!(in_array($item['id'], $projectIds) || ( + ($item['namespace']['id'] ?? null) && + ($item['namespace']['kind'] ?? null) == 'group' && + in_array($item['namespace']['id'], $groupIds) + ))) { $list->pull($key); } } diff --git a/config/gitlab.php b/config/gitlab.php index b1894d9..bd18704 100644 --- a/config/gitlab.php +++ b/config/gitlab.php @@ -23,7 +23,10 @@ // int[]|null 'project_ids' => env('GITLAB_RESTRICTIONS_PROJECT_IDS') ? explode(',', env('GITLAB_RESTRICTIONS_PROJECT_IDS')) - : null, + : [], + 'group_ids' => env('GITLAB_RESTRICTIONS_GROUP_IDS') + ? explode(',', env('GITLAB_RESTRICTIONS_GROUP_IDS')) + : [], ], ];