public bool TryGetUriForFile(string filePath, out Uri bitBucketUri)
        {
            GitSourceAnalyzer analyzer;

            if (GitSourceAnalyzer.TryCreate(filePath, out analyzer))
            {
                Dictionary <string, Uri> possibleOrigins = analyzer.PossibleOrigins.Where(kvp => kvp.Value.Host == Host).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

                if (possibleOrigins.Count > 0)
                {
                    Uri origin;

                    if (!possibleOrigins.TryGetValue(PreferredRemote, out origin))
                    {
                        origin = possibleOrigins.First().Value;
                    }

                    var projectAndRepo = origin.AbsolutePath.Trim('/').Replace(BITBUCKET_REPO_PATH_PREFIX, string.Empty).Split('/');
                    var remote         = Client.Manufacture(projectAndRepo[0]).FirstOrDefault(r => r.Name + GIT_EXTENSION == projectAndRepo[1]);
                    if (remote != null)
                    {
                        var remoteUri = remote.Uris.FirstOrDefault(u => u.Scheme.StartsWith("http"));
                        if (remoteUri != null)
                        {
                            bitBucketUri = AddToPath(remoteUri, analyzer.RepoRelativePath.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar).Where(p => !string.IsNullOrEmpty(p)));
                            return(true);
                        }
                    }
                }
            }

            bitBucketUri = null;
            return(false);
        }
Пример #2
0
        public static bool TryCreate(string path, out GitSourceAnalyzer result)
        {
            path = GetProperFilePathCapitalization(Path.GetFullPath(path));
            var workdir = Repository.Discover(path);

            if (workdir != null)
            {
                result = new GitSourceAnalyzer(path, workdir);
                return(true);
            }
            else
            {
                result = null;
                return(false);
            }
        }