|  | @@ -44,6 +44,13 @@ func HandlePush(payload interface{}, header webhooks.Header) {
 | 
	
		
			
			| 44 | 44 |  		return
 | 
	
		
			
			| 45 | 45 |  	}
 | 
	
		
			
			| 46 | 46 |  
 | 
	
		
			
			|  | 47 | +	// Files to push are stored in a map before being pushed to the Grafana API.
 | 
	
		
			
			|  | 48 | +	// We don't push them in the loop iterating over commits because, in the
 | 
	
		
			
			|  | 49 | +	// case a file is successively updated by two commits pushed at the same
 | 
	
		
			
			|  | 50 | +	// time, it would push the same file several time, which isn't an optimised
 | 
	
		
			
			|  | 51 | +	// behaviour.
 | 
	
		
			
			|  | 52 | +	filesToPush := make(map[string]bool)
 | 
	
		
			
			|  | 53 | +
 | 
	
		
			
			| 47 | 54 |  	// Iterate over the commits descriptions from the payload
 | 
	
		
			
			| 48 | 55 |  	for _, commit := range pl.Commits {
 | 
	
		
			
			| 49 | 56 |  		// We don't want to process commits made by the puller
 | 
	
	
		
			
			|  | @@ -53,21 +60,24 @@ func HandlePush(payload interface{}, header webhooks.Header) {
 | 
	
		
			
			| 53 | 60 |  
 | 
	
		
			
			| 54 | 61 |  		// Push all added files
 | 
	
		
			
			| 55 | 62 |  		for _, addedFile := range commit.Added {
 | 
	
		
			
			| 56 |  | -			if err = pushFile(addedFile); err != nil {
 | 
	
		
			
			| 57 |  | -				panic(err)
 | 
	
		
			
			| 58 |  | -			}
 | 
	
		
			
			|  | 63 | +			filesToPush[addedFile] = true
 | 
	
		
			
			| 59 | 64 |  		}
 | 
	
		
			
			| 60 | 65 |  
 | 
	
		
			
			| 61 | 66 |  		// Push all modified files
 | 
	
		
			
			| 62 | 67 |  		for _, modifiedFile := range commit.Modified {
 | 
	
		
			
			| 63 |  | -			if err = pushFile(modifiedFile); err != nil {
 | 
	
		
			
			| 64 |  | -				panic(err)
 | 
	
		
			
			| 65 |  | -			}
 | 
	
		
			
			|  | 68 | +			filesToPush[modifiedFile] = true
 | 
	
		
			
			| 66 | 69 |  		}
 | 
	
		
			
			| 67 | 70 |  
 | 
	
		
			
			| 68 | 71 |  		// TODO: Remove a dashboard when its file gets deleted?
 | 
	
		
			
			| 69 | 72 |  	}
 | 
	
		
			
			| 70 | 73 |  
 | 
	
		
			
			|  | 74 | +	// Push all files to the Grafana API
 | 
	
		
			
			|  | 75 | +	for fileToPush := range filesToPush {
 | 
	
		
			
			|  | 76 | +		if err = pushFile(fileToPush); err != nil {
 | 
	
		
			
			|  | 77 | +			panic(err)
 | 
	
		
			
			|  | 78 | +		}
 | 
	
		
			
			|  | 79 | +	}
 | 
	
		
			
			|  | 80 | +
 | 
	
		
			
			| 71 | 81 |  	// Grafana will auto-update the version number after we pushed the new
 | 
	
		
			
			| 72 | 82 |  	// dashboards, so we use the puller mechanic to pull the updated numbers and
 | 
	
		
			
			| 73 | 83 |  	// commit them in the git repo.
 |