Skip to content

Commit

Permalink
Fix after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
miguel-crespo-fdc committed Oct 22, 2024
1 parent a925b0f commit ce5a86d
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 510 deletions.
1 change: 0 additions & 1 deletion pkg/api/v1/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,6 @@ message OverviewApplication {
}

message GetOverviewResponse {
map<string, Application> applications = 2;
repeated EnvironmentGroup environment_groups = 3;
string git_revision = 4;
string branch = 5;
Expand Down
6 changes: 1 addition & 5 deletions pkg/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -1120,10 +1120,7 @@ func (h *DBHandler) DBInsertRelease(ctx context.Context, transaction *sql.Tx, re
previousEslVersion+1,
err)
}
err = h.UpdateOverviewRelease(ctx, transaction, release)
if err != nil {
return err
}

logger.FromContext(ctx).Sugar().Infof(
"inserted release: app '%s' and version '%v' and eslVersion %v",
release.App,
Expand Down Expand Up @@ -5664,7 +5661,6 @@ func (h *DBHandler) ReadLatestOverviewCache(ctx context.Context, transaction *sq
result := &api.GetOverviewResponse{
Branch: "",
ManifestRepoUrl: "",
Applications: map[string]*api.Application{},
LightweightApps: []*api.OverviewApplication{},
EnvironmentGroups: []*api.EnvironmentGroup{},
GitRevision: "",
Expand Down
70 changes: 1 addition & 69 deletions pkg/db/overview.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,79 +228,11 @@ func (h *DBHandler) UpdateOverviewApplicationLock(ctx context.Context, transacti
return nil
}

func (h *DBHandler) UpdateOverviewRelease(ctx context.Context, transaction *sql.Tx, release DBReleaseWithMetaData) error {
latestOverview, err := h.ReadLatestOverviewCache(ctx, transaction)
if err != nil {
return err
}
if h.IsOverviewEmpty(latestOverview) {
return nil
}
app := getApplicationByName(latestOverview.Applications, release.App)
if app == nil {
if release.Deleted {
return nil
}
selectApp, err := h.DBSelectApp(ctx, transaction, release.App)
if err != nil {
return fmt.Errorf("could not find application '%s' in apps table, got an error: %w", release.App, err)
}
if selectApp == nil {
return fmt.Errorf("could not find application '%s' in apps table: got no result", release.App)
}
app = &api.Application{
Name: release.App,
Releases: []*api.Release{},
SourceRepoUrl: "", // TODO
Team: selectApp.Metadata.Team,
UndeploySummary: 0,
Warnings: []*api.Warning{},
}
latestOverview.Applications[release.App] = app
}
apiRelease := &api.Release{
PrNumber: extractPrNumber(release.Metadata.SourceMessage),
Version: release.ReleaseNumber,
UndeployVersion: release.Metadata.UndeployVersion,
SourceAuthor: release.Metadata.SourceAuthor,
SourceCommitId: release.Metadata.SourceCommitId,
SourceMessage: release.Metadata.SourceMessage,
CreatedAt: timestamppb.New(release.Created),
DisplayVersion: release.Metadata.DisplayVersion,
IsMinor: release.Metadata.IsMinor,
IsPrepublish: release.Metadata.IsPrepublish,
}
foundRelease := false
for relIndex, currentRelease := range app.Releases {
if currentRelease.Version == release.ReleaseNumber {
if release.Deleted {
app.Releases = append(app.Releases[:relIndex], app.Releases[relIndex+1:]...)
} else {
app.Releases[relIndex] = apiRelease
}
foundRelease = true
}
}
if !foundRelease && !release.Deleted {
app.Releases = append(app.Releases, apiRelease)
}

if release.Metadata.UndeployVersion {
app.UndeploySummary = deriveUndeploySummary(app.Name, latestOverview.EnvironmentGroups)
}

err = h.WriteOverviewCache(ctx, transaction, latestOverview)
if err != nil {
return err
}
return nil
}

func (h *DBHandler) IsOverviewEmpty(overviewResp *api.GetOverviewResponse) bool {
if overviewResp == nil {
return true
}
if len(overviewResp.Applications) == 0 && len(overviewResp.EnvironmentGroups) == 0 && overviewResp.GitRevision == "" {
if len(overviewResp.EnvironmentGroups) == 0 && overviewResp.GitRevision == "" {
return true
}
return false
Expand Down
Loading

0 comments on commit ce5a86d

Please sign in to comment.