-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- update LibGit2Sharp to version 0.27.0.0 (arm64 support)
- update .NetFramework to version 4.7.2 - it's safe for Visual Studio 2017https://stackoverflow.com/questions/56616487/net-framework-version-compatibility-for-visual-studio-package https://learn.microsoft.com/en-us/visualstudio/releases/2017/vs2017-system-requirements-vs - fix missing Visual Studio 2022 json file context menu #14 - add support for Solution Explorer and Tab Bar #16 - add functionality to work on other Version Control Tools (Gitea, Bitbucket, AzureDevOps) #15 - add arm64 support - add main branch support #12 - rename menu "Open on GitHub -> master" to "Git Hub -> Open Main" Useful repositories: * https://github.com/ziyasal/vscode-open-in-github * https://github.com/veler/CopyGitLink
- Loading branch information
Showing
25 changed files
with
756 additions
and
472 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,33 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace OpenOnGitHub | ||
{ | ||
static class PackageGuids | ||
{ | ||
public const string guidOpenOnGitHubPkgString = "465b40b6-311a-4e37-9556-95fced2de9c6"; | ||
public const string guidOpenOnGitHubCmdSetString = "a674aaec-a6f5-4df0-9749-e7bef776df5d"; | ||
|
||
public static readonly Guid guidOpenOnGitHubCmdSet = new Guid(guidOpenOnGitHubCmdSetString); | ||
private const string guidOpenOnGitHubCmdSetString = "a674aaec-a6f5-4df0-9749-e7bef776df5d"; | ||
public static readonly Guid guidOpenOnGitHubCmdSet = new(guidOpenOnGitHubCmdSetString); | ||
}; | ||
|
||
static class PackageCommanddIDs | ||
static class PackageCommandIDs | ||
{ | ||
public const uint OpenMaster = 0x100; | ||
public const uint OpenBranch = 0x200; | ||
public const uint OpenRevision = 0x300; | ||
public const uint OpenRevisionFull = 0x400; | ||
public const int OpenMain = 0x100; | ||
public const int OpenBranch = 0x200; | ||
public const int OpenRevision = 0x300; | ||
public const int OpenRevisionFull = 0x400; | ||
|
||
public static IEnumerable<int> Enumerate() | ||
{ | ||
yield return OpenMain; | ||
yield return OpenBranch; | ||
yield return OpenRevisionFull; | ||
yield return OpenRevision; | ||
} | ||
}; | ||
|
||
static class PackageVersion | ||
{ | ||
public const string Version = "1.3"; | ||
public const string Version = "2.0"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System; | ||
using System.IO; | ||
|
||
namespace OpenOnGitHub.Extensions | ||
{ | ||
public static class StringExtensions | ||
{ | ||
/// <summary> | ||
/// Returns true if <paramref name="path"/> starts with the path <paramref name="baseDirPath"/>. | ||
/// The comparison is case-insensitive, handles / and \ slashes as folder separators and | ||
/// only matches if the base dir folder name is matched exactly ("c:\foobar\file.txt" is not a sub path of "c:\foo"). | ||
/// </summary> | ||
public static bool IsSubPathOf(this string path, string baseDirPath) | ||
{ | ||
var normalizedPath = Path.GetFullPath(path.Replace('/', '\\') | ||
.WithEnding("\\")); | ||
|
||
var normalizedBaseDirPath = Path.GetFullPath(baseDirPath.Replace('/', '\\') | ||
.WithEnding("\\")); | ||
|
||
return normalizedPath.StartsWith(normalizedBaseDirPath, StringComparison.OrdinalIgnoreCase); | ||
} | ||
|
||
/// <summary> | ||
/// Returns <paramref name="str"/> with the minimal concatenation of <paramref name="ending"/> (starting from end) that | ||
/// results in satisfying .EndsWith(ending). | ||
/// </summary> | ||
/// <example>"hel".WithEnding("llo") returns "hello", which is the result of "hel" + "lo".</example> | ||
private static string WithEnding(this string str, string ending) | ||
{ | ||
if (str == null) | ||
return ending; | ||
|
||
// Right() is 1-indexed, so include these cases | ||
// * Append no characters | ||
// * Append up to N characters, where N is ending length | ||
for (var i = 0; i <= ending.Length; i++) | ||
{ | ||
var tmp = str + ending.Right(i); | ||
if (tmp.EndsWith(ending, StringComparison.OrdinalIgnoreCase)) | ||
return tmp; | ||
} | ||
|
||
return str; | ||
} | ||
|
||
/// <summary>Gets the rightmost <paramref name="length" /> characters from a string.</summary> | ||
/// <param name="value">The string to retrieve the substring from.</param> | ||
/// <param name="length">The number of characters to retrieve.</param> | ||
/// <returns>The substring.</returns> | ||
private static string Right(this string value, int length) | ||
{ | ||
if (value == null) | ||
{ | ||
throw new ArgumentNullException(nameof(value)); | ||
} | ||
if (length < 0) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(length), length, "Length is less than zero"); | ||
} | ||
|
||
return length < value.Length ? value.Substring(value.Length - length) : value; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace OpenOnGitHub; | ||
|
||
public enum GitHubUrlType | ||
{ | ||
Main, | ||
CurrentBranch, | ||
CurrentRevision, | ||
CurrentRevisionFull | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
using LibGit2Sharp; | ||
using OpenOnGitHub.Extensions; | ||
using System; | ||
using System.Linq; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace OpenOnGitHub | ||
{ | ||
public sealed class GitRepository : IDisposable | ||
{ | ||
private Repository _innerRepository; | ||
private string _rootDirectory; | ||
public string MainBranchName { get; private set; } | ||
public bool IsDiscoveredGitRepository => _innerRepository != null; | ||
public string UrlRoot { get; private set; } | ||
|
||
public GitRepository(string targetFullPath) | ||
{ | ||
var repositoryPath = Repository.Discover(targetFullPath); | ||
|
||
if (repositoryPath != null) | ||
{ | ||
Initialize(repositoryPath); | ||
return; | ||
} | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
private void Initialize(string repositoryPath) | ||
{ | ||
_innerRepository = new Repository(repositoryPath); | ||
|
||
// https://github.com/user/repo.git | ||
var originUrl = _innerRepository.Config.Get<string>("remote.origin.url") ?? | ||
throw new InvalidOperationException("OriginUrl can't found"); | ||
|
||
// https://github.com/user/repo | ||
UrlRoot = originUrl.Value.EndsWith(".git", StringComparison.InvariantCultureIgnoreCase) | ||
? originUrl.Value.Substring(0, originUrl.Value.Length - 4) // remove .git | ||
: originUrl.Value; | ||
|
||
// [email protected]:user/repo -> http://github.com/user/repo | ||
UrlRoot = Regex.Replace(UrlRoot, "^git@(.+):(.+)/(.+)$", | ||
match => "http://" + string.Join("/", match.Groups.OfType<Group>().Skip(1).Select(group => group.Value)), | ||
RegexOptions.IgnoreCase); | ||
|
||
// https://[email protected]/user/repo -> https://github.com/user/repo | ||
UrlRoot = Regex.Replace(UrlRoot, "(?<=^https?://)([^@/]+)@", ""); | ||
|
||
//https://github.com/user/repo/ -> https://github.com/user/repo | ||
UrlRoot = UrlRoot.TrimEnd('/'); | ||
|
||
// foo/bar.cs | ||
_rootDirectory = _innerRepository.Info.WorkingDirectory; | ||
|
||
MainBranchName = _innerRepository.Branches.Select(x => x.FriendlyName) | ||
.FirstOrDefault(x => new[] { "main", "master" }.Contains(x.ToLower())) ?? "main"; | ||
} | ||
|
||
public bool IsInsideRepositoryFolder(string filePath) | ||
{ | ||
return filePath.IsSubPathOf(_rootDirectory); | ||
} | ||
|
||
public string GetFileIndexPath(string fullFilePath) | ||
{ | ||
return fullFilePath.Substring(_rootDirectory.Length).Replace('\\', '/'); | ||
} | ||
|
||
public string GetGitHubTargetPath(GitHubUrlType urlType) | ||
{ | ||
return urlType switch | ||
{ | ||
GitHubUrlType.CurrentBranch => _innerRepository.Head.FriendlyName.Replace("origin/", ""), | ||
GitHubUrlType.CurrentRevision => _innerRepository.Commits.First().Id.ToString(8), | ||
GitHubUrlType.CurrentRevisionFull => _innerRepository.Commits.First().Id.Sha, | ||
_ => MainBranchName | ||
}; | ||
} | ||
|
||
public string GetGitHubTargetDescription(GitHubUrlType urlType) | ||
{ | ||
return urlType switch | ||
{ | ||
GitHubUrlType.CurrentBranch => $"Open Branch: {_innerRepository.Head.FriendlyName.Replace("origin/", "")}", | ||
GitHubUrlType.CurrentRevision => $"Open Revision: {_innerRepository.Commits.First().Id.ToString(8)}", | ||
GitHubUrlType.CurrentRevisionFull => $"Open Revision: {_innerRepository.Commits.First().Id.ToString(8)}... (Full ID)", | ||
_ => $"Open {MainBranchName}" | ||
}; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_innerRepository?.Dispose(); | ||
_innerRepository = null; | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
~GitRepository() | ||
{ | ||
_innerRepository?.Dispose(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace OpenOnGitHub; | ||
|
||
public interface IGitUrlProvider | ||
{ | ||
string GetUrl(GitRepository repository, string filePath, GitHubUrlType urlType, SelectedRange selectedRange); | ||
bool IsUrlTypeAvailable(GitHubUrlType urlType); | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.