private PullRequestDto GetPullRequestDto(MergeRequest mergeRequest)
        {
            var pullRequestDto = new PullRequestDto
            {
                Number    = mergeRequest.Iid,
                Title     = mergeRequest.Title,
                CreatedAt = mergeRequest.CreatedAt,
                MergedAt  = mergeRequest.UpdatedAt,
                Author    = mergeRequest.Author.Name,
                AuthorUrl = mergeRequest.Author.WebUrl,
                Url       = PullRequestUrl(mergeRequest.Iid),
                Labels    = new List <string>()
            };

            foreach (var label in mergeRequest.Labels)
            {
                // filter out any unwanted pull requests
                if (label.CaseInsensitiveContains(_programArgs.ExcludeLabel))
                {
                    if (_programArgs.VerboseOutput)
                    {
                        Console.WriteLine($"   - Excluding Merge Request");
                    }
                    return(null);
                }
                pullRequestDto.Labels.Add(label);
                if (_programArgs.VerboseOutput)
                {
                    Console.WriteLine($"   - Label : {label}");
                }
            }
            return(pullRequestDto);
        }
        private IEnumerable <BitBucketServerCommit> GetPullRequestCommits(PullRequestDto pullRequestDto)
        {
            ResponseWrapper <BitBucketServerCommit> commits;
            var request  = new RestRequest($"/pull-requests/{pullRequestDto.Number}/commits", Method.GET);
            var response = _restClient.Execute(request);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                try
                {
                    commits = JsonConvert.DeserializeObject <ResponseWrapper <BitBucketServerCommit> >(response.Content);
                }
                catch (JsonReaderException)
                {
                    Console.WriteLine($"Error finding BitBucket Server pull request commits. Response content:\n{response.Content}");
                    throw;
                }
                if (response.StatusCode != HttpStatusCode.OK || commits == null || !commits.Values.Any())
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
            return(commits.Values);
        }
        private IEnumerable <SharpBucket.V2.Pocos.Commit> GetPullRequestCommits(PullRequestDto pullRequestDto)
        {
            var pullRequests = _bitBucketClient.RepositoriesEndPoint()
                               .PullReqestsResource(_programArgs.BitBucketAccount, _programArgs.BitBucketRepository);

            return(pullRequests.PullRequestResource(pullRequestDto.Number).ListPullRequestCommits() as IEnumerable <SharpBucket.V2.Pocos.Commit>);
        }
        private ICommitLog GetPullRequestCommits(PullRequestDto pullRequestDto)
        {
            var filter = new CommitFilter
            {
                Since           = pullRequestDto.MergeCommitSha,
                Until           = pullRequestDto.BaseCommitSha,
                FirstParentOnly = true
            };

            return(_programArgs.LocalGitRepository.Commits.QueryBy(filter));
        }
        private PullRequestDto GetPullRequestDto(PullRequest pullRequest)
        {
            var pullRequestDto = new PullRequestDto
            {
                Number         = pullRequest.Id,
                Title          = RemoveTags(pullRequest.Title),
                CreatedAt      = pullRequest.CreationDate,
                MergedAt       = pullRequest.ClosedDate,
                Author         = pullRequest.CreatedBy.DisplayName,
                AuthorUrl      = pullRequest.CreatedBy.Url.ToString(),
                Url            = PullRequestUrl(pullRequest.Id),
                BaseCommitSha  = pullRequest.LastMergeTargetCommit.Id.ToString(),
                MergeCommitSha = pullRequest.LastMergeSourceCommit.Id.ToString(),
                Labels         = new List <string>()
            };
            // extract labels from title and description following pattern [#Section] ... [##Category]
            var labelPattern = new Regex(@"\#(?:[^\[\]]+)*");
            var matches      = labelPattern.Matches($"{pullRequest.Title}{pullRequest.Description}");

            if (matches.Count <= 0)
            {
                return(null);
            }
            foreach (Match match in matches)
            {
                foreach (var group in match.Groups.Cast <Group>().Distinct().ToList())
                {
                    var label = group.Value.Substring(1);
                    // filter out any unwanted pull requests
                    if (label.CaseInsensitiveContains(_programArgs.ExcludeLabel))
                    {
                        if (_programArgs.VerboseOutput)
                        {
                            Console.WriteLine($"   - Excluding Pull Request");
                        }
                        return(null);
                    }
                    pullRequestDto.Labels.Add(label);
                    if (_programArgs.VerboseOutput)
                    {
                        Console.WriteLine($"   - Label : {label}");
                    }
                }
            }
            pullRequestDto.Labels = pullRequestDto.Labels.Distinct().ToList();
            return(pullRequestDto);
        }
        private PullRequestDto GetPullRequestDto(PullRequest pullRequest)
        {
            var pullRequestDto = new PullRequestDto
            {
                Number      = (int)pullRequest.id,
                Title       = RemoveTags(pullRequest.title),
                CreatedAt   = Convert.ToDateTime(pullRequest.created_on),
                MergedAt    = Convert.ToDateTime(pullRequest.updated_on),
                Author      = pullRequest.author.display_name,
                AuthorUrl   = pullRequest.author.links.self.href,
                Url         = PullRequestUrl((int)pullRequest.id),
                DocumentUrl = pullRequest.description.ExtractDocumentUrl(),
                Labels      = new List <string>()
            };

            // extract labels from title and description following pattern [#Section] ... [##Category]
            var labelPattern = new Regex(@"\#(?:[^\[\]]+)*");
            var matches      = labelPattern.Matches($"{pullRequest.title}{pullRequest.description}");

            if (matches.Count <= 0)
            {
                return(null);
            }
            foreach (Match match in matches)
            {
                foreach (var group in match.Groups.Cast <Group>().Distinct().ToList())
                {
                    var label = group.Value.Substring(1);
                    // filter out any unwanted pull requests
                    if (label.CaseInsensitiveContains(_programArgs.ExcludeLabel))
                    {
                        if (_programArgs.VerboseOutput)
                        {
                            Console.WriteLine($"   - Excluding Pull Request");
                        }
                        return(null);
                    }
                    pullRequestDto.Labels.Add(label);
                    if (_programArgs.VerboseOutput)
                    {
                        Console.WriteLine($"   - Label : {label}");
                    }
                }
            }
            pullRequestDto.Labels = pullRequestDto.Labels.Distinct().ToList();
            return(pullRequestDto);
        }
        private PullRequestDto GetPullRequestDto(BitBucketServerPullRequest pullRequest)
        {
            var pullRequestDto = new PullRequestDto
            {
                Number      = Convert.ToInt32(pullRequest.Id),
                Title       = RemoveTags(pullRequest.Title),
                CreatedAt   = Convert.ToInt64(pullRequest.CreatedDate).FromTimestamp(),
                MergedAt    = Convert.ToInt64(pullRequest.UpdatedDate).FromTimestamp(),
                Author      = pullRequest.Author.User.DisplayName,
                AuthorUrl   = pullRequest.Author.User.Links.Self.First().Href.ToString(),
                Url         = PullRequestUrl(Convert.ToInt32(pullRequest.Id)),
                DocumentUrl = pullRequest.Description.ExtractDocumentUrl(),
                Labels      = new List <string>()
            };
            // extract labels from title and description following pattern [#Section] ... [##Category]
            var labelPattern = new Regex(@"\#(?:[^\[\]]+)*");
            var matches      = labelPattern.Matches($"{pullRequest.Title}{pullRequest.Description}");

            if (matches.Count <= 0)
            {
                return(null);
            }
            foreach (Match match in matches)
            {
                foreach (var group in match.Groups.Cast <Group>().Distinct().ToList())
                {
                    var label = group.Value.Substring(1);
                    // filter out any unwanted pull requests
                    if (label.CaseInsensitiveContains(_programArgs.ExcludeLabel))
                    {
                        if (_programArgs.VerboseOutput)
                        {
                            Console.WriteLine($"   - Excluding Pull Request");
                        }
                        return(null);
                    }
                    pullRequestDto.Labels.Add(label);
                    if (_programArgs.VerboseOutput)
                    {
                        Console.WriteLine($"   - Label : {label}");
                    }
                }
            }
            pullRequestDto.Labels = pullRequestDto.Labels.Distinct().ToList();
            return(pullRequestDto);
        }
