public static void AzureDevOpsSetPullRequestStatus(
            this ICakeContext context,
            AzureDevOpsPullRequestSettings settings,
            AzureDevOpsPullRequestStatus status)
        {
            context.NotNull(nameof(context));
            settings.NotNull(nameof(settings));
            status.NotNull(nameof(status));

            new AzureDevOpsPullRequest(context.Log, settings, new GitClientFactory()).SetStatus(status);
        }
Пример #2
0
            public void Should_Set_Valid_Status_On_AzureDevOps_Pull_Request()
            {
                // Given
                var fixture     = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 16);
                var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);
                var status      = new AzureDevOpsPullRequestStatus("Hello")
                {
                    State = AzureDevOpsPullRequestStatusState.Succeeded
                };

                // When
                pullRequest.SetStatus(status);

                // Then
                // ?? Nothing to validate here since the method returns void
            }
Пример #3
0
            public void Should_Throw_If_AzureDevOps_Pull_Request_State_Is_Invalid()
            {
                // Given
                var fixture     = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 16);
                var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);
                var status      = new AzureDevOpsPullRequestStatus("whatever")
                {
                    State = (AzureDevOpsPullRequestStatusState)123
                };

                // When
                var result = Record.Exception(() => pullRequest.SetStatus(status));

                // Then
                result.ShouldNotBe(null);
                result.IsExpected("SetStatus");
                result.Message.ShouldBe("Unknown value");
            }
Пример #4
0
        /// <inheritdoc />
        public override void SetPullRequestIssuesState(IssuesContext context)
        {
            context.NotNull(nameof(context));

#pragma warning disable SA1123 // Do not place regions within elements
            #region DupFinder Exclusion
#pragma warning restore SA1123 // Do not place regions within elements
            if (string.IsNullOrWhiteSpace(context.EnvironmentVariable("SYSTEM_ACCESSTOKEN")))
            {
                context.Warning("SYSTEM_ACCESSTOKEN environment variable not set. Make sure the 'Allow Scripts to access OAuth token' option is enabled on the build definition.");
                return;
            }

            var pullRequestSettings =
                new AzureDevOpsPullRequestSettings(
                    context.State.BuildServer.DetermineRepositoryRemoteUrl(context, context.State.RepositoryRootDirectory),
                    context.State.BuildServer.DeterminePullRequestId(context).Value,
                    context.AzureDevOpsAuthenticationOAuth(context.EnvironmentVariable("SYSTEM_ACCESSTOKEN")));
            #endregion

            var pullRequestStatusName            = "Issues";
            var pullRequestDescriptionIfIssues   = $"Found {context.State.Issues.Count()} issues";
            var pullRequestDescriptionIfNoIssues = "No issues found";
            if (!string.IsNullOrWhiteSpace(context.Parameters.BuildIdentifier))
            {
                pullRequestStatusName            += $"-{context.Parameters.BuildIdentifier}";
                pullRequestDescriptionIfIssues   += $" for build {context.Parameters.BuildIdentifier}";
                pullRequestDescriptionIfNoIssues += $" for build {context.Parameters.BuildIdentifier}";
            }

            var pullRequestStatus =
                new AzureDevOpsPullRequestStatus(pullRequestStatusName)
            {
                Genre       = "Cake.Issues.Recipe",
                State       = context.State.Issues.Any() ? AzureDevOpsPullRequestStatusState.Failed : AzureDevOpsPullRequestStatusState.Succeeded,
                Description = context.State.Issues.Any() ? pullRequestDescriptionIfIssues : pullRequestDescriptionIfNoIssues
            };

            context.AzureDevOpsSetPullRequestStatus(
                pullRequestSettings,
                pullRequestStatus);
        }
Пример #5
0
            public void Should_Throw_If_Null_Is_Returned_On_AzureDevOps_Pull_Request()
            {
                // Given
                var fixture = new PullRequestFixture(BasePullRequestFixture.ValidAzureDevOpsServerUrl, 16)
                {
                    GitClientFactory = new FakeNullForMethodsGitClientFactory(),
                };
                var pullRequest = new AzureDevOpsPullRequest(fixture.Log, fixture.Settings, fixture.GitClientFactory);
                var status      = new AzureDevOpsPullRequestStatus("One")
                {
                    State = AzureDevOpsPullRequestStatusState.Failed
                };

                // When
                var result = Record.Exception(() => pullRequest.SetStatus(status));

                // Then
                result.ShouldNotBe(null);
                result.IsExpected("SetStatus");
                result.IsAzureDevOpsPullRequestNotFoundException();
            }