Skip to content

Commit

Permalink
fix: UNKNOWN deployment status after second sync (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
egekocabas authored Feb 3, 2025
1 parent 0d1e309 commit 1002bfc
Showing 1 changed file with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void syncDeploymentsOfRepository(
* Synchronizes deployments for a specific environment.
*
* @param ghRepository the GitHub repository
* @param environment the environment entity
* @param environment the environment entity
* @param since an optional timestamp to fetch deployments since
*/
public void syncDeploymentsOfEnvironment(
Expand All @@ -131,10 +131,22 @@ public void syncDeploymentsOfEnvironment(

while (iterator.hasNext()) {
final GitHubDeploymentDto ghDeployment = iterator.next();
// Set state as UNKNOWN as the state is not provided by the GitHub API
// We can make a separate API call to fetch the deployment state
// But that would be an overkill for now
// Webhook handler sets the state of the deployment

// The data sync fetches deployments without their state,
// as the GitHub REST API does not provide the state directly.
// This is not ideal, but it's a limitation of the API.
// To avoid making an additional API call to fetch the state,
// we set it to UNKNOWN initially.
// The state is later updated by the webhook handler during runtime.
// However, if the data sync runs again, it could overwrite the state back to UNKNOWN.
// To prevent this, we check if the deployment already exists in the database.
// If it does, we skip processing to avoid overwriting the state with UNKNOWN.
// If it doesn't, we proceed with processing the deployment.
if (deploymentRepository.existsById(ghDeployment.getId())) {
continue;
}

// Set state as UNKNOWN
final DeploymentSource deploymentSource =
deploymentSourceFactory.create(ghDeployment, Deployment.State.UNKNOWN);

Expand All @@ -159,9 +171,9 @@ public void syncDeploymentsOfEnvironment(
* repository.
*
* @param deploymentSource the source (GHDeployment or GitHubDeploymentDto) wrapped as a
* DeploymentSource
* DeploymentSource
* @param gitRepository the associated GitRepository entity
* @param environment the associated environment entity
* @param environment the associated environment entity
*/
@Transactional
void processDeployment(
Expand Down

0 comments on commit 1002bfc

Please sign in to comment.