Skip to content

Commit 477c99e

Browse files
committed
* Expands parser and data-structures for GitLab groups
1 parent bbd4328 commit 477c99e

File tree

8 files changed

+68
-48
lines changed

8 files changed

+68
-48
lines changed
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module Buckaroo.Tests.PackageIdentifier
22

33
open Xunit
4-
54
open Buckaroo
65

76
[<Fact>]
@@ -12,12 +11,17 @@ let ``PackageIdentifier.parse works correctly`` () =
1211
("github+abc/def", PackageIdentifier.GitHub { Owner = "abc"; Project = "def" });
1312
("github+abc/def_ghi", PackageIdentifier.GitHub { Owner = "abc"; Project = "def_ghi" });
1413
("bitbucket.org/abc/def", PackageIdentifier.BitBucket { Owner = "abc"; Project = "def" });
15-
("gitlab.com/abc/def", PackageIdentifier.GitLab { Owner = "abc"; Project = "def" });
16-
("gitlab.com/abc-def/xyz", PackageIdentifier.GitLab { Owner = "abc-def"; Project = "xyz" });
14+
("gitlab.com/abc/def", PackageIdentifier.GitLab { Groups = [ "abc" ]; Project = "def" });
15+
("gitlab.com/abc-def/xyz", PackageIdentifier.GitLab { Groups = [ "abc-def" ]; Project = "xyz" });
1716
("github.com/ABC-DEF/XYZ", PackageIdentifier.GitHub { Owner = "abc-def"; Project = "xyz" });
18-
("gitlab.com/ABC-DEF/XYZ", PackageIdentifier.GitLab { Owner = "abc-def"; Project = "xyz" });
17+
("gitlab.com/ABC-DEF/XYZ", PackageIdentifier.GitLab { Groups = [ "abc-def" ]; Project = "xyz" });
1918
("bitbucket.org/ABC-DEF/XYZ", PackageIdentifier.BitBucket { Owner = "abc-def"; Project = "xyz" });
19+
("gitlab.com/abc/def/xyz", PackageIdentifier.GitLab { Groups = [ "abc"; "def" ]; Project = "xyz" });
2020
]
2121

2222
for (input, expected) in cases do
23+
// Parses to what we expect?
2324
Assert.Equal(Result.Ok expected, PackageIdentifier.parse input)
25+
26+
// Round-trip via show
27+
Assert.Equal(Result.Ok expected, expected |> PackageIdentifier.show |> PackageIdentifier.parse)

buckaroo/GitLabApi.fs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ module Buckaroo.GitLabApi
33
open System
44
open FSharp.Data
55

