|
8 | 8 |
|
9 | 9 | configv1alpha1 "github.com/padok-team/burrito/api/v1alpha1"
|
10 | 10 | "github.com/padok-team/burrito/internal/annotations"
|
| 11 | + layerCtrl "github.com/padok-team/burrito/internal/controllers/terraformlayer" |
11 | 12 | repo "github.com/padok-team/burrito/internal/repository"
|
12 | 13 | log "github.com/sirupsen/logrus"
|
13 | 14 | corev1 "k8s.io/api/core/v1"
|
@@ -136,24 +137,33 @@ func (s *SyncNeeded) getHandler() Handler {
|
136 | 137 |
|
137 | 138 | // Add annotation to trigger a sync for all layers that depend on this branch
|
138 | 139 | affectedLayers := retrieveLayersForRef(branch.Name, layers)
|
| 140 | + date := time.Now().Format(time.UnixDate) |
139 | 141 | for _, layer := range affectedLayers {
|
140 | 142 | ann := map[string]string{}
|
141 |
| - // TODO: Set LastRelevantCommit |
| 143 | + |
| 144 | + // We always set the last branch commit to the latest revision |
142 | 145 | ann[annotations.LastBranchCommit] = latestRev
|
143 |
| - // ann[annotations.LastBranchCommitDate] = date // TODO: add date |
| 146 | + ann[annotations.LastBranchCommitDate] = date |
144 | 147 |
|
145 |
| - // TODO: inspect if layer files have changed when git providers will expose a function to do so |
146 |
| - // if controller.LayerFilesHaveChanged(layer, e.Changes) { |
147 |
| - // log.Infof("layer %s is affected by push event", layer.Name) |
148 |
| - // ann[annotations.LastRelevantCommit] = e.ChangeInfo.ShaAfter |
149 |
| - // ann[annotations.LastRelevantCommitDate] = date |
150 |
| - // } |
| 148 | + if currentLastRelevant, ok := layer.Annotations[annotations.LastRelevantCommit]; !ok { |
| 149 | + // If the layer does not have a last relevant commit, we set it to the last branch commit |
| 150 | + ann[annotations.LastRelevantCommit] = latestRev |
| 151 | + ann[annotations.LastRelevantCommitDate] = date |
| 152 | + } else { |
| 153 | + // We compare the current last relevant commit with the latest revision |
| 154 | + changes := gitProvider.GetChanges(currentLastRelevant, latestRev) |
| 155 | + if layerCtrl.LayerFilesHaveChanged(layer, changes) { |
| 156 | + log.Infof("layer %s/%s is affected by new revision %s", layer.Namespace, layer.Name, latestRev) |
| 157 | + ann[annotations.LastRelevantCommit] = latestRev |
| 158 | + ann[annotations.LastRelevantCommitDate] = date |
| 159 | + } |
| 160 | + } |
151 | 161 |
|
152 | 162 | err := annotations.Add(context.TODO(), r.Client, &layer, ann)
|
153 | 163 | if err != nil {
|
154 | 164 | log.Errorf("could not add annotation to TerraformLayer %s/%s: %s", layer.Namespace, layer.Name, err)
|
155 | 165 | } else {
|
156 |
| - log.Infof("layer %s/%s annotated with new last branch commit %s", layer.Namespace, layer.Name, latestRev) |
| 166 | + log.Infof("layer %s/%s annotated with new revision %s", layer.Namespace, layer.Name, latestRev) |
157 | 167 | }
|
158 | 168 | }
|
159 | 169 | }
|
|
0 commit comments