public void Should_succeed_in_parsing_valid_url(string url)
        {
            var azureDevOpsRemoteParser = new AzureDevOpsRemoteParser();

            azureDevOpsRemoteParser.TryExtractAzureDevopsDataFromRemoteUrl(url, out var owner, out var project, out var repository).Should().BeTrue();
            owner.Should().Be("owner");
            project.Should().Be("project");
            repository.Should().Be("repo");

            azureDevOpsRemoteParser.IsValidRemoteUrl(url).Should().BeTrue();
        }
        public void Should_fail_in_parsing_invalid_url()
        {
            var azureDevOpsRemoteParser = new AzureDevOpsRemoteParser();
            var url = "https://[email protected]/owner/project/_git/repo";

            azureDevOpsRemoteParser.TryExtractAzureDevopsDataFromRemoteUrl(url, out var owner, out var project, out var repository).Should().BeFalse();
            owner.Should().BeNull();
            project.Should().BeNull();
            repository.Should().BeNull();

            azureDevOpsRemoteParser.IsValidRemoteUrl(url).Should().BeFalse();
        }
示例#3
0
        public override IList <ExternalLinkDefinition> GetDefinitions(string remoteUrl)
        {
            var    externalLinkDefinitions = new List <ExternalLinkDefinition>();
            string accountName             = null;
            string repoName = null;

            if (!string.IsNullOrWhiteSpace(remoteUrl))
            {
                _azureDevOpsRemoteParser.TryExtractAzureDevopsDataFromRemoteUrl(remoteUrl, out accountName, out _, out repoName);
            }

            accountName = accountName ?? "ACCOUNT_NAME";
            repoName    = repoName ?? "REPO_NAME";

            var azureDevopsUrl = $"https://dev.azure.com/{accountName}";
            var definition     = new ExternalLinkDefinition
            {
                Name          = string.Format(CodeLink.Text, ServiceName),
                Enabled       = true,
                SearchInParts = { ExternalLinkDefinition.RevisionPart.Message },
                SearchPattern = @".*",
                LinkFormats   =
                {
                    new ExternalLinkFormat {
                        Caption = string.Format(ViewCommitLink.Text, ServiceName), Format = $"{azureDevopsUrl}/_git/{repoName}/commit/%COMMIT_HASH%"
                    },
                    new ExternalLinkFormat {
                        Caption = string.Format(ViewProjectLink.Text, ServiceName), Format = $"{azureDevopsUrl}/{repoName}"
                    }
                }
            };

            externalLinkDefinitions.Add(definition);

            externalLinkDefinitions.Add(new ExternalLinkDefinition
            {
                Name          = string.Format(IssuesLink.Text, ServiceName),
                Enabled       = true,
                SearchInParts = { ExternalLinkDefinition.RevisionPart.Message },
                SearchPattern = @"#(\d+)",
                LinkFormats   = { new ExternalLinkFormat {
                                      Caption = "#{0}", Format = $"{azureDevopsUrl}/{repoName}/_workitems/edit/{{0}}"
                                  } }
            });

            return(externalLinkDefinitions);
        }