Skip to content

Commit

Permalink
#114 Import all projects from specified namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
mnvx committed Jan 19, 2023
1 parent 6fd9015 commit 0f6897b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
1 change: 1 addition & 0 deletions .env.docker.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 0 additions & 13 deletions app/Model/Service/Eloquent/EloquentIssueService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,16 @@ 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');
}

/**
* @inheritdoc
*/
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);
Expand Down
17 changes: 14 additions & 3 deletions app/Model/Service/Eloquent/EloquentProjectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,32 @@ 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');
}

/**
* @inheritdoc
*/
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);
}
}
Expand Down
5 changes: 4 additions & 1 deletion config/gitlab.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
: [],
],

];

0 comments on commit 0f6897b

Please sign in to comment.