Prevent tagging existing remote versions.

This commit is contained in:
Marcin Bilski 2021-12-22 15:35:09 +01:00
parent e08d238243
commit 52d4a68d86
3 changed files with 21 additions and 10 deletions

View File

@ -352,7 +352,10 @@ func (api *api) tag(w http.ResponseWriter, r *http.Request, module, version stri
return
}
taggable.Tag(vcs.Version(version), req.Short)
// TODO(bilus): Response
err = taggable.Tag(r.Context(), vcs.Version(version), req.Short)
if err != nil {
api.log("api.tag", "module", module, "version", version, "error", err)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
}

View File

@ -144,10 +144,10 @@ func isVendoredPackage(name string) bool {
func (g *gitVCS) Zip(ctx context.Context, version Version) (io.ReadCloser, error) {
dirName := g.module + "@" + string(version)
return g.zipUnder(ctx, version, dirName)
return g.zipAs(ctx, version, dirName)
}
func (g *gitVCS) zipUnder(ctx context.Context, version Version, dirName string) (io.ReadCloser, error) {
func (g *gitVCS) zipAs(ctx context.Context, version Version, dirName string) (io.ReadCloser, error) {
g.log("gitVCS.Zip", "module", g.module, "version", version)
ci, err := g.commit(ctx, version)
if err != nil {

View File

@ -22,7 +22,7 @@ func NewEphemeralTagStorage() *EphemeralTagStorage {
}
}
func (s *EphemeralTagStorage) Tag(module string, semVer Version, short string) {
func (s *EphemeralTagStorage) Tag(module string, semVer Version, short string) error {
tags := s.tagsByModule[module]
tmp := tags[:0]
for _, t := range tags {
@ -31,6 +31,7 @@ func (s *EphemeralTagStorage) Tag(module string, semVer Version, short string) {
}
}
s.tagsByModule[module] = append(tmp, ephemeralTag{semVer, short})
return nil
}
func (s *EphemeralTagStorage) tags(module string) []ephemeralTag {
@ -46,7 +47,7 @@ type taggableVCS struct {
}
type Taggable interface {
Tag(semVer Version, short string)
Tag(ctx context.Context, semVer Version, short string) error
}
// NewGitWithEphemeralTags return a go-git VCS client implementation that
@ -61,8 +62,15 @@ func NewGitWithEphemeralTags(l logger, dir string, module string, auth Auth, sto
}
}
func (v *taggableVCS) Tag(semVer Version, short string) {
v.storage.Tag(v.module, semVer, short)
func (v *taggableVCS) Tag(ctx context.Context, semVer Version, short string) error {
remoteVersions, err := v.wrapped.List(ctx)
if err != nil {
return err
}
if versionExists(remoteVersions, semVer) {
return fmt.Errorf("remote version %s already exists for module %s", semVer, v.module)
}
return v.storage.Tag(v.module, semVer, short)
}
func (v *taggableVCS) List(ctx context.Context) ([]Version, error) {
@ -110,7 +118,7 @@ func (v *taggableVCS) Zip(ctx context.Context, version Version) (io.ReadCloser,
}
// Zip must contain the ephemeral version.
dirName := v.module + "@" + string(version)
return v.wrapped.zipUnder(ctx, version2, dirName)
return v.wrapped.zipAs(ctx, version2, dirName)
}
func (v *taggableVCS) resolveVersion(ctx context.Context, version Version) (Version, error) {