This repository has been archived by the owner on Jul 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for "org" mode for selfhosted BitBucket. (#589)
You need to provide the --Api switch when using this mode otherwise Nukeeper will default to use GitHub
- Loading branch information
1 parent
b62819d
commit 09a9bac
Showing
4 changed files
with
94 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
Nukeeper.BitBucketLocal/BitbucketLocalRepositoryDiscovery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text.RegularExpressions; | ||
using System.Threading.Tasks; | ||
using NuKeeper.Abstractions.CollaborationModels; | ||
using NuKeeper.Abstractions.CollaborationPlatform; | ||
using NuKeeper.Abstractions.Configuration; | ||
using NuKeeper.Abstractions.Logging; | ||
|
||
namespace NuKeeper.BitBucketLocal | ||
{ | ||
public class BitbucketLocalRepositoryDiscovery : IRepositoryDiscovery | ||
{ | ||
private readonly INuKeeperLogger _logger; | ||
private readonly ICollaborationPlatform _collaborationPlatform; | ||
private CollaborationPlatformSettings _setting; | ||
|
||
public BitbucketLocalRepositoryDiscovery(INuKeeperLogger logger, ICollaborationPlatform collaborationPlatform, CollaborationPlatformSettings settings) | ||
{ | ||
_logger = logger; | ||
_collaborationPlatform = collaborationPlatform; | ||
_setting = settings; | ||
} | ||
|
||
public async Task<IEnumerable<RepositorySettings>> GetRepositories(SourceControlServerSettings settings) | ||
{ | ||
switch (settings.Scope) | ||
{ | ||
case ServerScope.Global: | ||
_logger.Error($"{settings.Scope} not yet implemented"); | ||
throw new NotImplementedException(); | ||
|
||
case ServerScope.Organisation: | ||
return await FromOrganisation(settings.OrganisationName, settings); | ||
|
||
case ServerScope.Repository: | ||
return await Task.FromResult(new List<RepositorySettings> { settings.Repository }.AsEnumerable()); | ||
|
||
default: | ||
_logger.Error($"Unknown Server Scope {settings.Scope}"); | ||
return await Task.FromResult(Enumerable.Empty<RepositorySettings>()); | ||
} | ||
} | ||
|
||
|
||
|
||
private async Task<IReadOnlyCollection<RepositorySettings>> FromOrganisation(string organisationName, SourceControlServerSettings settings) | ||
{ | ||
var allOrgRepos = await _collaborationPlatform.GetRepositoriesForOrganisation(organisationName); | ||
|
||
var usableRepos = allOrgRepos | ||
.Where(r => MatchesIncludeExclude(r, settings)) | ||
.ToList(); | ||
|
||
if (allOrgRepos.Count > usableRepos.Count) | ||
{ | ||
_logger.Detailed($"Can pull from {usableRepos.Count} repos out of {allOrgRepos.Count}"); | ||
} | ||
|
||
return usableRepos | ||
.Select(r => new RepositorySettings() | ||
{ | ||
ApiUri = _setting.BaseApiUrl, | ||
RepositoryUri = r.HtmlUrl, | ||
RepositoryName = r.Name, | ||
RepositoryOwner = organisationName | ||
}).ToList(); | ||
} | ||
|
||
private static bool MatchesIncludeExclude(Repository repo, SourceControlServerSettings settings) | ||
{ | ||
return | ||
MatchesInclude(settings.IncludeRepos, repo) | ||
&& !MatchesExclude(settings.ExcludeRepos, repo); | ||
} | ||
|
||
private static bool MatchesInclude(Regex regex, Repository repo) | ||
{ | ||
return regex == null || regex.IsMatch(repo.Name); | ||
} | ||
|
||
private static bool MatchesExclude(Regex regex, Repository repo) | ||
{ | ||
return regex != null && regex.IsMatch(repo.Name); | ||
} | ||
|
||
} | ||
} |