Skip to content

Commit

Permalink
Merge #3884 Deduce primary branch name in merge script
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Aug 18, 2023
2 parents b361b38 + ba417a7 commit 42875fb
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 75 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.
### Internal

- [Netkan] Fix Netkan swinfo transformer null list error (#3869 by: HebaruSan)
- [Tooling] Deduce primary branch name in merge script (#3884 by: HebaruSan; reviewed: techman83)

## v1.33.2 (Laplace)

Expand Down
19 changes: 4 additions & 15 deletions Core/Net/NetFileCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,13 @@ public void OnCacheChanged()
}

// returns true if a url is already in the cache
public bool IsCached(Uri url)
{
return GetCachedFilename(url) != null;
}
public bool IsCached(Uri url) => GetCachedFilename(url) != null;

// returns true if a url is already in the cache
// returns the filename in the outFilename parameter
public bool IsCached(Uri url, out string outFilename)
{
outFilename = GetCachedFilename(url);

return outFilename != null;
}

Expand All @@ -172,10 +168,7 @@ public bool IsCached(Uri url, out string outFilename)
/// validation tests. Prefer this over IsCached when working with
/// zip files.
/// </summary>
public bool IsCachedZip(Uri url)
{
return GetCachedZip(url) != null;
}
public bool IsCachedZip(Uri url) => GetCachedZip(url) != null;

/// <summary>
/// Returns true if a file matching the given URL is cached, but makes no
Expand All @@ -184,9 +177,7 @@ public bool IsCachedZip(Uri url)
/// Use IsCachedZip() for a slower but more reliable method.
/// </summary>
public bool IsMaybeCachedZip(Uri url, DateTime? remoteTimestamp = null)
{
return GetCachedFilename(url, remoteTimestamp) != null;
}
=> GetCachedFilename(url, remoteTimestamp) != null;

/// <summary>>
/// Returns the filename of an already cached url or null otherwise
Expand Down Expand Up @@ -337,14 +328,12 @@ public void CheckFreeSpace(long bytesToStore)
}

private HashSet<string> legacyDirs()
{
return manager?.Instances.Values
=> manager?.Instances.Values
.Where(ksp => ksp.Valid)
.Select(ksp => ksp.DownloadCacheDir())
.Where(dir => Directory.Exists(dir))
.ToHashSet()
?? new HashSet<string>();
}

