prow/plugins/updateconfig/updateconfig.go
func FilterChanges(cfg plugins.ConfigUpdater, changes []github.PullRequestChange, log *logrus.Entry) map[ConfigMapID][]ConfigMapUpdate {
	toUpdate := map[ConfigMapID][]ConfigMapUpdate{}
	for _, change := range changes {
		var cm plugins.ConfigMapSpec
		found := false

		for key, configMap := range cfg.Maps {
			var matchErr error
			found, matchErr = zglob.Match(key, change.Filename)
			if matchErr != nil {
				// Should not happen, log matchErr and continue
				log.WithError(matchErr).Info("key matching error")
				continue
			}

			if found {
				cm = configMap
				break
			}
		}

		if !found {
			continue // This file does not define a configmap
		}

		// Yes, update the configmap with the contents of this file
		for _, ns := range append(cm.Namespaces) {
			id := ConfigMapID{Name: cm.Name, Namespace: ns}
			key := cm.Key
			if key == "" {
				key = path.Base(change.Filename)
				// if the key changed, we need to remove the old key
				if change.Status == github.PullRequestFileRenamed {
					oldKey := path.Base(change.PreviousFilename)
					// not setting the filename field will cause the key to be
					// deleted
					toUpdate[id] = append(toUpdate[id], ConfigMapUpdate{Key: oldKey})
				}
			}
			if change.Status == github.PullRequestFileRemoved {
				toUpdate[id] = append(toUpdate[id], ConfigMapUpdate{Key: key})
			} else {
				gzip := cfg.GZIP
				if cm.GZIP != nil {
					gzip = *cm.GZIP
				}
				toUpdate[id] = append(toUpdate[id], ConfigMapUpdate{Key: key, Filename: change.Filename, GZIP: gzip})
			}
		}
	}
	return toUpdate
}
func FilterChanges(cfg plugins.ConfigUpdater, changes []github.PullRequestChange, log *logrus.Entry) map[ConfigMapID][]ConfigMapUpdate {
	toUpdate := map[ConfigMapID][]ConfigMapUpdate{}
	for _, change := range changes {
		var cm plugins.ConfigMapSpec
		found := false

		for key, configMap := range cfg.Maps {
			var matchErr error
			found, matchErr = zglob.Match(key, change.Filename)
			if matchErr != nil {
				// Should not happen, log matchErr and continue
				log.WithError(matchErr).Info("key matching error")
				continue
			}

			if found {
				cm = configMap
				break
			}
		}

		if !found {
			continue // This file does not define a configmap
		}

		// Yes, update the configmap with the contents of this file
		for _, ns := range append(cm.Namespaces) {
			id := ConfigMapID{Name: cm.Name, Namespace: ns}
			key := cm.Key
			if key == "" {
				key = path.Base(change.Filename)
				// if the key changed, we need to remove the old key
				if change.Status == github.PullRequestFileRenamed {
					oldKey := path.Base(change.PreviousFilename)
					// not setting the filename field will cause the key to be
					// deleted
					toUpdate[id] = append(toUpdate[id], ConfigMapUpdate{Key: oldKey})
				}
			}
			if change.Status == github.PullRequestFileRemoved {
				toUpdate[id] = append(toUpdate[id], ConfigMapUpdate{Key: key})
			} else {
				gzip := cfg.GZIP
				if cm.GZIP != nil {
					gzip = *cm.GZIP
				}
				toUpdate[id] = append(toUpdate[id], ConfigMapUpdate{Key: key, Filename: change.Filename, GZIP: gzip})
			}
		}
	}
	return toUpdate
}
func FilterChanges ( cfg plugins . ConfigUpdater , changes [ ] github . PullRequestChange , log * logrus . Entry ) map [ ConfigMapID ] [ ] ConfigMapUpdate { toUpdate := map [ ConfigMapID ] [ ] ConfigMapUpdate { } for _ , change := range changes { var cm plugins . ConfigMapSpec found := false for key , configMap := range cfg . Maps { var matchErr error found , matchErr = zglob . Match ( key , change . Filename ) if matchErr != nil { // Should not happen, log matchErr and continue log . WithError ( matchErr ) . Info ( " " ) continue } if found { cm = configMap break } } if ! found { continue // This file does not define a configmap } // Yes, update the configmap with the contents of this file for _ , ns := range append ( cm . Namespaces ) { id := ConfigMapID { Name : cm . Name , Namespace : ns } key := cm . Key if key == " " { key = path . Base ( change . Filename ) // if the key changed, we need to remove the old key if change . Status == github . PullRequestFileRenamed { oldKey := path . Base ( change . PreviousFilename ) // not setting the filename field will cause the key to be // deleted toUpdate [ id ] = append ( toUpdate [ id ] , ConfigMapUpdate { Key : oldKey } ) } } if change . Status == github . PullRequestFileRemoved { toUpdate [ id ] = append ( toUpdate [ id ] , ConfigMapUpdate { Key : key } ) } else { gzip := cfg . GZIP if cm . GZIP != nil { gzip = * cm . GZIP } toUpdate [ id ] = append ( toUpdate [ id ] , ConfigMapUpdate { Key : key , Filename : change . Filename , GZIP : gzip } ) } } } return toUpdate }
// FilterChanges determines which of the changes are relevant for config updating, returning mapping of
// config map to key to filename to update that key from.
FilterChanges determines which of the changes are relevant for config updating returning mapping of config map to key to filename to update that key from .