Esempio n. 1
0
        public string BuildGiteaUrl(GiteaUrlType urlType, Tuple <int, int> selectionLineRange)
        {
            // https://try.gitea.io/user/repo.git
            string urlRoot = GetRepoUrlRoot();

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

            var repositoryTarget = GetGiteaTargetPath(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 urlshowkind = "blob";

            if (urlType == GiteaUrlType.Blame)
            {
                urlshowkind = "blame";
            }
            if (urlType == GiteaUrlType.Commits)
            {
                urlshowkind = "commits";
            }
            var fileUrl = string.Format("{0}/{4}/{1}/{2}{3}", urlRoot.Trim('/'), WebUtility.UrlEncode(repositoryTarget.Trim('/')), fileIndexPath.Trim('/'), fragment, urlshowkind);

            return(fileUrl);
        }
 public string GetGiteaTargetPath(GiteaUrlType urlType)
 {
     switch (urlType)
     {
         case GiteaUrlType.CurrentBranch:
             return repository.Head.FriendlyName.Replace("origin/", "");
         case GiteaUrlType.CurrentRevision:
             return repository.Commits.First().Id.ToString(8);
         case GiteaUrlType.CurrentRevisionFull:
             return repository.Commits.First().Id.Sha;
         case GiteaUrlType.Master:
         default:
             return "master";
     }
 }
 public string GetGiteaTargetDescription(GiteaUrlType urlType)
 {
     switch (urlType)
     {
         case GiteaUrlType.CurrentBranch:
             return Strings.GitAnalysisn_Branch + repository.Head.FriendlyName.Replace("origin/", "");
         case GiteaUrlType.CurrentRevision:
             return Strings.GitAnalysis_Revision + repository.Commits.First().Id.ToString(8);
         case GiteaUrlType.CurrentRevisionFull:
             return Strings.GitAnalysis_Revision + repository.Commits.First().Id.ToString(8) + Strings.GitAnalysis_GetGiteaTargetDescription_FullID;
         case GiteaUrlType.Blame:
             return Strings.GitAnalysis_Blame;
         case GiteaUrlType.Commits:
             return Strings.GitAnalysis_Commits;
         case GiteaUrlType.Master:
         default:
             return "master";
     }
 }