Beispiel #1
0
 public RevisionSource(
     RepositoryProvider provider,
     string accountName,
     string repositoryName,
     Revision?revision)
 {
     Provider       = provider;
     AccountName    = accountName;
     RepositoryName = repositoryName ?? throw new ArgumentNullException(nameof(repositoryName));
     Revision       = revision;
 }
Beispiel #2
0
        public static RevisionSource Parse(string text)
        {
            #region Preconditions

            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }

            #endregion

            var hasHost = text.Contains(":");

            if (text.Contains("://"))
            {
                // Strip off the protocal
                text = text.Substring(text.IndexOf("://") + 3);
            }

            var      provider       = RepositoryProvider.GitHub;
            string   accountName    = null;
            string   repositoryName = null;
            Revision?revision       = null;

            var i = 0;

            foreach (var part in text.Split(revisionSegmentSeperators)) // | : | / | # |
            {
                if (i == 0)
                {
                    if (hasHost)
                    {
                        provider = RepositoryProvider.Parse(part);
                    }
                    else
                    {
                        provider    = RepositoryProvider.GitHub;
                        accountName = part;
                    }
                }

                if (i == 1)
                {
                    if (accountName == null)
                    {
                        accountName = part;
                    }
                    else
                    {
                        repositoryName = part;
                    }
                }

                if (i == 2)
                {
                    if (repositoryName == null)
                    {
                        repositoryName = part;
                    }
                    else
                    {
                        revision = VersionControl.Revision.Parse(part);
                    }
                }

                if (i == 3)
                {
                    revision = VersionControl.Revision.Parse(part);
                }

                i++;
            }

            if (repositoryName.EndsWith(".git"))
            {
                repositoryName = repositoryName.Replace(".git", "");
            }

            return(new RevisionSource(provider, accountName, repositoryName, revision));
        }