Skip to content

Commit

Permalink
Add AppRepoContext
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Standeren authored and Andrea Standeren committed Jan 17, 2024
1 parent cfdc3c9 commit fff397c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
12 changes: 7 additions & 5 deletions backend/src/Designer/Controllers/RepositoryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -544,10 +544,11 @@ public ActionResult Contents(string org, string repository, [FromQuery] string p
[Route("repo/{org}/{repository:regex(^(?!datamodels$)[[a-z]][[a-z0-9-]]{{1,28}}[[a-z0-9]]$)}/contents.zip")]
public ActionResult ContentsZip(string org, string repository, [FromQuery] bool full)
{
AltinnRepoContext appContext = AltinnRepoContext.FromOrgRepo(org, repository);
string appRoot;
try
{
appRoot = _repository.GetAppPath(org, repository);
appRoot = _repository.GetAppPath(appContext.Org, appContext.Repo);

if (!Directory.Exists(appRoot))
{
Expand All @@ -560,10 +561,11 @@ public ActionResult ContentsZip(string org, string repository, [FromQuery] bool
}

var zipType = full ? "full" : "changes";
var zipFileName = $"{org}-{repository}-{zipType}.zip";
var zipFilePath = Path.Combine(Path.GetTempPath(), "altinn", zipFileName);
var zipFileName = $"{appContext.Org}-{appContext.Repo}-{zipType}.zip";
var tempAltinnFolderPath = Path.Combine(Path.GetTempPath(), "altinn");
var zipFilePath = Path.Combine(tempAltinnFolderPath, zipFileName);

using (var archive = new ZipArchive(new FileStream(zipFilePath, FileMode.Create, FileAccess.ReadWrite, FileShare.Read, 512, FileOptions.DeleteOnClose), ZipArchiveMode.Create, leaveOpen: false))
using (var archive = new ZipArchive(new FileStream(zipFilePath, FileMode.Create, FileAccess.ReadWrite, FileShare.Read), ZipArchiveMode.Create, leaveOpen: false))
{
IEnumerable<string> changedFiles;
if (full)
Expand All @@ -573,7 +575,7 @@ public ActionResult ContentsZip(string org, string repository, [FromQuery] bool
else
{
changedFiles = _sourceControl
.Status(org, repository)
.Status(appContext.Org, appContext.Repo)
.Where(f => f.FileStatus != FileStatus.DeletedFromWorkdir)
.Select(f => f.FilePath);
};
Expand Down
5 changes: 5 additions & 0 deletions backend/src/Designer/Models/AltinnRepoContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,10 @@ private void ValidateOrganization(string org)
throw new ArgumentException("Provided organization name is not valid");
}
}

public static AltinnRepoContext FromOrgRepo(string org, string repo)
{
return new AltinnRepoContext(org, repo);
}
}
}

0 comments on commit fff397c

Please sign in to comment.