Skip to content

Commit

Permalink
Adds a tag if one is not present when installing a new dependency (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
ADRFranklin committed Jan 2, 2022
1 parent 55af089 commit fd1e11a
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pkgcontext/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package pkgcontext

import (
"context"
"fmt"

"github.com/google/go-github/github"
"github.com/pkg/errors"

"github.com/Southclaws/sampctl/print"
Expand All @@ -18,11 +20,24 @@ func (pcx *PackageContext) Install(
exists := false

for _, target := range targets {
_, err = target.Explode()
var meta versioning.DependencyMeta
meta, err = target.Explode()
if err != nil {
return errors.Wrapf(err, "failed to parse %s as a dependency string", target)
}

if meta.Tag == "" {
var options github.ListOptions
tags, _, err := pcx.GitHub.Repositories.ListTags(ctx, meta.User, meta.Repo, &options)
if err != nil {
return errors.Wrapf(err, "failed to get repository tags for dependency %s", target)
}

if len(tags) != 0 {
target = versioning.DependencyString(fmt.Sprintf("%s:%s", target, *tags[0].Name))
}
}

for _, dep := range pcx.Package.GetAllDependencies() {
if dep == target {
exists = true
Expand Down

0 comments on commit fd1e11a

Please sign in to comment.