Exemple #1
0
        private static GithubReference ParseGithubUrl(Uri input)
        {
            if (input.Host != "github.com")
            {
                return(null);
            }
            var pathParts = input.PathAndQuery.Split(new[] { '/' }, 4, StringSplitOptions.RemoveEmptyEntries);

            int issue;

            if (pathParts.Length == 4 &&
                pathParts[2] == "pull" &&
                Int32.TryParse(pathParts[3], out issue))
            {
                return(GithubReference.FromIssue(pathParts[0], pathParts[1], issue));
            }

            if (pathParts.Length == 4 &&
                pathParts[2] == "tree")
            {
                return(GithubReference.FromBranch(pathParts[0], pathParts[1], pathParts[3]));
            }

            if (pathParts.Length == 4 &&
                pathParts[2] == "compare")
            {
                return(ParseCommitOrBranch(pathParts[0], pathParts[1], pathParts[3]));
            }

            return(null);
        }
Exemple #2
0
        private static GithubReference ParseCommitOrBranch(string user, string repo, string commitOrBranch)
        {
            string[] comparison;
            if (TrySplitComparison(commitOrBranch, out comparison) && comparison.Length == 2)
            {
                return(GithubReference.FromComparison(user, repo, comparison[1], comparison[0]));
            }

            if (Regex.IsMatch(commitOrBranch, @"^[a-f0-9]{4,40}$"))
            {
                return(GithubReference.FromCommit(user, repo, commitOrBranch));
            }

            return(GithubReference.FromBranch(user, repo, commitOrBranch));
        }