public void DuplicatesGetIgnored() { var store = Substitute.For <IGitHubConfigurationStore>(); var githubClient = Substitute.For <IGitHubClient>(); var githubClientLazy = new Lazy <IGitHubClient>(() => githubClient); store.GetBaseUrl().Returns("https://github.com"); store.GetIsEnabled().Returns(true); var workItemNumber = 1234; githubClient.Issue.Get(Arg.Is("UserX"), Arg.Is("RepoY"), Arg.Is(workItemNumber)) .Returns(new Issue("url", "htmlUrl", "commentUrl", "eventsUrl", workItemNumber, ItemState.Open, "Test title", "test body", null, null, new List <Octokit.Label>(), null, new List <Octokit.User>(), null, 0, null, null, DateTimeOffset.Now, null, workItemNumber, "node", false, null, null)); var mapper = new WorkItemLinkMapper(Substitute.For <ISystemLog>(), store, new CommentParser(), githubClientLazy); var workItems = mapper.Map(new OctopusBuildInformation { VcsRoot = "https://github.com/UserX/RepoY", VcsType = "Git", Commits = new Commit[] { new Commit { Id = "abcd", Comment = "This is a test commit message. Fixes #1234" }, new Commit { Id = "defg", Comment = "This is a test commit message with duplicates. Fixes #1234" } } }); Assert.AreEqual(1, ((ISuccessResult <WorkItemLink[]>)workItems).Value.Length); }
public void AzureDevOpsGitCommentsGetIgnored() { var store = Substitute.For <IGitHubConfigurationStore>(); var githubClient = Substitute.For <IGitHubClient>(); var githubClientLazy = new Lazy <IGitHubClient>(() => githubClient); store.GetBaseUrl().Returns("https://github.com"); store.GetIsEnabled().Returns(true); var log = Substitute.For <ISystemLog>(); var mapper = new WorkItemLinkMapper(log, store, new CommentParser(), githubClientLazy); var workItems = mapper.Map(new OctopusBuildInformation { VcsRoot = "https://something.com/_git/ProjectX", VcsType = "Git", Commits = new Commit[] { new Commit { Id = "abcd", Comment = "This is a test commit message. Fixes #1234" } } }); var success = workItems as ISuccessResult <WorkItemLink[]>; Assert.IsNotNull(success, "AzureDevOps VCS root should not be a failure"); Assert.IsEmpty(success !.Value, "AzureDevOps VCS root should return an empty list of links"); log.Received(1).WarnFormat("The VCS Root '{0}' indicates this build information is Azure DevOps related so GitHub comment references will be ignored", "https://something.com/_git/ProjectX"); }
public void HttpAuthExceptionShouldLogMeaningfulMessage() { if (!TryGetJiraSettings(out var baseUrl, out var username, out var _)) { Assert.Ignore($"Configure the following environment variables '{JiraBaseUrlEnvironmentVariable}', '{JiraUsernameEnvironmentVariable}', '{JiraAuthTokenEnvironmentVariable}' to run these tests."); } var log = Substitute.For <ISystemLog>(); var store = BuildJiraConfigurationStore(baseUrl, username, "invalidtoken"); var jira = BuildJiraRestClient(baseUrl, username, "invalidtoken", log); var buildInformation = CreateBuildInformation( new[] { new Commit { Id = "234", Comment = "OATP-9999" } }); var workItemLinkMapper = new WorkItemLinkMapper( store, new CommentParser(), new Lazy <IJiraRestClient>(jira), log); IResultFromExtension <WorkItemLink[]> result = null; Should.NotThrow( () => { result = workItemLinkMapper.Map(buildInformation); }); result.ShouldBeOfType <FailureResultFromExtension <WorkItemLink[]> >("A failure should be received"); var failure = (FailureResultFromExtension <WorkItemLink[]>)result; failure.ErrorString.ShouldStartWith("Authentication failure, check the Jira access token is valid and has permissions to read work items"); }
public void DuplicatesGetIgnored() { var store = Substitute.For <IJiraConfigurationStore>(); var jiraClient = Substitute.For <IJiraRestClient>(); var jiraClientLazy = new Lazy <IJiraRestClient>(() => jiraClient); store.GetBaseUrl().Returns("https://github.com"); store.GetIsEnabled().Returns(true); store.GetJiraUsername().Returns("user"); store.GetJiraPassword().Returns("password"); jiraClient.GetIssue(Arg.Is("JRE-1234")).Returns(new JiraIssue()); jiraClient.GetIssueComments(Arg.Is("JRE-1234")).Returns(new JiraIssueComments { Comments = new [] { new JiraIssueComment { Body = string.Empty } } }); var mapper = new WorkItemLinkMapper(store, new CommentParser(), jiraClientLazy); var workItems = mapper.Map(new OctopusPackageMetadata { CommentParser = "Jira", Commits = new Commit[] { new Commit { Id = "abcd", Comment = "This is a test commit message. Fixes JRE-1234" }, new Commit { Id = "defg", Comment = "This is a test commit message with duplicates. Fixes JRE-1234" } } }); Assert.IsTrue(workItems.Succeeded); Assert.AreEqual(1, workItems.Value.Length); }