diff --git a/CHANGELOG.md b/CHANGELOG.md index f907b2d549..89caee7765 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/Core/Net/NetFileCache.cs b/Core/Net/NetFileCache.cs index fba3c0a16e..0830a50639 100644 --- a/Core/Net/NetFileCache.cs +++ b/Core/Net/NetFileCache.cs @@ -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; } @@ -172,10 +168,7 @@ public bool IsCached(Uri url, out string outFilename) /// validation tests. Prefer this over IsCached when working with /// zip files. /// - public bool IsCachedZip(Uri url) - { - return GetCachedZip(url) != null; - } + public bool IsCachedZip(Uri url) => GetCachedZip(url) != null; /// /// Returns true if a file matching the given URL is cached, but makes no @@ -184,9 +177,7 @@ public bool IsCachedZip(Uri url) /// Use IsCachedZip() for a slower but more reliable method. /// public bool IsMaybeCachedZip(Uri url, DateTime? remoteTimestamp = null) - { - return GetCachedFilename(url, remoteTimestamp) != null; - } + => GetCachedFilename(url, remoteTimestamp) != null; /// > /// Returns the filename of an already cached url or null otherwise @@ -337,14 +328,12 @@ public void CheckFreeSpace(long bytesToStore) } private HashSet legacyDirs() - { - return manager?.Instances.Values + => manager?.Instances.Values .Where(ksp => ksp.Valid) .Select(ksp => ksp.DownloadCacheDir()) .Where(dir => Directory.Exists(dir)) .ToHashSet() ?? new HashSet(); - } public void EnforceSizeLimit(long bytes, Registry registry) { diff --git a/Core/Net/NetModuleCache.cs b/Core/Net/NetModuleCache.cs index 381e9e90ba..387b905a73 100644 --- a/Core/Net/NetModuleCache.cs +++ b/Core/Net/NetModuleCache.cs @@ -123,9 +123,7 @@ public string DescribeAvailability(CkanModule m) /// SHA1 hash, in all-caps hexadecimal format /// public string GetFileHashSha1(string filePath, IProgress progress, CancellationToken cancelToken = default(CancellationToken)) - { - return cache.GetFileHashSha1(filePath, progress, cancelToken); - } + => cache.GetFileHashSha1(filePath, progress, cancelToken); /// /// Calculate the SHA256 hash of a file @@ -136,9 +134,7 @@ public string DescribeAvailability(CkanModule m) /// SHA256 hash, in all-caps hexadecimal format /// public string GetFileHashSha256(string filePath, IProgress progress, CancellationToken cancelToken = default(CancellationToken)) - { - return cache.GetFileHashSha256(filePath, progress, cancelToken); - } + => cache.GetFileHashSha256(filePath, progress, cancelToken); /// /// Try to add a file to the module cache. diff --git a/Core/Registry/InstalledModule.cs b/Core/Registry/InstalledModule.cs index 4794bb86ce..feeb9e319b 100644 --- a/Core/Registry/InstalledModule.cs +++ b/Core/Registry/InstalledModule.cs @@ -89,30 +89,15 @@ public class InstalledModule // registry format compatibility. [JsonProperty] private Dictionary installed_files; - public IEnumerable 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 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); diff --git a/Core/Registry/Registry.cs b/Core/Registry/Registry.cs index 5d469f70d2..6906ef9309 100644 --- a/Core/Registry/Registry.cs +++ b/Core/Registry/Registry.cs @@ -47,14 +47,7 @@ public class Registry : IEnlistmentNotification, IRegistryQuerier [JsonProperty] public readonly SortedDictionary download_counts = new SortedDictionary(); 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 counts) { diff --git a/GUI/GUIUser.cs b/GUI/GUIUser.cs index 2bb7e58aff..77bb1132fa 100644 --- a/GUI/GUIUser.cs +++ b/GUI/GUIUser.cs @@ -17,10 +17,8 @@ public GUIUser(Main main, Wait wait) /// /// A GUIUser is obviously not headless. Returns false. /// - public bool Headless - { - get { return false; } - } + public bool Headless => false; + /// /// Shows a small form with the question. @@ -29,9 +27,7 @@ public bool Headless /// true if user pressed yes, false if no. /// Question. public bool RaiseYesNoDialog(string question) - { - return main.YesNoDialog(question); - } + => main.YesNoDialog(question); /// /// Will show a small form with the message and a list to choose from. @@ -40,9 +36,7 @@ public bool RaiseYesNoDialog(string question) /// Message. /// Array of offered options. public int RaiseSelectionDialog(string message, params object[] args) - { - return main.SelectionDialog(message, args); - } + => main.SelectionDialog(message, args); /// /// Shows a message box containing the formatted error message. diff --git a/Tests/Core/Cache.cs b/Tests/Core/Cache.cs index 9e5fa06cf2..09d42a4a2f 100644 --- a/Tests/Core/Cache.cs +++ b/Tests/Core/Cache.cs @@ -2,8 +2,10 @@ using System.IO; using System.Threading; using System.Globalization; + using NUnit.Framework; using Tests.Data; + using CKAN; namespace Tests.Core diff --git a/bin/ckan-merge-pr.py b/bin/ckan-merge-pr.py index 7c0e93adf6..8a6b27c787 100755 --- a/bin/ckan-merge-pr.py +++ b/bin/ckan-merge-pr.py @@ -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' @@ -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: @@ -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: