Skip to content

Commit

Permalink
Merge pull request #16 from serpent-os/forced-uri-updates
Browse files Browse the repository at this point in the history
fixtures: Forcibly sync the URIs from fixtures when changed
  • Loading branch information
ikeycode authored Dec 5, 2024
2 parents 4f44545 + 497836b commit d4c78d5
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
16 changes: 16 additions & 0 deletions source/summit/fixtures.d
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ static void loadFixtures(ServiceContext context, ProjectManager projectManager)
auto l = project.bySlug(repo.name);
if (l !is null)
{
// Check if URI needs updating
if (l.model.originURI != repo.uri)
{
auto m = l.model;
m.originURI = repo.uri;
immutable err = project.updateRepository(m);
enforceHTTP(err.isNull, HTTPStatus.internalServerError, err.message);
}
continue;
}
Repository r;
Expand All @@ -105,6 +113,14 @@ static void loadFixtures(ServiceContext context, ProjectManager projectManager)
auto l = project.profile(profile.name);
if (l !is null)
{
// Check if URI needs updating
if (l.profile.volatileIndexURI != profile.indexURI)
{
auto m = l.profile;
m.volatileIndexURI = profile.indexURI;
immutable err = project.updateProfile(m);
enforceHTTP(err.isNull, HTTPStatus.internalServerError, err.message);
}
continue;
}

Expand Down
60 changes: 58 additions & 2 deletions source/summit/projects/project.d
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public final class ManagedProject
{
@disable this();

/**
/**
* Construct a new ManagedProject
*
* Params:
Expand Down Expand Up @@ -75,7 +75,7 @@ public final class ManagedProject
return managedProfiles.values;
}

/**
/**
* Returns: Repository within this project
*
* Params:
Expand Down Expand Up @@ -160,6 +160,34 @@ public final class ManagedProject
f.message)));
}

/**
* Update a repository in this project
*
* Params:
* model = Input model
* Returns: Nullable database error
*/
DatabaseResult updateRepository(Repository model) @safe
{
/* Try to store the model */
immutable err = context.appDB.update((scope tx) => model.save(tx));
if (!err.isNull)
{
return err;
}

/* Get it managed */
auto managedRepository = managedRepos.get(model.name, null);
if (managedRepository is null)
{
return DatabaseResult(DatabaseError(DatabaseErrorCode.BucketNotFound,
"Repository not found"));
}

runTask({ managedRepository.refresh(); });
return NoDatabaseError;
}

/**
* Add a profile to this project
*
Expand Down Expand Up @@ -193,6 +221,34 @@ public final class ManagedProject
f.message)));
}

/**
* Update a profile in this project
*
* Params:
* model = Input model
* Returns: Nullable database error
*/
DatabaseResult updateProfile(Profile model) @safe
{
/* Try to store the model */
immutable err = context.appDB.update((scope tx) => model.save(tx));
if (!err.isNull)
{
return err;
}

/* Get it managed */
auto managedProfile = managedProfiles.get(model.name, null);
if (managedProfile is null)
{
return DatabaseResult(DatabaseError(DatabaseErrorCode.BucketNotFound,
"Profile not found"));
}

runTask({ managedProfile.refresh(); });
return NoDatabaseError;
}

package:

/**
Expand Down

0 comments on commit d4c78d5

Please sign in to comment.