Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Netkan warning for archived repos, set bugtracker for GitHub #3061

Merged
merged 5 commits into from
May 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Netkan/Services/CachingHttpService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ internal sealed class CachingHttpService : IHttpService
private bool _overwriteCache = false;
private Dictionary<Uri, StringCacheEntry> _stringCache = new Dictionary<Uri, StringCacheEntry>();

// Re-use string value URLs within 2 minutes
private static readonly TimeSpan stringCacheLifetime = new TimeSpan(0, 2, 0);
// Re-use string value URLs within 15 minutes
private static readonly TimeSpan stringCacheLifetime = new TimeSpan(0, 15, 0);

public CachingHttpService(NetFileCache cache, bool overwrite = false)
{
Expand Down
16 changes: 11 additions & 5 deletions Netkan/Sources/Github/GithubRepo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,34 @@ public sealed class GithubRepo

[JsonProperty("license")]
public GithubLicense License { get; set; }

[JsonProperty("parent")]
public GithubRepo ParentRepo { get; set; }

[JsonProperty("source")]
public GithubRepo SourceRepo { get; set; }

[JsonProperty("owner")]
public GithubUser Owner { get; set; }

[JsonProperty("has_issues")]
public bool HasIssues { get; set; }

[JsonProperty("archived")]
public bool Archived { get; set; }
}

public class GithubLicense
{
[JsonProperty("spdx_id")]
public string Id;
}

public class GithubUser
{
[JsonProperty("login")]
public string Login { get; set; }

[JsonProperty("type")]
public string Type { get; set; }
}
Expand Down
8 changes: 8 additions & 0 deletions Netkan/Transformers/GithubTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public IEnumerable<Metadata> Transform(Metadata metadata, TransformOptions opts)

// Get the GitHub repository
var ghRepo = _api.GetRepo(ghRef);
if (ghRepo.Archived)
{
Log.Warn("Repo is archived, consider freezing");
}
var versions = _api.GetAllReleases(ghRef);
if (opts.SkipReleases.HasValue)
{
Expand Down Expand Up @@ -103,6 +107,10 @@ private Metadata TransformOne(Metadata metadata, JObject json, GithubRef ghRef,
resourcesJson.SafeAdd("homepage", ghRepo.Homepage);

resourcesJson.SafeAdd("repository", ghRepo.HtmlUrl);
if (ghRepo.HasIssues)
{
resourcesJson.SafeAdd("bugtracker", $"{ghRepo.HtmlUrl}/issues");
}

if (ghRelease != null)
{
Expand Down
19 changes: 12 additions & 7 deletions Netkan/Validators/ModuleManagerDependsValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using log4net;
using CKAN.NetKAN.Services;
using CKAN.NetKAN.Model;
using CKAN.Extensions;

namespace CKAN.NetKAN.Validators
{
Expand Down Expand Up @@ -34,17 +35,21 @@ public void Validate(Metadata metadata)
{
ZipFile zip = new ZipFile(package);

bool hasMMsyntax = _moduleService.GetConfigFiles(mod, zip)
.Select(cfg => new StreamReader(zip.GetInputStream(cfg.source)).ReadToEnd())
.Any(contents => moduleManagerRegex.IsMatch(contents));
var mmConfigs = _moduleService.GetConfigFiles(mod, zip)
.Where(cfg => moduleManagerRegex.IsMatch(
new StreamReader(zip.GetInputStream(cfg.source)).ReadToEnd()))
.Memoize();

bool dependsOnMM = mod?.depends?.Any(r => r.ContainsAny(identifiers)) ?? false;

if (hasMMsyntax && !dependsOnMM)
if (!dependsOnMM && mmConfigs.Any())
{
Log.Warn("ModuleManager syntax used without ModuleManager dependency");
Log.WarnFormat(
"ModuleManager syntax used without ModuleManager dependency: {0}",
string.Join(", ", mmConfigs.Select(cfg => cfg.source))
);
}
else if (!hasMMsyntax && dependsOnMM)
else if (dependsOnMM && !mmConfigs.Any())
{
Log.Warn("ModuleManager dependency may not be needed, no ModuleManager syntax found");
}
Expand All @@ -55,7 +60,7 @@ public void Validate(Metadata metadata)
private string[] identifiers = new string[] { "ModuleManager" };

private static readonly Regex moduleManagerRegex = new Regex(
@"^\s*[@+$\-!%]",
@"^\s*[@+$\-!%]|^\s*[a-zA-Z0-9_]+:",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline
);

Expand Down