func processModified()

in ci/internal/cli/mitresync.go [65:116]


func processModified(ctx context.Context, repo *git.Repository, commit string, flags *mitreSyncFlags) error {
	records, err := modifiedRecords(ctx, repo, commit)
	if err != nil {
		slog.Error("error getting modified records", "error", err)
		return err
	}

	if !flags.update {
		if len(records) > 0 {
			slog.Warn("skipping updating of modified records on MITRE", "records", records)
		}
		return nil
	}

	if len(records) == 0 {
		slog.Info("no modified records to update on MITRE")
		return nil
	}

	mitreClient, err := initMITREClient(flags)
	if err != nil {
		slog.Error("error initializing MITRE API client", "error", err)
		return fmt.Errorf("initializing MITRE API client: %w", err)
	}

	var errs error

	for i, record := range records {
		logger := slog.With("record", record, "progress", fmt.Sprintf("%d/%d", i+1, len(records)))

		published, err := mitreClient.GetRecord(ctx, record.CveMetadata.CveID)
		if err != nil {
			errs = errors.Join(errs, err)
			logger.Error("error fetching record on MITRE", "error", err)
			continue
		}

		if equalContainers(record.Containers.Cna, published.Containers.Cna) {
			logger.Info("record has no changes to CNA container; skipping")
			continue
		}

		if err := mitreClient.UpdateRecord(ctx, record.CveMetadata.CveID, &record.Containers.Cna); err != nil {
			errs = errors.Join(errs, err)
			logger.Error("error updating modified record on MITRE", "error", err)
		}

		logger.Info("updated modified record on MITRE")
	}

	return errs
}