コード例 #1
0
        public void SaveIssues(BitbucketRepository repository, string path)
        {
            var exportUrl = string.Concat(_oldApiUrl, repository.TeamName, "/", repository.DirectoryName, _issueExportUri);

            // to prepare export
            _request.GetResponseFileStream(exportUrl);

            var exportDownloadUrl = string.Concat(_oldApiUrl, repository.TeamName, "/", repository.DirectoryName, _issueExportDownloadUri);

            Stream responseStream = _request.GetResponseFileStream(exportDownloadUrl);

            FileStream fileStream = File.Create(path);

            int bufferSize = 1024;
            var buffer     = new byte[bufferSize];
            int bytesRead  = 0;

            try
            {
                while ((bytesRead = responseStream.Read(buffer, 0, bufferSize)) != 0)
                {
                    fileStream.Write(buffer, 0, bytesRead);
                }
            }
            finally
            {
                fileStream.Dispose();
            }
        }
コード例 #2
0
        public IEnumerable <BitbucketRepository> GetTeamRepositories(string teamName)
        {
            List <BitbucketRepository> repositories = new List <BitbucketRepository>();

            string apiUrl      = string.Concat(_newApiUrl, teamName);
            JToken nextPageUrl = string.Concat(apiUrl, "?pagelen=", MaxPagelen);

            try
            {
                while (nextPageUrl != null)
                {
                    JObject response = _request.GetResponse(nextPageUrl.ToString());
                    JToken  values   = response["values"];

                    foreach (JToken value in values ?? Enumerable.Empty <JToken>())
                    {
                        BitbucketRepository repository = new BitbucketRepository();
                        repository.Name          = value["name"].ToString().ToLower();
                        repository.DirectoryName = repository.Name.Replace(" ", "-");
                        repository.TeamName      = teamName;
                        repository.CloneUrl      = value["links"]["clone"].First["href"].ToString();
                        repository.HasWiki       = (bool)value["has_wiki"];
                        repository.HasIssues     = (bool)value["has_issues"];
                        repository.UpdatedOn     = (DateTime)value["updated_on"];

                        if (repository.HasIssues)
                        {
                            try
                            {
                                repository.LastIssueChange = GetLastIssueChange(repository);
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(repository.Name + " - Error: " + e.Message);
                                repository.LastIssueChange = DateTime.MinValue;
                            }
                        }
                        else
                        {
                            repository.LastIssueChange = DateTime.MinValue;
                        }
                        repositories.Add(repository);
                        Console.WriteLine(repository.Name);
                    }
                    nextPageUrl = response["next"];
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(teamName + " - Error: " + e.Message);
            }
            return(repositories);
        }
コード例 #3
0
        private IEnumerable <JObject> GetIssues(BitbucketRepository repository)
        {
            var    issues      = new List <JObject>();
            JToken nextPageUrl = string.Concat(_newApiUrl, repository.TeamName, "/", repository.DirectoryName, "/issues?pagelen=", MaxPagelen);

            while (nextPageUrl != null)
            {
                JObject response = _request.GetResponse(nextPageUrl.ToString());
                issues.Add(response);

                nextPageUrl = response["next"];
            }
            return(issues);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: DataOne/BitUp
        private static ErrorType DownloadRepository(BitbucketRepository repository, IGitSourceControl sourceControl, string repositoryDirectory)
        {
            ErrorType error          = ErrorType.None;
            string    cloneDirectory = string.Concat(repositoryDirectory, @"\", repository.DirectoryName, ".git");
            string    wikiDirectory  = cloneDirectory.Replace(".git", "-wiki.git");

            if (Directory.Exists(cloneDirectory))
            {
                ForceDeleteDirectory(cloneDirectory);
            }
            if (Directory.Exists(wikiDirectory))
            {
                ForceDeleteDirectory(wikiDirectory);
            }
            AppendLog(repository.Name + Messages.CloneRepository);
            sourceControl.CloneRepository(repository.CloneUrl, cloneDirectory);

            if (repository.HasIssues)
            {
                AppendLog(Messages.ExportIssues);
                string issueZipPath = string.Concat(repositoryDirectory, "/", repository.DirectoryName, "-issues.zip");

                try
                {
                    sourceControl.SaveIssues(repository, issueZipPath);
                }
                catch (Exception e)
                {
                    error = ErrorType.Error;
                    AppendLog(Messages.IssueExportingError + e.Message);
                }
            }
            if (repository.HasWiki)
            {
                AppendLog(Messages.CloneWiki);
                try
                {
                    sourceControl.CloneWiki(repository.CloneUrl, wikiDirectory);
                }
                catch (Exception e)
                {
                    error = ErrorType.Error;
                    AppendLog(Messages.WikiCloningError + e.Message);
                }
            }
            return(error);
        }
コード例 #5
0
        private DateTime GetLastIssueChange(BitbucketRepository repository)
        {
            DateTime latestChange = DateTime.MinValue;

            IEnumerable <JObject> allIssues = GetIssues(repository);

            foreach (var issues in allIssues ?? Enumerable.Empty <JObject>())
            {
                foreach (var issue in issues["values"])
                {
                    DateTime updatedOn = (DateTime)issue["updated_on"];
                    if (latestChange < updatedOn)
                    {
                        latestChange = updatedOn;
                    }
                }
            }
            return(latestChange);
        }