Ejemplo n.º 1
0
        public static bool TryParse(string fullName, out BranchName branchName)
        {
            if (string.IsNullOrEmpty(fullName))
            {
                branchName = default;
                return(false);
            }

            if (fullName[0] == '/')
            {
                fullName = fullName.Substring(1);
            }

            var    normalPrefix = "refs/heads/";
            var    prPrefix     = "refs/pull/";
            string shortName;
            bool   isPullRequest;

            if (fullName.StartsWith(normalPrefix, StringComparison.OrdinalIgnoreCase))
            {
                shortName     = fullName.Substring(normalPrefix.Length);
                isPullRequest = false;
            }
            else if (fullName.StartsWith(prPrefix, StringComparison.OrdinalIgnoreCase))
            {
                shortName     = fullName.Split(new[] { '/' })[2];
                isPullRequest = true;
            }
            else
            {
                shortName     = fullName;
                isPullRequest = false;
            }

            branchName = new BranchName(fullName, shortName, isPullRequest);
            return(true);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Normalize the branch name so that has the short human readable form of the branch
 /// name
 /// </summary>
 public static string NormalizeBranchName(string fullName) => BranchName.Parse(fullName).ShortName;