6-
let fetchFile (package : AdhocPackageIdentifier) (commit : Revision) (file : string) = async {
6+
let fetchFile (package : GitLabPackageIdentifier) (commit : Revision) (file : string) = async {
77
if commit.Length <> 40
88
then
9-
return raise <| new ArgumentException("GitLab API requires full length commit hashes")
9+
return raise <| ArgumentException("GitLab API requires full length commit hashes")
1010
else
11-
let url =
12-
"https://gitlab.com/" + package.Owner + "/" + package.Project + "/raw/" + commit + "/" + file
11+
let url =
12+
"https://gitlab.com/" + (package.Groups |> String.concat "/") +
13+
"/" + package.Project + "/raw/" + commit + "/" + file
14+
1315
return! Http.AsyncRequestString(url)
1416
}

buckaroo/InstallCommand.fs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,13 @@ let rec computeCellIdentifier (parents : PackageIdentifier list) (package : Pack
131131
| PackageIdentifier.BitBucket bitBucket ->
132132
[ "buckaroo"; "bitbucket"; bitBucket.Owner; bitBucket.Project ]
133133
| PackageIdentifier.GitLab gitLab ->
134-
[ "buckaroo"; "gitlab"; gitLab.Owner; gitLab.Project ]
134+
seq {
135+
yield "buckaroo"
136+
yield "gitlab"
137+
yield! gitLab.Groups
138+
yield gitLab.Project
139+
}
140+
|> Seq.toList
135141
| PackageIdentifier.Adhoc adhoc ->
136142
[ "buckaroo"; "adhoc"; adhoc.Owner; adhoc.Project ]
137143
)
@@ -144,10 +150,10 @@ let rec packageInstallPath (parents : PackageIdentifier list) (package : Package
144150
| [] ->
145151
let (prefix, owner, project) =
146152
match package with
147-
| PackageIdentifier.GitHub x -> ("github", x.Owner, x.Project)
148-
| PackageIdentifier.BitBucket x -> ("bitbucket", x.Owner, x.Project)
149-
| PackageIdentifier.GitLab x -> ("gitlab", x.Owner, x.Project)
150-
| PackageIdentifier.Adhoc x -> ("adhoc", x.Owner, x.Project)
153+
| PackageIdentifier.GitHub x -> ("github", x.Owner, x.Project)
154+
| PackageIdentifier.BitBucket x -> ("bitbucket", x.Owner, x.Project)
155+
| PackageIdentifier.GitLab x -> ("gitlab", (x.Groups |> String.concat "."), x.Project)
156+
| PackageIdentifier.Adhoc x -> ("adhoc", x.Owner, x.Project)
151157
Path.Combine(".", Constants.PackagesDirectory, prefix, owner, project)
152158
| head::tail ->
153159
Path.Combine(packageInstallPath tail head, packageInstallPath [] package)
@@ -181,11 +187,11 @@ let writeReceipt (installPath : string) (packageLock : PackageLock) = async {
181187
"package = \"" + (PackageIdentifier.show package) + "\"\n" +
182188
"revision = \"" + g.Revision + "\"\n"
183189
| GitLab g ->
184-
let package = PackageIdentifier.GitHub g.Package
190+
let package = PackageIdentifier.GitLab g.Package
185191
"package = \"" + (PackageIdentifier.show package) + "\"\n" +
186192
"revision = \"" + g.Revision + "\"\n"
187193
| BitBucket b ->
188-
let package = PackageIdentifier.GitHub b.Package
194+
let package = PackageIdentifier.BitBucket b.Package
189195
"package = \"" + (PackageIdentifier.show package) + "\"\n" +
190196
"revision = \"" + b.Revision + "\"\n"
191197

buckaroo/PackageIdentifier.fs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ namespace Buckaroo
22

33
type AdhocPackageIdentifier = { Owner : string; Project : string }
44

5+
type GitLabPackageIdentifier = { Groups : string list; Project : string }
6+
57
type PackageIdentifier =
68
| GitHub of AdhocPackageIdentifier
79
| BitBucket of AdhocPackageIdentifier
8-
| GitLab of AdhocPackageIdentifier
10+
| GitLab of GitLabPackageIdentifier
911
| Adhoc of AdhocPackageIdentifier
1012

1113
module PackageIdentifier =
@@ -17,19 +19,13 @@ module PackageIdentifier =
1719
match id with
1820
| GitHub x -> "github.com/" + x.Owner + "/" + x.Project
1921
| BitBucket x -> "bitbucket.org/" + x.Owner + "/" + x.Project
20-
| GitLab x -> "gitlab.com/" + x.Owner + "/" + x.Project
22+
| GitLab x -> "gitlab.com/" + (x.Groups |> String.concat "/") + "/" + x.Project
2123
| Adhoc x -> x.Owner + "/" + x.Project
2224

2325
let showRich (id : PackageIdentifier) =
24-
let host = highlight
25-
let owner = highlight
26-
let project = highlight
27-
28-
match id with
29-
| GitHub x -> (host "github.com") + (subtle "/") + (owner x.Owner) + (subtle "/") + (project x.Project)
30-
| BitBucket x -> (host "bitbucket.org") + (subtle "/") + x.Owner + (subtle "/") + (project x.Project)
31-
| GitLab x -> (host "gitlab.com") + (subtle "/") + x.Owner + (subtle "/") + (project x.Project)
32-
| Adhoc x -> (owner x.Owner) + (subtle "/") + (project x.Project)
26+
id
27+
|> show
28+
|> identifier
3329

3430
let private gitHubIdentifierParser =
3531
CharParsers.regex @"[a-zA-Z.\d](?:[a-zA-Z_.\d]|-(?=[a-zA-Z_.\d])){0,38}"
@@ -46,7 +42,6 @@ module PackageIdentifier =
4642
| Success(result, _, _) -> Result.Ok result
4743
| Failure(error, _, _) -> Result.Error error
4844

49-
5045
let gitHubPackageIdentifierParser = parse {
5146
do! CharParsers.skipString "github.com/" <|> CharParsers.skipString "github+"
5247
let! owner = gitHubIdentifierParser
@@ -74,11 +69,18 @@ module PackageIdentifier =
7469
| Failure(error, _, _) -> Result.Error error
7570

7671
let gitLabPackageIdentifierParser = parse {
77-
do! CharParsers.skipString "gitlab.com/" <|> CharParsers.skipString "gitlab+"
78-
let! owner = gitHubIdentifierParser
72+
do! CharParsers.skipString "gitlab.com/"
73+
let! x = gitHubIdentifierParser
7974
do! CharParsers.skipString "/"
80-
let! project = gitHubIdentifierParser
81-
return { Owner = owner.ToLower(); Project = project.ToLower() }
75+
let! xs = Primitives.sepBy1 gitHubIdentifierParser (skipString "/")
76+
let parts =
77+
[ x ] @ xs
78+
|> List.map (fun x -> x.ToLower ())
79+
80+
return {
81+
Groups = parts |> List.truncate (parts.Length - 1)
82+
Project = parts |> List.last
83+
}
8284
}
8385

8486
let parseGitLabIdentifier (x : string) =

buckaroo/PackageLocation.fs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,40 @@
11
namespace Buckaroo
22

33
type HttpLocation = {
4-
Url : string;
5-
StripPrefix : string option;
6-
Type : ArchiveType option;
4+
Url : string
5+
StripPrefix : string option
6+
Type : ArchiveType option
77
}
88

99
type GitLocation = {
10-
Url : string;
11-
Revision : Revision;
10+
Url : string
11+
Revision : Revision
12+
}
13+
14+
type GitLabLocation = {
15+
Package : GitLabPackageIdentifier
16+
Revision : Revision
1217
}
1318

1419
type HostedGitLocation = {
15-
Package : AdhocPackageIdentifier;
16-
Revision : Revision;
20+
Package : AdhocPackageIdentifier
21+
Revision : Revision
1722
}
1823

1924
type PackageLocation =
2025
| Http of HttpLocation
2126
| Git of GitLocation
2227
| GitHub of HostedGitLocation
2328
| BitBucket of HostedGitLocation
24-
| GitLab of HostedGitLocation
29+
| GitLab of GitLabLocation
2530

2631
override this.ToString () =
2732
match this with
2833
| Http http -> http.Url + "#" + (http.StripPrefix |> Option.defaultValue "")
2934
| Git git -> git.Url + "#" + git.Revision
3035
| GitHub gitHub -> "github.com/" + gitHub.Package.Owner + "/" + gitHub.Package.Project + "#" + gitHub.Revision
3136
| BitBucket bitbucket -> "bitbucket.org/" + bitbucket.Package.Owner + "/" + bitbucket.Package.Project + "#" + bitbucket.Revision
32-
| GitLab gitLab -> "gitlab.com/" + gitLab.Package.Owner + "/" + gitLab.Package.Project + "#" + gitLab.Revision
37+
| GitLab gitLab -> "gitlab.com/" + (gitLab.Package.Groups |> String.concat "/") + "/" + gitLab.Package.Project + "#" + gitLab.Revision
3338

3439
module PackageLocation =
3540

@@ -49,12 +54,12 @@ module PackageLocation =
4954
else
5055
"ssh://[email protected]:" + x.Owner + "/" + x.Project + ".git"
5156

52-
let gitLabUrl (x : AdhocPackageIdentifier) =
57+
let gitLabUrl (x : GitLabPackageIdentifier) =
5358
if Environment.GetEnvironmentVariable "BUCKAROO_GITLAB_SSH" |> isNull
5459
then
55-
"https://gitlab.com/" + x.Owner + "/" + x.Project + ".git"
60+
"https://gitlab.com/" + (x.Groups |> String.concat "/") + "/" + x.Project + ".git"
5661
else
57-
"ssh://[email protected]:" + x.Owner + "/" + x.Project + ".git"
62+
"ssh://[email protected]:" + (x.Groups |> String.concat "/") + "/" + x.Project + ".git"
5863

5964
let versionSetFromLocation location =
6065
match location with

buckaroo/PackageLock.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type PackageLock =
99
| Git of GitLocation
1010
| GitHub of HostedGitLocation
1111
| BitBucket of HostedGitLocation
12-
| GitLab of HostedGitLocation
12+
| GitLab of GitLabLocation
1313

1414
module PackageLock =
1515

buckaroo/ResolvedVersion.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace Buckaroo
22

33
type ResolvedVersion = {
4-
Versions : Set<Version>;
5-
Lock : PackageLock;
6-
Manifest : Manifest;
4+
Versions : Set<Version>
5+
Lock : PackageLock
6+
Manifest : Manifest
77
}

buckaroo/RichOutput.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,5 @@ let subtle = text >> (foreground System.ConsoleColor.DarkGray)
113113
let warn = text >> (foreground System.ConsoleColor.Yellow)
114114
let info = text >> (foreground System.ConsoleColor.Cyan)
115115
let success = text >> (foreground System.ConsoleColor.Green)
116-
let highlight = text >> (foreground System.ConsoleColor.White)
116+
let highlight = text >> (foreground System.ConsoleColor.White)
117+
let identifier = text >> (foreground System.ConsoleColor.Magenta)

0 commit comments

Comments
 (0)