Skip to content

Fix/GitHub deployment time calculation#8715

Merged
klesh merged 8 commits intoapache:mainfrom
Ke-vin-S:fix/github-deployment-time-calculation
Feb 26, 2026
Merged

Fix/GitHub deployment time calculation#8715
klesh merged 8 commits intoapache:mainfrom
Ke-vin-S:fix/github-deployment-time-calculation

Conversation

@Ke-vin-S
Copy link
Copy Markdown
Contributor

@Ke-vin-S Ke-vin-S commented Feb 15, 2026

Summary

Fix deployment finish time calculation in the GitHub GraphQL plugin.

Previously, DevLake used the latest deployment status timestamp (often inactive) as the deployment completion time. However, GitHub marks a deployment as inactive when it is superseded by a newer successful deployment, which may occur significantly later than the actual success event. This led to inflated deployment durations and inaccurate metrics (e.g., PR Deploy Time).

This PR introduces a new nullable field finished_date in GithubDeployment and implements success-priority logic:

  • Use the latest success status timestamp if present.
  • Otherwise, fall back to the latest terminal status timestamp.
  • During domain conversion, finished_date is used to populate TaskDatesInfo.FinishedDate and calculate deployment duration.

This ensures deployment metrics reflect the actual completion time rather than a later superseding status update.

Backward Compatibility

  • Adds a nullable finished_date field with a backward-compatible migration.
  • Preserves existing fields (LatestStatusState, LatestUpdatedDate) without changing their semantics.
  • No breaking changes.

Does this close any open issues?

Closes #8654

Introduce FinishedDate field in GithubDeployment to represent
success-priority deployment completion timestamp.

This field allows distinguishing SUCCESS timestamp from
latest status update time while preserving backward compatibility.
Add logic to derive FinishedDate from deployment statuses.

Preference order:
1. Latest SUCCESS timestamp
2. Latest terminal timestamp (FAILURE/ERROR/INACTIVE/ACTIVE)

This improves deployment lifecycle accuracy without modifying
existing LatestStatus semantics.
Update ConvertDeployment to use tool-layer FinishedDate when
populating domain TaskDatesInfo.FinishedDate.

Duration is now calculated using resolved finished time
instead of UpdatedDate.
Add migration script to auto-migrate GithubDeployment
and create nullable finished_date column.
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. component/plugins This issue or PR relates to plugins pr-type/bug-fix This PR fixes a bug priority/medium This issue is medium important severity/p1 This bug affects functionality or significantly affect ux labels Feb 15, 2026
…te and duration

Introduce adjustments to existing e2e tests to validate backward
compatibility after adding deployment finished date and duration
calculation logic.

Add `deployment_finished_date` field to `_tool_github_deployments.csv`
and `duration_seconds` field to `cicd_deployments.csv`.

Ensure historical data remains compatible with the updated behavior.
…tion calculation logic

Add test coverage for deployment finished date and duration calculation based
on the SUCCESS state  instead of relying on the inactive state.

Verify fallback behavior when a SUCCESS state is not present.
Copy link
Copy Markdown
Contributor

@klesh klesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution.
The overall idea looks solid. Please fix the linting.

func (*addFinishedDateToGithubDeployment) Up(basicRes context.BasicRes) errors.Error {
return migrationhelper.AutoMigrateTables(
basicRes,
&models.GithubDeployment{},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Referencing the active model in a migration script is incorrect because the model will change over time while the script must stay reproducible. Please define a new struct just for this script; feel free to use the other scripts as examples.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks for the explanation. I’ll update the migration

… model

Define a dedicated versioned struct for the finished_date
migration instead of referencing the evolving GithubDeployment
model to ensure deterministic and reproducible schema changes.
…ment extractor

Remove redundant restTasks alias and use githubTasks
constants consistently to resolve lint warnings and
improve import clarity.
@Ke-vin-S Ke-vin-S requested a review from klesh February 24, 2026 18:01
Copy link
Copy Markdown
Contributor

@klesh klesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for your contribution.

@klesh klesh merged commit e2f4a7a into apache:main Feb 26, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/plugins This issue or PR relates to plugins pr-type/bug-fix This PR fixes a bug priority/medium This issue is medium important severity/p1 This bug affects functionality or significantly affect ux size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug][Github] PR Deploy Time Incorrectly Calculated Using 'inactive' Status Timestamp Instead of 'success' Timestamp

2 participants