public void EnforceSizeLimit(long bytes, Registry registry)
{
Expand Down
8 changes: 2 additions & 6 deletions Core/Net/NetModuleCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ public string DescribeAvailability(CkanModule m)
/// SHA1 hash, in all-caps hexadecimal format
/// </returns>
public string GetFileHashSha1(string filePath, IProgress<long> progress, CancellationToken cancelToken = default(CancellationToken))
{
return cache.GetFileHashSha1(filePath, progress, cancelToken);
}
=> cache.GetFileHashSha1(filePath, progress, cancelToken);

/// <summary>
/// Calculate the SHA256 hash of a file
Expand All @@ -136,9 +134,7 @@ public string DescribeAvailability(CkanModule m)
/// SHA256 hash, in all-caps hexadecimal format
/// </returns>
public string GetFileHashSha256(string filePath, IProgress<long> progress, CancellationToken cancelToken = default(CancellationToken))
{
return cache.GetFileHashSha256(filePath, progress, cancelToken);
}
=> cache.GetFileHashSha256(filePath, progress, cancelToken);

/// <summary>
/// Try to add a file to the module cache.
Expand Down
27 changes: 6 additions & 21 deletions Core/Registry/InstalledModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,30 +89,15 @@ public class InstalledModule
// registry format compatibility.
[JsonProperty] private Dictionary<string, InstalledModuleFile> installed_files;

public IEnumerable<string> Files
{
get { return installed_files.Keys; }
}

public string identifier
{
get { return source_module.identifier; }
}

public CkanModule Module
{
get { return source_module; }
}

public DateTime InstallTime
{
get { return install_time; }
}
public IEnumerable<string> Files => installed_files.Keys;
public string identifier => source_module.identifier;
public CkanModule Module => source_module;
public DateTime InstallTime => install_time;

public bool AutoInstalled
{
get { return auto_installed; }
set {
get => auto_installed;
set {
if (Module.IsDLC)
{
throw new ModuleIsDLCKraken(Module);
Expand Down
9 changes: 1 addition & 8 deletions Core/Registry/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,7 @@ public class Registry : IEnlistmentNotification, IRegistryQuerier
[JsonProperty] public readonly SortedDictionary<string, int> download_counts = new SortedDictionary<string, int>();

public int? DownloadCount(string identifier)
{
int count;
if (download_counts.TryGetValue(identifier, out count))
{
return count;
}
return null;
}
=> download_counts.TryGetValue(identifier, out int count) ? (int?)count : null;

public void SetDownloadCounts(SortedDictionary<string, int> counts)
{
Expand Down
14 changes: 4 additions & 10 deletions GUI/GUIUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ public GUIUser(Main main, Wait wait)
/// <summary>
/// A GUIUser is obviously not headless. Returns false.
/// </summary>
public bool Headless
{
get { return false; }
}
public bool Headless => false;


/// <summary>
/// Shows a small form with the question.
Expand All @@ -29,9 +27,7 @@ public bool Headless
/// <returns><c>true</c> if user pressed yes, <c>false</c> if no.</returns>
/// <param name="question">Question.</param>
public bool RaiseYesNoDialog(string question)
{
return main.YesNoDialog(question);
}
=> main.YesNoDialog(question);

/// <summary>
/// Will show a small form with the message and a list to choose from.
Expand All @@ -40,9 +36,7 @@ public bool RaiseYesNoDialog(string question)
/// <param name="message">Message.</param>
/// <param name="args">Array of offered options.</param>
public int RaiseSelectionDialog(string message, params object[] args)
{
return main.SelectionDialog(message, args);
}
=> main.SelectionDialog(message, args);

/// <summary>
/// Shows a message box containing the formatted error message.
Expand Down
2 changes: 2 additions & 0 deletions Tests/Core/Cache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
using System.IO;
using System.Threading;
using System.Globalization;

using NUnit.Framework;
using Tests.Data;

using CKAN;

namespace Tests.Core
Expand Down
34 changes: 19 additions & 15 deletions bin/ckan-merge-pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@

class CkanRepo(Repo):

def remote_master(self) -> RemoteReference:
return self.heads.master.tracking_branch()
def remote_primary(self) -> RemoteReference:
return next(filter(lambda ref: 'HEAD' in ref.name, self.refs))

def master_remote(self) -> Remote:
return self.remotes[self.remote_master().remote_name]
def primary_name(self) -> str:
full = self.remote_primary().ref.name
return full[full.index('/')+1:]

def on_master(self) -> bool:
return not self.head.is_detached and self.head.ref.name == 'master'
def primary_remote(self) -> Remote:
return self.remotes[self.remote_primary().remote_name]

def master_up_to_date(self) -> bool:
print(f'Fetching {self.master_remote().name}...')
self.master_remote().fetch()
return self.heads.master.commit.hexsha == self.remote_master().commit.hexsha
def on_primary_branch(self) -> bool:
return not self.head.is_detached and self.head.ref.name == self.primary_name()

def primary_branch_up_to_date(self) -> bool:
print(f'Fetching {self.primary_remote().name}...')
self.primary_remote().fetch()
return getattr(self.heads, self.primary_name()).commit.hexsha == self.remote_primary().commit.hexsha

def changelog_path(self) -> Path:
return Path(self.working_dir) / 'CHANGELOG.md'
Expand All @@ -38,7 +42,7 @@ def prepend_line(self, path: Path, new_line: str) -> None:
changelog.writelines(lines)

def user_edit_file(self, path: Path) -> None:
editor=self.config_reader().get('core', 'editor')
editor = self.config_reader().get('core', 'editor')
run([editor, str(path)])

class CkanPullRequest:
Expand Down Expand Up @@ -86,11 +90,11 @@ def merge_into(self, repo: CkanRepo, self_review: bool) -> bool:
if not self_review and not self.approvers():
print(f'PR #{self.pull_request.number} is not approved!')
return False
if not repo.on_master():
print(f'Not on master branch!')
if not repo.on_primary_branch():
print('Not on primary branch!')
return False
if not repo.master_up_to_date():
print(f'master branch is not up to date!')
if not repo.primary_branch_up_to_date():
print('Primary branch is not up to date!')
return False
branch = self.latest_commit(repo)
if not branch:
Expand Down

0 comments on commit 42875fb

Please sign in to comment.