Update+bugfix

This commit is contained in:
Laura Hausmann 2020-06-25 22:25:11 +02:00
parent 1d49bd6ef3
commit 6ca140cbbd
Signed by: zotan
GPG key ID: 5EC1D38FFC321311
6 changed files with 445 additions and 498 deletions

View file

@ -1,4 +1,5 @@
@page @page
@using System.Web
@model IndexModel @model IndexModel
@{ @{
ViewData["Title"] = "Builds"; ViewData["Title"] = "Builds";
@ -40,7 +41,7 @@
} }
@if (System.IO.File.Exists(System.IO.Path.Combine(Program.Repo._pkgpath, p.Name, "buildlog.txt"))) @if (System.IO.File.Exists(System.IO.Path.Combine(Program.Repo._pkgpath, p.Name, "buildlog.txt")))
{ {
<td><a role="button" class="btn btn-sm btn-info" target="_blank" href="/Log?package=@p.Name">View Build log</a></td> <td><a role="button" class="btn btn-sm btn-info" target="_blank" href="/Log?package=@HttpUtility.UrlEncode(p.Name)">View Build log</a></td>
} }
else else
{ {

View file

@ -6,45 +6,39 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore; using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace repomgr namespace repomgr {
{ public static class Program {
public static class Program
{
public static RepoMgr Repo; public static RepoMgr Repo;
public static void Main(string[] args) public static void Main(string[] args) {
{ if (File.Exists("/tmp/repomgr.lock") && args[1] != "daemon") {
if (File.Exists("/tmp/repomgr.lock") && args[1] != "daemon")
{
Console.WriteLine("/tmp/repomgr.lock exists, delete it if you are sure no other process is running"); Console.WriteLine("/tmp/repomgr.lock exists, delete it if you are sure no other process is running");
Environment.Exit(1); Environment.Exit(1);
} }
else if (args[1] != "daemon") else if (args[1] != "daemon") {
{
File.Create("/tmp/repomgr.lock"); File.Create("/tmp/repomgr.lock");
} }
if (args.Length < 2 || args[1].Equals("help")) if (args.Length < 2 || args[1].Equals("help"))
PrintHelp(); PrintHelp();
Repo = new RepoMgr(args[0]); Repo = new RepoMgr(args[0]);
if (File.Exists(Path.Combine(args[0], "repomgr.index.json"))) if (File.Exists(Path.Combine(args[0], "repomgr.index.json")))
Repo.ReadIndex(); Repo.ReadIndex();
switch (args[1]) switch (args[1]) {
{
case "daemon": case "daemon":
CreateWebHostBuilder(args).Build().Run(); CreateHostBuilder(args).Build().Run();
break; break;
case "init": case "init":
if (args.Length != 4) if (args.Length != 4)
PrintHelp(); PrintHelp();
try try {
{
Repo.Init(args[2], args[3]); Repo.Init(args[2], args[3]);
} }
catch (Exception e) catch (Exception e) {
{
Console.WriteLine("Init failed with error: " + e); Console.WriteLine("Init failed with error: " + e);
} }
@ -52,12 +46,10 @@ namespace repomgr
case "add": case "add":
if (args.Length != 3) if (args.Length != 3)
PrintHelp(); PrintHelp();
try try {
{
Repo.Add(args[2]); Repo.Add(args[2]);
} }
catch (Exception e) catch (Exception e) {
{
Console.WriteLine("Add failed with error: " + e); Console.WriteLine("Add failed with error: " + e);
} }
@ -65,10 +57,8 @@ namespace repomgr
case "update": case "update":
if (args.Length < 3 || args.Length > 4) if (args.Length < 3 || args.Length > 4)
PrintHelp(); PrintHelp();
try try {
{ switch (args.Length) {
switch (args.Length)
{
case 3: case 3:
Repo.Build(args[2]); Repo.Build(args[2]);
break; break;
@ -80,8 +70,7 @@ namespace repomgr
break; break;
} }
} }
catch (Exception e) catch (Exception e) {
{
Console.WriteLine("Build failed with error: " + e); Console.WriteLine("Build failed with error: " + e);
} }
@ -89,12 +78,10 @@ namespace repomgr
case "update-all": case "update-all":
if (args.Length != 2) if (args.Length != 2)
PrintHelp(); PrintHelp();
try try {
{
Repo.BuildAll(); Repo.BuildAll();
} }
catch (Exception e) catch (Exception e) {
{
Console.WriteLine("BuildAll failed with error: " + e); Console.WriteLine("BuildAll failed with error: " + e);
} }
@ -102,12 +89,10 @@ namespace repomgr
case "remove": case "remove":
if (args.Length != 3) if (args.Length != 3)
PrintHelp(); PrintHelp();
try try {
{
Repo.Remove(args[2]); Repo.Remove(args[2]);
} }
catch (Exception e) catch (Exception e) {
{
Console.WriteLine("Remove failed with error: " + e); Console.WriteLine("Remove failed with error: " + e);
} }
@ -115,12 +100,10 @@ namespace repomgr
case "list": case "list":
if (args.Length != 2) if (args.Length != 2)
PrintHelp(); PrintHelp();
try try {
{
Repo.List(); Repo.List();
} }
catch (Exception e) catch (Exception e) {
{
Console.WriteLine("List failed with error " + e); Console.WriteLine("List failed with error " + e);
} }
@ -129,12 +112,12 @@ namespace repomgr
PrintHelp(); PrintHelp();
break; break;
} }
if (File.Exists("/tmp/repomgr.lock")) if (File.Exists("/tmp/repomgr.lock"))
File.Delete("/tmp/repomgr.lock"); File.Delete("/tmp/repomgr.lock");
} }
private static void PrintHelp() private static void PrintHelp() {
{
//TODO: add/remove <package> [...] //TODO: add/remove <package> [...]
Console.WriteLine("Usage:"); Console.WriteLine("Usage:");
Console.WriteLine("repomgr <data-path> init <repo-path> <reponame>"); Console.WriteLine("repomgr <data-path> init <repo-path> <reponame>");
@ -146,8 +129,7 @@ namespace repomgr
Console.WriteLine("repomgr <data-path> daemon"); Console.WriteLine("repomgr <data-path> daemon");
} }
private static IWebHostBuilder CreateWebHostBuilder(string[] args) => public static IHostBuilder CreateHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args) Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
.UseStartup<Startup>();
} }
} }

View file

@ -6,12 +6,9 @@ using System.Linq;
using LibGit2Sharp; using LibGit2Sharp;
using System.Diagnostics; using System.Diagnostics;
namespace repomgr namespace repomgr {
{ public class RepoMgr {
public class RepoMgr public RepoMgr(string buildpath) {
{
public RepoMgr(string buildpath)
{
_buildpath = Path.GetFullPath(buildpath); _buildpath = Path.GetFullPath(buildpath);
_pkgpath = Path.Combine(_buildpath, "pkg"); _pkgpath = Path.Combine(_buildpath, "pkg");
} }
@ -19,48 +16,41 @@ namespace repomgr
public readonly string _buildpath; public readonly string _buildpath;
public readonly string _pkgpath; public readonly string _pkgpath;
public Repository _repo; public Repository _repo;
public void Init(string repopath, string reponame)
{ public void Init(string repopath, string reponame) {
_repo = new Repository(repopath, reponame); _repo = new Repository(repopath, reponame);
if (!Directory.Exists(repopath)) if (!Directory.Exists(repopath))
Directory.CreateDirectory(repopath); Directory.CreateDirectory(repopath);
WriteIndex(); WriteIndex();
Console.WriteLine("Initialized."); Console.WriteLine("Initialized.");
} }
public void Add(string package)
{ public void Add(string package) {
Package pkg; Package pkg;
if (Directory.Exists(Path.Combine(_pkgpath, package))) if (Directory.Exists(Path.Combine(_pkgpath, package))) {
{ if (_repo.Packages.Find(p => p.Name.Equals(package)) != null) {
if (_repo.Packages.Find(p => p.Name.Equals(package)) != null)
{
Console.WriteLine("Package already exists."); Console.WriteLine("Package already exists.");
return; return;
} }
if (!CheckPackage(package)) if (!CheckPackage(package)) {
{
throw new Exception("Package directory exists but is invalid (PKGBUILD or .git missing)"); throw new Exception("Package directory exists but is invalid (PKGBUILD or .git missing)");
} }
pkg = new Package(package); pkg = new Package(package);
} }
else else {
{
if (_repo.Packages.Find(p => p.Name.Equals(package)) != null) if (_repo.Packages.Find(p => p.Name.Equals(package)) != null)
_repo.Packages.RemoveAll(p => p.Name.Equals(package)); _repo.Packages.RemoveAll(p => p.Name.Equals(package));
try try {
{
var refcount = LibGit2Sharp.Repository.ListRemoteReferences($"https://aur.archlinux.org/{package}.git").Count(); var refcount = LibGit2Sharp.Repository.ListRemoteReferences($"https://aur.archlinux.org/{package}.git").Count();
if (refcount < 1) if (refcount < 1) {
{
throw new Exception("git clone failed: Package doesn't exist in remote"); throw new Exception("git clone failed: Package doesn't exist in remote");
} }
LibGit2Sharp.Repository.Clone($"https://aur.archlinux.org/{package}.git", LibGit2Sharp.Repository.Clone($"https://aur.archlinux.org/{package}.git", Path.Combine(_pkgpath, package));
Path.Combine(_pkgpath, package));
} }
catch (Exception e) catch (Exception e) {
{
throw new Exception($"Error during clone: {e}"); throw new Exception($"Error during clone: {e}");
} }
@ -71,8 +61,8 @@ namespace repomgr
_repo.Packages.Add(pkg); _repo.Packages.Add(pkg);
WriteIndex(); WriteIndex();
} }
private void Build(Package package, bool force = false)
{ private void Build(Package package, bool force = false) {
if (UpdateAvailable(package)) if (UpdateAvailable(package))
UpdatePackage(package); UpdatePackage(package);
if (File.ReadAllText(Path.Combine(_pkgpath, package.Name, "PKGBUILD")).Contains("pkgver()")) if (File.ReadAllText(Path.Combine(_pkgpath, package.Name, "PKGBUILD")).Contains("pkgver()"))
@ -83,63 +73,59 @@ namespace repomgr
Shell.Exec("makepkg -Ccsf --sign --noconfirm 2>&1| tee buildlog.txt", Path.Combine(_pkgpath, package.Name)); Shell.Exec("makepkg -Ccsf --sign --noconfirm 2>&1| tee buildlog.txt", Path.Combine(_pkgpath, package.Name));
else if (package.CurrentVersion != package.RepoVersion) else if (package.CurrentVersion != package.RepoVersion)
Shell.Exec("makepkg -Ccs --sign --noconfirm 2>&1| tee buildlog.txt", Path.Combine(_pkgpath, package.Name)); Shell.Exec("makepkg -Ccs --sign --noconfirm 2>&1| tee buildlog.txt", Path.Combine(_pkgpath, package.Name));
else return; else
return;
var resultingPackages = Directory var resultingPackages = Directory.GetFiles(Path.Combine(_pkgpath, package.Name), "*.pkg.tar*");
.GetFiles(Path.Combine(_pkgpath, package.Name), "*.pkg.tar*"); if (resultingPackages.Length < 1) {
if (resultingPackages.Length < 1)
{
package.LastBuildSucceeded = false; package.LastBuildSucceeded = false;
throw new Exception("makepkg didn't build any package"); throw new Exception("makepkg didn't build any package");
} }
package.LastBuildSucceeded = true; package.LastBuildSucceeded = true;
if (package.PkgFiles.Any()) if (package.PkgFiles.Any()) {
{
foreach (var pkgFile in package.PkgFiles) foreach (var pkgFile in package.PkgFiles)
if (File.Exists(Path.Combine(_repo.Path, pkgFile))) if (File.Exists(Path.Combine(_repo.Path, pkgFile)))
File.Delete(Path.Combine(_repo.Path, pkgFile)); File.Delete(Path.Combine(_repo.Path, pkgFile));
package.PkgFiles.Clear(); package.PkgFiles.Clear();
} }
foreach (var resultingPackage in resultingPackages.Where(p => p.EndsWith(".sig"))) foreach (var resultingPackage in resultingPackages.Where(p => p.EndsWith(".sig"))) {
{
File.Copy(resultingPackage, Path.Combine(_repo.Path, Path.GetFileName(resultingPackage)), true); File.Copy(resultingPackage, Path.Combine(_repo.Path, Path.GetFileName(resultingPackage)), true);
File.Delete(resultingPackage); File.Delete(resultingPackage);
package.PkgFiles.Add(Path.GetFileName(resultingPackage)); package.PkgFiles.Add(Path.GetFileName(resultingPackage));
} }
foreach (var resultingPackage in resultingPackages.Where(p => !p.EndsWith(".sig"))) foreach (var resultingPackage in resultingPackages.Where(p => !p.EndsWith(".sig"))) {
{
File.Copy(resultingPackage, Path.Combine(_repo.Path, Path.GetFileName(resultingPackage)), true); File.Copy(resultingPackage, Path.Combine(_repo.Path, Path.GetFileName(resultingPackage)), true);
File.Delete(resultingPackage); File.Delete(resultingPackage);
package.PkgFiles.Add(Path.GetFileName(resultingPackage)); package.PkgFiles.Add(Path.GetFileName(resultingPackage));
Shell.Exec($"repo-add --remove --sign {_repo.Name}.db.tar.gz {Path.GetFileName(resultingPackage)}", _repo.Path); Shell.Exec($"repo-add --remove --sign {_repo.Name}.db.tar.gz {Path.GetFileName(resultingPackage)}", _repo.Path);
} }
package.RepoVersion = package.CurrentVersion; package.RepoVersion = package.CurrentVersion;
WriteIndex(); WriteIndex();
} }
private void Remove(Package package)
{ private void Remove(Package package) {
var packageDir = Path.Combine(_pkgpath, package.Name); var packageDir = Path.Combine(_pkgpath, package.Name);
if (Directory.Exists(packageDir)) if (Directory.Exists(packageDir))
Directory.Delete(packageDir, true); Directory.Delete(packageDir, true);
Shell.Exec($"repo-remove --sign {_repo.Name}.db.tar.gz {package.Name}", _repo.Path); Shell.Exec($"repo-remove --sign {_repo.Name}.db.tar.gz {package.Name}", _repo.Path);
if (package.PkgFiles.Any()) if (package.PkgFiles.Any()) {
{
foreach (var pkgFile in package.PkgFiles) foreach (var pkgFile in package.PkgFiles)
if (File.Exists(Path.Combine(_repo.Path, pkgFile))) if (File.Exists(Path.Combine(_repo.Path, pkgFile)))
File.Delete(Path.Combine(_repo.Path, pkgFile)); File.Delete(Path.Combine(_repo.Path, pkgFile));
package.PkgFiles.Clear(); package.PkgFiles.Clear();
} }
_repo.Packages.Remove(package); _repo.Packages.Remove(package);
WriteIndex(); WriteIndex();
} }
public void List()
{ public void List() {
Console.WriteLine(Shell.Yellow($"{Shell.Bold(_repo.Name)} ({_repo.Packages.Count} packages):")); Console.WriteLine(Shell.Yellow($"{Shell.Bold(_repo.Name)} ({_repo.Packages.Count} packages):"));
foreach (var package in _repo.Packages.OrderBy(p => p.Name)) foreach (var package in _repo.Packages.OrderBy(p => p.Name)) {
{
var line = $"{Shell.Bold(package.Name)}"; var line = $"{Shell.Bold(package.Name)}";
if (package.RepoVersion != package.CurrentVersion) if (package.RepoVersion != package.CurrentVersion)
line += $" ({Shell.Red(package.RepoVersion)} {Shell.Gray("->")} {Shell.Yellow(package.CurrentVersion)})"; line += $" ({Shell.Red(package.RepoVersion)} {Shell.Gray("->")} {Shell.Yellow(package.CurrentVersion)})";
@ -154,105 +140,96 @@ namespace repomgr
} }
// util stuff // util stuff
private Package GetPackage(string package) private Package GetPackage(string package) {
{
var pkg = _repo.Packages.FirstOrDefault(p => p.Name.Equals(package)); var pkg = _repo.Packages.FirstOrDefault(p => p.Name.Equals(package));
if (pkg != null) return pkg; if (pkg != null)
return pkg;
throw new Exception("Package not found."); throw new Exception("Package not found.");
} }
// git fetch, returns true if differences between origin/master and master found // git fetch, returns true if differences between origin/master and master found
private bool UpdateAvailable(Package package) private bool UpdateAvailable(Package package) {
{
var repo = new LibGit2Sharp.Repository(Path.Combine(_pkgpath, package.Name)); var repo = new LibGit2Sharp.Repository(Path.Combine(_pkgpath, package.Name));
var remote = repo.Network.Remotes["origin"]; var remote = repo.Network.Remotes["origin"];
var refSpecs = remote.FetchRefSpecs.Select(x => x.Specification); var refSpecs = remote.FetchRefSpecs.Select(x => x.Specification);
Commands.Fetch(repo, remote.Name, refSpecs, null, null); Commands.Fetch(repo, remote.Name, refSpecs, null, null);
return repo.Diff.Compare<TreeChanges>(repo.Branches["origin/master"].Tip.Tree, return repo.Diff.Compare<TreeChanges>(repo.Branches["origin/master"].Tip.Tree, DiffTargets.Index | DiffTargets.WorkingDirectory).Any();
DiffTargets.Index | DiffTargets.WorkingDirectory).Any();
} }
// resets master to origin/master // resets master to origin/master
private void UpdatePackage(Package package) private void UpdatePackage(Package package) {
{
var repo = new LibGit2Sharp.Repository(Path.Combine(_pkgpath, package.Name)); var repo = new LibGit2Sharp.Repository(Path.Combine(_pkgpath, package.Name));
var originMaster = repo.Branches["origin/master"]; var originMaster = repo.Branches["origin/master"];
repo.Reset(ResetMode.Hard, originMaster.Tip); repo.Reset(ResetMode.Hard, originMaster.Tip);
repo.RemoveUntrackedFiles();
} }
public void ReadIndex()
{ public void ReadIndex() {
try try {
{ _repo = JsonConvert.DeserializeObject<Repository>(File.ReadAllText(Path.Combine(_buildpath, "repomgr.index.json")));
_repo = JsonConvert.DeserializeObject<Repository>(
File.ReadAllText(Path.Combine(_buildpath, "repomgr.index.json")));
} }
catch (IOException) catch (IOException) {
{
throw new Exception("configuration file not found or wrong permissions. Did you run repomgr init?"); throw new Exception("configuration file not found or wrong permissions. Did you run repomgr init?");
} }
catch (JsonException) catch (JsonException) {
{
throw new Exception("configuration corrupt. Please check manually or re-init repo."); throw new Exception("configuration corrupt. Please check manually or re-init repo.");
} }
} }
private void WriteIndex()
{ private void WriteIndex() {
try try {
{
var json = JsonConvert.SerializeObject(_repo); var json = JsonConvert.SerializeObject(_repo);
if (!Directory.Exists(_buildpath)) if (!Directory.Exists(_buildpath))
Directory.CreateDirectory(_buildpath); Directory.CreateDirectory(_buildpath);
File.WriteAllText(Path.Combine(_buildpath, "repomgr.index.json"), json); File.WriteAllText(Path.Combine(_buildpath, "repomgr.index.json"), json);
} }
catch (IOException) catch (IOException) {
{
throw new Exception("Unable to write configuration. Check permissions."); throw new Exception("Unable to write configuration. Check permissions.");
} }
} }
private bool CheckPackage(string package)
{ private bool CheckPackage(string package) {
return Directory.Exists(Path.Combine(_pkgpath, package, ".git")) && return Directory.Exists(Path.Combine(_pkgpath, package, ".git")) && File.Exists(Path.Combine(_pkgpath, package, "PKGBUILD"));
File.Exists(Path.Combine(_pkgpath, package, "PKGBUILD"));
} }
public void Build(string package, bool force = false)
{ public void Build(string package, bool force = false) {
if (!CheckPackage(package)) return; if (!CheckPackage(package))
return;
var iPackage = GetPackage(package); var iPackage = GetPackage(package);
try try {
{
Build(iPackage, force); Build(iPackage, force);
} }
catch (Exception) catch (Exception) {
{
iPackage.LastBuildSucceeded = false; iPackage.LastBuildSucceeded = false;
throw; throw;
} }
} }
public void BuildAll()
{ public void BuildAll() {
foreach (var package in _repo.Packages) foreach (var package in _repo.Packages) {
{ if (!CheckPackage(package.Name))
if (!CheckPackage(package.Name)) return; return;
try
{ try {
Build(package); Build(package);
} }
catch (Exception) catch (Exception) {
{
package.LastBuildSucceeded = false; package.LastBuildSucceeded = false;
} }
} }
} }
public void Remove(string package)
{ public void Remove(string package) {
if (CheckPackage(package)) if (CheckPackage(package))
Remove(GetPackage(package)); Remove(GetPackage(package));
} }
} }
public class Repository public class Repository {
{ public Repository(string path, string name) {
public Repository(string path, string name)
{
Path = path; Path = path;
Name = name; Name = name;
Packages = new List<Package>(); Packages = new List<Package>();
@ -263,10 +240,8 @@ namespace repomgr
public readonly List<Package> Packages; public readonly List<Package> Packages;
} }
public class Package public class Package {
{ public Package(string name) {
public Package(string name)
{
Name = name; Name = name;
} }
@ -277,16 +252,12 @@ namespace repomgr
public readonly List<string> PkgFiles = new List<string>(); public readonly List<string> PkgFiles = new List<string>();
} }
internal static class Shell internal static class Shell {
{ public static void Exec(string cmd, string workingDirectory) {
public static void Exec(string cmd, string workingDirectory)
{
var escapedArgs = cmd.Replace("\"", "\\\""); var escapedArgs = cmd.Replace("\"", "\\\"");
var process = new Process() var process = new Process() {
{ StartInfo = new ProcessStartInfo {
StartInfo = new ProcessStartInfo
{
FileName = "/bin/bash", FileName = "/bin/bash",
Arguments = $"-c \"{escapedArgs}\"", Arguments = $"-c \"{escapedArgs}\"",
WorkingDirectory = workingDirectory, WorkingDirectory = workingDirectory,
@ -300,14 +271,11 @@ namespace repomgr
process.WaitForExit(); process.WaitForExit();
} }
public static string ExecR(string cmd, string workingDirectory) public static string ExecR(string cmd, string workingDirectory) {
{
var escapedArgs = cmd.Replace("\"", "\\\""); var escapedArgs = cmd.Replace("\"", "\\\"");
var process = new Process() var process = new Process() {
{ StartInfo = new ProcessStartInfo {
StartInfo = new ProcessStartInfo
{
FileName = "/bin/bash", FileName = "/bin/bash",
Arguments = $"-c \"{escapedArgs}\"", Arguments = $"-c \"{escapedArgs}\"",
WorkingDirectory = workingDirectory, WorkingDirectory = workingDirectory,
@ -323,25 +291,23 @@ namespace repomgr
return stdout.Trim(); return stdout.Trim();
} }
public static string Bold(string s) public static string Bold(string s) {
{ return $"\x1B[1m{s}\x1B[0m";
return $"\x1B[1m{s}\x1B[21m";
} }
public static string Red(string s) public static string Red(string s) {
{
return $"\x1b[31m{s}\x1b[39m"; return $"\x1b[31m{s}\x1b[39m";
} }
public static string Yellow(string s)
{ public static string Yellow(string s) {
return $"\x1b[33m{s}\x1b[39m"; return $"\x1b[33m{s}\x1b[39m";
} }
public static string Green(string s)
{ public static string Green(string s) {
return $"\x1b[32m{s}\x1b[39m"; return $"\x1b[32m{s}\x1b[39m";
} }
public static string Gray(string s)
{ public static string Gray(string s) {
return $"\x1b[90m{s}\x1b[39m"; return $"\x1b[90m{s}\x1b[39m";
} }
} }

View file

@ -9,51 +9,48 @@ using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace repomgr namespace repomgr
{ {
public class Startup public class Startup {
{ public Startup(IConfiguration configuration) => Configuration = configuration;
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; } public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services) {
{ services.AddRazorPages();
services.Configure<CookiePolicyOptions>(options => #if (DEBUG)
{ services.AddControllers().AddRazorRuntimeCompilation();
// This lambda determines whether user consent for non-essential cookies is needed for a given request. #else
options.CheckConsentNeeded = context => true; services.AddControllers();
options.MinimumSameSitePolicy = SameSiteMode.None; #endif
});
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env) public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
{ if (env.IsDevelopment()) {
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
} }
else else {
{
app.UseExceptionHandler("/Error"); app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts(); app.UseHsts();
} }
app.UseHttpsRedirection(); app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseMvc(); app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints => {
endpoints.MapRazorPages();
endpoints.MapControllers();
});
} }
} }
} }

View file

@ -1,21 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Configurations>Debug;Release</Configurations> <Configurations>Debug;Release</Configurations>
<Platforms>AnyCPU</Platforms> <Platforms>AnyCPU</Platforms>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier> <RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
<OutputType>Exe</OutputType>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="LibGit2Sharp" Version="0.26.0" /> <PackageReference Include="LibGit2Sharp" Version="0.26.2" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" /> <PackageReference Include="LibGit2Sharp.NativeBinaries" Version="2.0.306" />
<PackageReference Include="Microsoft.AspNetCore.CookiePolicy" Version="2.2.0" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.5" />
<PackageReference Include="Microsoft.AspNetCore.HttpsPolicy" Version="2.2.0" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
</ItemGroup> </ItemGroup>

View file

@ -1,15 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" /> <PackageReference Include="LibGit2Sharp.NativeBinaries" Version="2.0.306" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="xunit" Version="2.4.1" /> <PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" /> <PackageReference Include="xunit.runner.visualstudio" Version="2.4.2" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>