コード例 #1
0
        public async Task <Build> LinkBuildWithPr(Build build)
        {
            try
            {
                var devopsbuild = await _buildHttpClient.GetBuildAsync(build.Project, int.Parse(build.Id));

                if (devopsbuild.Reason != BuildReason.PullRequest)
                {
                    return(build);
                }

                var project = devopsbuild.Project.Name;
                var repo    = devopsbuild.Repository.Name;
                var prId    = devopsbuild.TriggerInfo.FirstOrDefault(k => k.Key == "pr.number").Value;
                var url     = DevOpsUtils.FormatPrUrl(_config.BaseUrl, project, repo, prId);

                build.PullRequest = new PullRequest
                {
                    Id             = prId,
                    ProjectName    = project,
                    RepositoryName = repo,
                    Url            = url
                };

                return(build);
            }
            catch (VssException ex) when(ex.Message == "VS30063: You are not authorized to access https://dev.azure.com.")
            {
                //TODO error handling: PAT expired or missing scope "Build -> Read"
                throw;
            }
        }
コード例 #2
0
        public async Task <Build> FillPullRequestMetadataFromUrl(Build build)
        {
            try
            {
                var pr = await _gitHttpClient.GetPullRequestAsync(build.PullRequest.ProjectName, build.PullRequest.RepositoryName, int.Parse(build.PullRequest.Id))
                         .ConfigureAwait(false);

                build.PullRequest.AuthorName  = pr.CreatedBy.DisplayName;
                build.PullRequest.AuthorEmail = pr.CreatedBy.UniqueName;
                build.PullRequest.CreatedDate = pr.CreationDate;
                build.PullRequest.Title       = pr.Title;
                return(build);
            }
            catch (VssException ex)// when (ex.Message == "VS30063: You are not authorized to access https://dev.azure.com.")
            {
                //TODO error handling: PAT expired or missing scope "Build -> Read"
                return(null);
            }
        }