Skip to content

Commit c191c15

Browse files
committed
dont approve deployments on webhook events replay
1 parent 39165c6 commit c191c15

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

server/application-server/src/main/java/de/tum/cit/aet/helios/deployment/github/GitHubDeploymentStatusMessageHandler.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import de.tum.cit.aet.helios.user.User;
1515
import de.tum.cit.aet.helios.user.github.GitHubUserSyncService;
1616
import java.io.IOException;
17+
import java.time.Instant;
1718
import java.util.Optional;
1819
import lombok.RequiredArgsConstructor;
1920
import lombok.extern.log4j.Log4j2;
@@ -41,6 +42,8 @@ public class GitHubDeploymentStatusMessageHandler
4142
private final GitHubFacade github;
4243
private final GitHubDataSyncOrchestrator gitHubDataSyncOrchestrator;
4344

45+
private final Instant applicationStartTime = Instant.now();
46+
4447
@Override
4548
protected Class<GHEventPayload.DeploymentStatus> getPayloadClass() {
4649
return GHEventPayload.DeploymentStatus.class;
@@ -141,10 +144,21 @@ protected void handleInstalledRepositoryEvent(GHEventPayload.DeploymentStatus ev
141144
deploymentSyncService.processDeployment(
142145
deploymentSource, repository, environment, convertedUser);
143146

144-
// TODO: Don't approve deployment on data sync
147+
// Auto-approve deployments in WAITING state
145148
if (deploymentSource.getState() == Deployment.State.WAITING) {
146-
log.info("Deployment is in WAITING state. Reviewing the deployment.");
147-
approvalService.reviewDeployment(deploymentSource, repository, environment, convertedUser);
149+
// Check if this is a recent event (after app startup) or an old event being replayed
150+
Instant eventTime;
151+
try {
152+
eventTime = eventPayload.getDeploymentStatus().getCreatedAt().toInstant();
153+
} catch (IOException e) {
154+
eventTime = Instant.now();
155+
}
156+
157+
// Only automatically approve if the event is recent (after application startup)
158+
if (eventTime.isAfter(applicationStartTime)) {
159+
log.info("Recent deployment in WAITING state. Reviewing the deployment.");
160+
approvalService.reviewDeployment(deploymentSource, repository, environment, convertedUser);
161+
}
148162
}
149163
}
150164
}

0 commit comments

Comments
 (0)