Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1114 from evolvedlight/master
Browse files Browse the repository at this point in the history
Add support for Gitlab organisations
  • Loading branch information
msallin authored Sep 21, 2021
2 parents 224ae20 + adb3d4d commit 382511f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
24 changes: 24 additions & 0 deletions NuKeeper.Gitlab.Tests/GitlabSettingsReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ public async Task AssumesItCanReadGitLabUrls()
Assert.AreEqual(true, canRead);
}

[Test]
public async Task AssumesItCanReadGitLabOrganisationUrls()
{
var canRead = await _gitlabSettingsReader.CanRead(new Uri("https://gitlab.com/org/user/projectname.git"));

Assert.AreEqual(true, canRead);
}

[TestCase(null)]
[TestCase("master")]
public async Task GetsCorrectSettingsFromTheUrl(string targetBranch)
Expand All @@ -67,5 +75,21 @@ public async Task GetsCorrectSettingsFromTheUrl(string targetBranch)
Assert.AreEqual(targetBranch, repositorySettings.RemoteInfo?.BranchName);
Assert.AreEqual(false, repositorySettings.SetAutoMerge);
}

[TestCase(null)]
[TestCase("master")]
public async Task GetsCorrectSettingsFromTheOrganisationUrl(string targetBranch)
{
var repositoryUri = new Uri("https://gitlab.com/org/user/projectname.git");
var repositorySettings = await _gitlabSettingsReader.RepositorySettings(repositoryUri, true, targetBranch);

Assert.IsNotNull(repositorySettings);
Assert.AreEqual(new Uri("https://gitlab.com/api/v4/"), repositorySettings.ApiUri);
Assert.AreEqual(repositoryUri, repositorySettings.RepositoryUri);
Assert.AreEqual("org/user", repositorySettings.RepositoryOwner);
Assert.AreEqual("projectname", repositorySettings.RepositoryName);
Assert.AreEqual(targetBranch, repositorySettings.RemoteInfo?.BranchName);
Assert.AreEqual(false, repositorySettings.SetAutoMerge);
}
}
}
6 changes: 3 additions & 3 deletions NuKeeper.Gitlab/GitlabSettingsReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ public Task<RepositorySettings> RepositorySettings(Uri repositoryUri, bool setAu
.Where(s => !string.IsNullOrWhiteSpace(s))
.ToList();

if (pathParts.Count != 2)
if (pathParts.Count < 2)
{
throw new NuKeeperException(
$"The provided uri was is not in the correct format. Provided {repositoryUri} and format should be {UrlPattern}");
}

var repoOwner = pathParts[0];
var repoName = pathParts[1].Replace(".git", string.Empty);
var repoOwner = string.Join("/", pathParts.Take(pathParts.Count - 1));
var repoName = pathParts.Last().Replace(".git", string.Empty);

var uriBuilder = new UriBuilder(repositoryUri) { Path = "/api/v4/" };

Expand Down

0 comments on commit 382511f

Please sign in to comment.