mirror of
https://github.com/crazy-max/diun.git
synced 2026-01-04 20:15:01 +01:00
Add option to set the maximum number of tags to watch for an item if watch_repo is enabled
This commit is contained in:
@@ -8,20 +8,30 @@ import (
|
||||
type Tags []string
|
||||
|
||||
// Tags returns tags of a Docker repository
|
||||
func (c *RegistryClient) Tags(image registry.Image) (Tags, error) {
|
||||
func (c *RegistryClient) Tags(image registry.Image, max int) (Tags, int, error) {
|
||||
ctx, cancel := c.timeoutContext()
|
||||
defer cancel()
|
||||
|
||||
imgCls, err := c.newImage(ctx, image.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, 0, err
|
||||
}
|
||||
defer imgCls.Close()
|
||||
|
||||
tags, err := docker.GetRepositoryTags(ctx, c.sysCtx, imgCls.Reference())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return Tags(tags), err
|
||||
// Reverse order (latest tags first)
|
||||
for i := len(tags)/2 - 1; i >= 0; i-- {
|
||||
opp := len(tags) - 1 - i
|
||||
tags[i], tags[opp] = tags[opp], tags[i]
|
||||
}
|
||||
|
||||
if max > 0 && len(tags) >= max {
|
||||
return Tags(tags[:max]), len(tags), nil
|
||||
}
|
||||
|
||||
return Tags(tags), len(tags), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user