Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
module github.com/git-pkgs/resolve

go 1.26
go 1.26.0

toolchain go1.26.7

require github.com/git-pkgs/purl v0.1.12
require github.com/git-pkgs/purl v0.1.20

require (
github.com/package-url/packageurl-go v0.1.6 // indirect
github.com/package-url/packageurl-go v0.1.7 // indirect
go.yaml.in/yaml/v3 v3.0.5 // indirect
)

require (
github.com/git-pkgs/managers v0.12.0
github.com/git-pkgs/vers v0.2.5 // indirect
github.com/git-pkgs/vers v0.6.0 // indirect
)
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
github.com/git-pkgs/managers v0.12.0 h1:Ex0fZ7hOzoxzXYLmY5ghxqel6jAltaehuGOcPFeQz4U=
github.com/git-pkgs/managers v0.12.0/go.mod h1:gWk/V63R12skgcTmVsYgED/kxlk2MERS2iWMYKBrJeM=
github.com/git-pkgs/purl v0.1.12 h1:qCskrEU1LWQhCkIVZd992W5++Bsxazvx2Cx1/65qCvU=
github.com/git-pkgs/purl v0.1.12/go.mod h1:ofp4mHsR0cUeVONQaf33n6Wxg2QTEvtUdRfCedI8ouA=
github.com/git-pkgs/vers v0.2.5 h1:tDtUMik9Iw1lyPHdT5V6LXjLo9LsJc0xOawURz7ibQU=
github.com/git-pkgs/vers v0.2.5/go.mod h1:biTbSQK1qdbrsxDEKnqe3Jzclxz8vW6uDcwKjfUGcOo=
github.com/package-url/packageurl-go v0.1.6 h1:YO3p6u1XmCUliivUg/qWphaY8vI6hxSnnPv7Bfg3m5M=
github.com/package-url/packageurl-go v0.1.6/go.mod h1:nKAWB8E6uk1MHqiS/lQb9pYBGH2+mdJ2PJc2s50dQY0=
github.com/git-pkgs/purl v0.1.20 h1:a4qzvUy5mBZ2GGjOQNW2h/ocFqjTjOiTDMv2ONtivmM=
github.com/git-pkgs/purl v0.1.20/go.mod h1:hthV5mp+Q67HpQ9+LnRLLmsReu5ooyQ5EaJsCGrA8yE=
github.com/git-pkgs/vers v0.6.0 h1:droJw8+oSyl8/UoDj/96B9ZPggmxJDTl/JeixzfKzSc=
github.com/git-pkgs/vers v0.6.0/go.mod h1:biTbSQK1qdbrsxDEKnqe3Jzclxz8vW6uDcwKjfUGcOo=
github.com/package-url/packageurl-go v0.1.7 h1:iFWg6tzAjLA6F/qX3M5nZaiMHJgc+p2zxVyr/fY+sZY=
github.com/package-url/packageurl-go v0.1.7/go.mod h1:nKAWB8E6uk1MHqiS/lQb9pYBGH2+mdJ2PJc2s50dQY0=
go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
18 changes: 17 additions & 1 deletion parsers/swift.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ package parsers
import (
"encoding/json"
"fmt"
"net/url"
"strings"

"github.com/git-pkgs/resolve"
)

// swiftPackage represents a package in swift's JSON output.
type swiftPackage struct {
Name string `json:"name"`
URL string `json:"url"`
Version string `json:"version"`
Dependencies []swiftPackage `json:"dependencies"`
}
Expand All @@ -28,7 +31,7 @@ func walkSwiftDeps(pkgs []swiftPackage) []*resolve.Dep {
var result []*resolve.Dep
for _, pkg := range pkgs {
dep := &resolve.Dep{
PURL: resolve.MakePURL("swift", pkg.Name, pkg.Version),
PURL: swiftPURL(pkg),
Name: pkg.Name,
Version: pkg.Version,
Deps: []*resolve.Dep{},
Expand All @@ -41,6 +44,19 @@ func walkSwiftDeps(pkgs []swiftPackage) []*resolve.Dep {
return result
}

func swiftPURL(pkg swiftPackage) string {
source := pkg.URL
if strings.HasPrefix(source, "git@") {
source = "ssh://" + strings.Replace(source, ":", "/", 1)
}
u, err := url.Parse(source)
if err != nil || u.Hostname() == "" || u.Scheme == "file" {
return ""
}
name := u.Hostname() + strings.TrimSuffix(u.Path, ".git")
return resolve.MakePURL("swift", name, pkg.Version)
}

func init() {
resolve.Register("swift", "swift", parseSwift)
}
2 changes: 1 addition & 1 deletion resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,5 @@ func buildResult(manager string, parse func() ([]*Dep, error)) (*Result, error)

// MakePURL constructs a PURL string for a dependency.
func MakePURL(ecosystem, name, version string) string {
return purl.MakePURL(ecosystem, name, version).String()
return purl.MakePURLString(ecosystem, name, version)
}
43 changes: 43 additions & 0 deletions resolve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resolve_test

import (
"errors"
"fmt"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -342,6 +343,48 @@ func TestSwift(t *testing.T) {
}
}

func TestSwiftPURL(t *testing.T) {
const wantPURL = "pkg:swift/github.com/apple/swift-log@1.5.3"
tests := []struct {
name string
url string
want string
}{
{"https", "https://github.com/apple/swift-log.git", wantPURL},
{"https without suffix", "https://github.com/apple/swift-log", wantPURL},
{"ssh", "ssh://git@github.com/apple/swift-log.git", wantPURL},
{"scp", "git@github.com:apple/swift-log.git", wantPURL},
{"missing owner", "https://github.com/swift-log.git", ""},
{"missing URL", "", ""},
{"registry identity", "apple.swift-log", ""},
{"local path", "/tmp/swift-log", ""},
{"file URL", "file:///tmp/swift-log", ""},
{"invalid URL", "https://%invalid", ""},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
input := fmt.Sprintf(`{"name":"MyProject","dependencies":[{
"identity":"swift-log","name":"swift-log","url":%q,
"version":"1.5.3","dependencies":[]
}]}`, tt.url)
result, err := resolve.Parse("swift", []byte(input))
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(result.Direct) != 1 {
t.Fatalf("expected one dependency, got %+v", result)
}
dep := result.Direct[0]
if dep.PURL != tt.want {
t.Errorf("PURL = %q, want %q", dep.PURL, tt.want)
}
if dep.Name != "swift-log" || dep.Version != "1.5.3" {
t.Errorf("dependency name/version changed: %+v", dep)
}
})
}
}

func TestUV(t *testing.T) {
result, err := resolve.Parse("uv", loadFixture(t, "uv.txt"))
if err != nil {
Expand Down
Loading