Esempio n. 8
0
        private PullRequestDto GetPullRequestWithLabels(int pullRequestId)
        {
            // pull requests are actually GitHub issues so we have to use the issue API to get labels
            var issue = _gitHubClient.Issue.Get(_programArgs.GitHubOwner, _programArgs.GitHubRepository, pullRequestId).Result;

            if (issue == null)
            {
                return(null);
            }
            if (_programArgs.VerboseOutput)
            {
                Console.WriteLine($"Found #{issue.Number}: {issue.Title}");
            }
            var pullRequestDto = new PullRequestDto
            {
                Number      = issue.Number,
                Title       = issue.Title,
                CreatedAt   = issue.CreatedAt,
                MergedAt    = issue.ClosedAt,
                Author      = issue.User.Login,
                AuthorUrl   = issue.User.Url,
                Url         = PullRequestUrl(issue.Number),
                DocumentUrl = issue.Body.ExtractDocumentUrl(),
                Labels      = new List <string>()
            };

            foreach (var label in issue.Labels)
            {
                // filter out any unwanted pull requests
                if (label.Name.CaseInsensitiveContains(_programArgs.ExcludeLabel))
                {
                    if (_programArgs.VerboseOutput)
                    {
                        Console.WriteLine($"   - Excluding Pull Request");
                    }
                    return(null);
                }
                pullRequestDto.Labels.Add(label.Name);
                if (_programArgs.VerboseOutput)
                {
                    Console.WriteLine($"   - Label : {label.Name}");
                }
            }
            return(pullRequestDto);
        }
        private PullRequestDto GetPullRequestWithLabels(PullRequest pullRequest)
        {
            // pull requests are actually GitHub issues so we have to use the issue API to get labels
            var issueNumber    = int.Parse(pullRequest.IssueUrl.Segments.Last());
            var issue          = _gitHubClient.Issue.Get(_programArgs.GitHubOwner, _programArgs.GitHubRepository, issueNumber).Result;
            var pullRequestDto = new PullRequestDto
            {
                Number    = pullRequest.Number,
                Title     = pullRequest.Title,
                CreatedAt = pullRequest.CreatedAt,
                MergedAt  = pullRequest.MergedAt,
                Author    = pullRequest.User.Login,
                AuthorUrl = pullRequest.User.Url,
                Url       = PullRequestUrl(pullRequest.Number),
                Labels    = new List <string>()
            };

            foreach (var label in issue.Labels)
            {
                // filter out any unwanted pull requests
                if (label.Name.CaseInsensitiveContains(_programArgs.ExcludeLabel))
                {
                    if (_programArgs.VerboseOutput)
                    {
                        Console.WriteLine($"   - Excluding Pull Request");
                    }
                    return(null);
                }
                pullRequestDto.Labels.Add(label.Name);
                if (_programArgs.VerboseOutput)
                {
                    Console.WriteLine($"   - Label : {label.Name}");
                }
            }
            return(pullRequestDto);
        }