private static string GetMethod([CanBeNull] string relativePath, GitHubItemType itemType, GitRepository repository) { var absolutePath = repository.LocalDirectory != null && relativePath != null ? PathConstruction.NormalizePath(Path.Combine(repository.LocalDirectory, relativePath)) : null; if (itemType == GitHubItemType.Directory || Directory.Exists(absolutePath) || relativePath == null) return "tree"; if (itemType == GitHubItemType.File || File.Exists(absolutePath)) return "blob"; return null; }
/// <summary> /// Url in the form of <c>https://github.com/{identifier}/tree/{branch}/directory</c> or /// <c>https://github.com/{identifier}/blob/{branch}/file</c> depending on the item type. /// </summary> public static string GetGitHubBrowseUrl( this GitRepository repository, string path = null, string branch = null, GitHubItemType itemType = GitHubItemType.Automatic) { branch = branch ?? repository.Branch.NotNull("repository.Branch != null"); var relativePath = GetRepositoryRelativePath(path, repository); var method = GetMethod(relativePath, itemType, repository); ControlFlow.Assert(path == null || method != null, "Could not determine item type."); return($"https://github.com/{repository.Identifier}/{method}/{branch}/{relativePath}"); }
/// <summary> /// Url in the form of <c>https://github.com/{identifier}/tree/{branch}/directory</c> or /// <c>https://github.com/{identifier}/blob/{branch}/file</c> depending on the item type. /// </summary> public static string GetGitHubBrowseUrl( this GitRepository repository, string path = null, string branch = null, GitHubItemType itemType = GitHubItemType.Automatic) { Assert.True(repository.IsGitHubRepository()); branch ??= repository.Branch.NotNull(); var relativePath = GetRepositoryRelativePath(path, repository); var method = GetMethod(relativePath, itemType, repository); Assert.True(path == null || method != null, "Could not determine item type"); return($"https://github.com/{repository.Identifier}/{method}/{branch}/{relativePath}".TrimEnd("/")); }
private static string GetMethod([CanBeNull] string relativePath, GitHubItemType itemType, GitRepository repository) { var absolutePath = repository.LocalDirectory != null && relativePath != null ? Path.Combine(repository.LocalDirectory, relativePath) : null; if (itemType == GitHubItemType.Directory || Directory.Exists(absolutePath) || relativePath == null) { return("tree"); } if (itemType == GitHubItemType.File || File.Exists(absolutePath)) { return("blob"); } return(null); }