Prevent tagging existing remote versions.
This commit is contained in:
parent
e08d238243
commit
52d4a68d86
@ -352,7 +352,10 @@ func (api *api) tag(w http.ResponseWriter, r *http.Request, module, version stri
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
taggable.Tag(vcs.Version(version), req.Short)
|
err = taggable.Tag(r.Context(), vcs.Version(version), req.Short)
|
||||||
|
if err != nil {
|
||||||
// TODO(bilus): Response
|
api.log("api.tag", "module", module, "version", version, "error", err)
|
||||||
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,10 +144,10 @@ func isVendoredPackage(name string) bool {
|
|||||||
|
|
||||||
func (g *gitVCS) Zip(ctx context.Context, version Version) (io.ReadCloser, error) {
|
func (g *gitVCS) Zip(ctx context.Context, version Version) (io.ReadCloser, error) {
|
||||||
dirName := g.module + "@" + string(version)
|
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)
|
g.log("gitVCS.Zip", "module", g.module, "version", version)
|
||||||
ci, err := g.commit(ctx, version)
|
ci, err := g.commit(ctx, version)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -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]
|
tags := s.tagsByModule[module]
|
||||||
tmp := tags[:0]
|
tmp := tags[:0]
|
||||||
for _, t := range tags {
|
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})
|
s.tagsByModule[module] = append(tmp, ephemeralTag{semVer, short})
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *EphemeralTagStorage) tags(module string) []ephemeralTag {
|
func (s *EphemeralTagStorage) tags(module string) []ephemeralTag {
|
||||||
@ -46,7 +47,7 @@ type taggableVCS struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Taggable interface {
|
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
|
// 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) {
|
func (v *taggableVCS) Tag(ctx context.Context, semVer Version, short string) error {
|
||||||
v.storage.Tag(v.module, semVer, short)
|
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) {
|
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.
|
// Zip must contain the ephemeral version.
|
||||||
dirName := v.module + "@" + string(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) {
|
func (v *taggableVCS) resolveVersion(ctx context.Context, version Version) (Version, error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user