Skip to content

Commit

Permalink
Merge #3061 Netkan warning for archived repos, set bugtracker for GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed May 25, 2020
2 parents 6273ca5 + 2117521 commit 5b08975
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ All notable changes to this project will be documented in this file.
- [Netkan] Purge stale cache entries for SpaceDock (#2859 by: HebaruSan; reviewed: DasSkelett)
- [Netkan] NetKAN warnings (#3045 by: HebaruSan; reviewed: DasSkelett)
- [Netkan] Support fallback URLs for netkan validate-ckan (#3060 by: HebaruSan; reviewed: DasSkelett)
- [Netkan] Netkan warning for archived repos, set bugtracker for GitHub (#3061 by: HebaruSan; reviewed: DasSkelett)

## v1.27.2 (Chandrasekhar)

Expand Down
4 changes: 2 additions & 2 deletions Netkan/Services/CachingHttpService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,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 All @@ -30,17 +31,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 @@ -51,7 +56,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

0 comments on commit 5b08975

Please sign in to comment.