func annotateTags()

in cmd/acr/annotate.go [153:210]


func annotateTags(ctx context.Context,
	acrClient api.AcrCLIClientInterface,
	orasClient api.ORASClientInterface,
	poolSize int,
	loginURL string,
	repoName string,
	artifactType string,
	annotations []string,
	tagFilter string,
	regexpMatchTimeoutSeconds int64,
	dryRun bool) (int, error) {

	if !dryRun {
		fmt.Printf("\nAnnotating tags for repository: %s\n", repoName)
	} else {
		fmt.Printf("\nTags for this repository would be annotated: %s\n", repoName)
	}

	tagRegex, err := common.BuildRegexFilter(tagFilter, regexpMatchTimeoutSeconds)
	if err != nil {
		return -1, err
	}

	lastTag := ""
	annotatedTagsCount := 0

	var annotator *worker.Annotator
	if !dryRun {
		// In order to only have a limited amount of http requests, an annotator is used that will start goroutines to annotate tags.
		annotator, err = worker.NewAnnotator(poolSize, orasClient, loginURL, repoName, artifactType, annotations)
		if err != nil {
			return -1, err
		}
	}

	for {
		// GetTagsToAnnotate will return an empty lastTag when there are no more tags.
		manifestsToAnnotate, newLastTag, err := getManifestsToAnnotate(ctx, acrClient, orasClient, loginURL, repoName, tagRegex, lastTag, artifactType, dryRun)
		if err != nil {
			return -1, err
		}
		lastTag = newLastTag
		if manifestsToAnnotate != nil {
			count := len(*manifestsToAnnotate)
			if !dryRun {
				_, annotateErr := annotator.Annotate(ctx, manifestsToAnnotate)
				if annotateErr != nil {
					return -1, annotateErr
				}
			}
			annotatedTagsCount += count
		}
		if len(lastTag) == 0 {
			break
		}
	}
	return annotatedTagsCount, nil
}