Ejemplo n.º 1
0
        public string BuildGitHubUrl(GitHubUrlType urlType, Tuple<int, int> selectionLineRange)
        {
            // https://github.com/user/repo.git
            var originUrl = repository.Config.Get<string>("remote.origin.url");
            if (originUrl == null) throw new InvalidOperationException("OriginUrl can't found");

            // https://github.com/user/repo
            var 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?://)([^@/]+)@", "");

            // foo/bar.cs
            var rootDir = repository.Info.WorkingDirectory;
            var fileIndexPath = targetFullPath.Substring(rootDir.Length).Replace("\\", "/");

            var repositoryTarget = GetGitHubTargetPath(urlType);

            // line selection
            var fragment = (selectionLineRange != null)
                                ? (selectionLineRange.Item1 == selectionLineRange.Item2)
                                    ? string.Format("#L{0}", selectionLineRange.Item1)
                                    : string.Format("#L{0}-L{1}", selectionLineRange.Item1, selectionLineRange.Item2)
                                : "";

            var fileUrl = string.Format("{0}/blob/{1}/{2}{3}", urlRoot.Trim('/'), WebUtility.UrlEncode(repositoryTarget.Trim('/')), fileIndexPath.Trim('/'), fragment);
            return fileUrl;
        }
Ejemplo n.º 2
0
 public string GetGitHubTargetDescription(GitHubUrlType urlType)
 {
     switch (urlType)
     {
         case GitHubUrlType.CurrentBranch:
             return "Branch: " + repository.Head.Name.Replace("origin/", "");
         case GitHubUrlType.CurrentRevision:
             return "Revision: " + repository.Commits.First().Id.ToString(8);
         case GitHubUrlType.CurrentRevisionFull:
             return "Revision: " + repository.Commits.First().Id.ToString(8) + "... (Full ID)";
         case GitHubUrlType.Master:
         default:
             return "master";
     }
 }
Ejemplo n.º 3
0
 public string GetGitHubTargetPath(GitHubUrlType urlType)
 {
     switch (urlType)
     {
         case GitHubUrlType.CurrentBranch:
             return repository.Head.Name.Replace("origin/", "");
         case GitHubUrlType.CurrentRevision:
             return repository.Commits.First().Id.ToString(8);
         case GitHubUrlType.CurrentRevisionFull:
             return repository.Commits.First().Id.Sha;
         case GitHubUrlType.Master:
         default:
             return "master";
     }
 }
Ejemplo n.º 4
0
        public string GetGitHubTargetDescription(GitHubUrlType urlType)
        {
            switch (urlType)
            {
            case GitHubUrlType.CurrentBranch:
                return("Branch: " + repository.Head.Name.Replace("origin/", ""));

            case GitHubUrlType.CurrentRevision:
                return("Revision: " + repository.Commits.First().Id.ToString(8));

            case GitHubUrlType.CurrentRevisionFull:
                return("Revision: " + repository.Commits.First().Id.ToString(8) + "... (Full ID)");

            case GitHubUrlType.Master:
            default:
                return("master");
            }
        }
Ejemplo n.º 5
0
        public string BuildGitHubUrl(GitHubUrlType urlType, Tuple <int, int> selectionLineRange)
        {
            // https://github.com/user/repo.git
            var originUrl = repository.Config.Get <string>("remote.origin.url");

            if (originUrl == null)
            {
                throw new InvalidOperationException("OriginUrl can't found");
            }

            // https://github.com/user/repo
            var 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?://)([^@/]+)@", "");

            // foo/bar.cs
            var rootDir       = repository.Info.WorkingDirectory;
            var fileIndexPath = targetFullPath.Substring(rootDir.Length).Replace("\\", "/");

            var repositoryTarget = GetGitHubTargetPath(urlType);

            // line selection
            var fragment = (selectionLineRange != null)
                                ? (selectionLineRange.Item1 == selectionLineRange.Item2)
                                    ? string.Format("#L{0}", selectionLineRange.Item1)
                                    : string.Format("#L{0}-L{1}", selectionLineRange.Item1, selectionLineRange.Item2)
                                : "";

            var fileUrl = string.Format("{0}/blob/{1}/{2}{3}", urlRoot.Trim('/'), WebUtility.UrlEncode(repositoryTarget.Trim('/')), fileIndexPath.Trim('/'), fragment);

            return(fileUrl);
        }