func annotateUntaggedManifests()

in cmd/acr/annotate.go [274:314]


func annotateUntaggedManifests(ctx context.Context,
	acrClient api.AcrCLIClientInterface,
	orasClient api.ORASClientInterface,
	poolSize int, loginURL string,
	repoName string, artifactType string,
	annotations []string,
	dryRun bool) (int, error) {
	if !dryRun {
		fmt.Printf("Annotating manifests for repository: %s\n", repoName)
	} else {
		fmt.Printf("Manifests for this repository would be annotated: %s\n", repoName)
	}

	// Contrary to getTagsToAnnotate, getManifests gets all the manifests at once.
	// This was done because if there is a manifest that has no tag but is referenced by a multiarch manifest that has tags then it
	// should not be annotated.
	manifestsToAnnotate, err := common.GetUntaggedManifests(ctx, acrClient, loginURL, repoName, dryRun, false)
	if err != nil {
		return -1, err
	}

	var annotator *worker.Annotator
	annotatedManifestsCount := 0
	if !dryRun {
		// In order to only have a limited amount of http requests, an annotator is used that will start goroutines to annotate manifests.
		annotator, err = worker.NewAnnotator(poolSize, orasClient, loginURL, repoName, artifactType, annotations)
		if err != nil {
			return -1, err
		}
		manifestsCount, annotateErr := annotator.Annotate(ctx, manifestsToAnnotate)
		if annotateErr != nil {
			return manifestsCount, annotateErr
		}
		annotatedManifestsCount += manifestsCount
	} else {
		annotatedManifestsCount = len(*manifestsToAnnotate)
	}

	return annotatedManifestsCount, nil

}