예제 #1
0
        public void Initialize(IBuildServerWatcher buildServerWatcher, ISettingsSource config)
        {
            if (_buildServerWatcher != null)
                throw new InvalidOperationException("Already initialized");

            _buildServerWatcher = buildServerWatcher;

            var projectName = config.GetString("ProjectName", null);
            var hostName = config.GetString("BuildServerUrl", null);

            if (!string.IsNullOrEmpty(hostName) && !string.IsNullOrEmpty(projectName))
            {
                var baseAdress = hostName.Contains("://")
                                     ? new Uri(hostName, UriKind.Absolute)
                                     : new Uri(string.Format("{0}://{1}:8080", Uri.UriSchemeHttp, hostName), UriKind.Absolute);

                _httpClient = new HttpClient(new HttpClientHandler(){ UseDefaultCredentials = true});
                _httpClient.Timeout = TimeSpan.FromMinutes(2);
                _httpClient.BaseAddress = baseAdress;

                var buildServerCredentials = buildServerWatcher.GetBuildServerCredentials(this, true);

                UpdateHttpClientOptions(buildServerCredentials);

                _getBuildUrls = new List<Task<IEnumerable<string>>>();

                string[] projectUrls = projectName.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var projectUrl in projectUrls.Select(s => baseAdress + "job/" + s.Trim() + "/"))
                {
                    AddGetBuildUrl(projectUrl);
                }
            }
        }
예제 #2
0
        public void Initialize(IBuildServerWatcher buildServerWatcher, ISettingsSource config, Func <string, bool> isCommitInRevisionGrid)
        {
            if (_buildServerWatcher != null)
            {
                throw new InvalidOperationException("Already initialized");
            }

            _buildServerWatcher = buildServerWatcher;

            _tfsServer             = config.GetString("TfsServer", null);
            _tfsTeamCollectionName = config.GetString("TfsTeamCollectionName", null);
            _projectName           = config.GetString("ProjectName", null);
            var tfsBuildDefinitionNameFilterSetting = config.GetString("TfsBuildDefinitionName", "");

            if (!BuildServerSettingsHelper.IsRegexValid(tfsBuildDefinitionNameFilterSetting))
            {
                return;
            }

            _tfsBuildDefinitionNameFilter = new Regex(tfsBuildDefinitionNameFilterSetting, RegexOptions.Compiled);

            if (!string.IsNullOrEmpty(_tfsServer) &&
                !string.IsNullOrEmpty(_tfsTeamCollectionName) &&
                !string.IsNullOrEmpty(_projectName))
            {
                _tfsHelper = LoadAssemblyAndConnectToServer("TfsInterop.Vs2015")
                             ?? LoadAssemblyAndConnectToServer("TfsInterop.Vs2013")
                             ?? LoadAssemblyAndConnectToServer("TfsInterop.Vs2012");

                if (_tfsHelper == null)
                {
                    Trace.WriteLine("fail to load the good interop assembly :(");
                }
            }
        }
예제 #3
0
        public void Initialize(IBuildServerWatcher buildServerWatcher, ISettingsSource config)
        {
            if (_buildServerWatcher != null)
                throw new InvalidOperationException("Already initialized");

            _buildServerWatcher = buildServerWatcher;

            _tfsServer = config.GetString("TfsServer", null);
            _tfsTeamCollectionName = config.GetString("TfsTeamCollectionName", null);
            _projectName = config.GetString("ProjectName", null);
            _tfsBuildDefinitionName = config.GetString("TfsBuildDefinitionName", null);

            if (!string.IsNullOrEmpty(_tfsServer)
                && !string.IsNullOrEmpty(_tfsTeamCollectionName)
                && !string.IsNullOrEmpty(_projectName))
            {
                _tfsHelper = LoadAssemblyAndConnectToServer("TfsInterop.Vs2013")
                    ?? LoadAssemblyAndConnectToServer("TfsInterop.Vs2012");

                if (_tfsHelper == null)
                {
                    Trace.WriteLine("fail to load the good interop assembly :(");
                }
            }
        }
예제 #4
0
        public void Initialize(IBuildServerWatcher buildServerWatcher, ISettingsSource config, Func <ObjectId, bool> isCommitInRevisionGrid = null)
        {
            if (_buildServerWatcher != null)
            {
                throw new InvalidOperationException("Already initialized");
            }

            _buildServerWatcher = buildServerWatcher;
            _settings           = IntegrationSettings.ReadFrom(config);

            if (!_settings.IsValid())
            {
                return;
            }

            _projectUrl = _buildServerWatcher.ReplaceVariables(_settings.ProjectUrl);

            if (!Uri.IsWellFormedUriString(_projectUrl, UriKind.Absolute) || string.IsNullOrWhiteSpace(_settings.ApiToken))
            {
                return;
            }

            _apiClient = new ApiClient(_projectUrl, _settings.ApiToken);
            if (CacheAzureDevOps == null || CacheAzureDevOps.Id != CacheKey)
            {
                CacheAzureDevOps      = null;
                _buildDefinitionsTask = _apiClient.GetBuildDefinitionsAsync(_settings.BuildDefinitionFilter);
            }
            else
            {
                _buildDefinitions = CacheAzureDevOps.BuildDefinitions;
            }
        }
예제 #5
0
        public void Initialize(IBuildServerWatcher buildServerWatcher, ISettingsSource config)
        {
            if (_buildServerWatcher != null)
            {
                throw new InvalidOperationException("Already initialized");
            }

            _buildServerWatcher = buildServerWatcher;

            _tfsServer              = config.GetString("TfsServer", null);
            _tfsTeamCollectionName  = config.GetString("TfsTeamCollectionName", null);
            _projectName            = config.GetString("ProjectName", null);
            _tfsBuildDefinitionName = config.GetString("TfsBuildDefinitionName", null);

            if (!string.IsNullOrEmpty(_tfsServer) &&
                !string.IsNullOrEmpty(_tfsTeamCollectionName) &&
                !string.IsNullOrEmpty(_projectName))
            {
                _tfsHelper = LoadAssemblyAndConnectToServer("TfsInterop.Vs2013")
                             ?? LoadAssemblyAndConnectToServer("TfsInterop.Vs2012");

                if (_tfsHelper == null)
                {
                    Trace.WriteLine("fail to load the good interop assembly :(");
                }
            }
        }
예제 #6
0
        public void Initialize(IBuildServerWatcher buildServerWatcher, ISettingsSource config, Func <string, bool> isCommitInRevisionGrid)
        {
            if (_buildServerWatcher != null)
            {
                throw new InvalidOperationException("Already initialized");
            }

            _buildServerWatcher = buildServerWatcher;

            _tfsServer             = config.GetString(VstsTfsServerUrlSettingKey, null);
            _tfsTeamCollectionName = config.GetString(VstsTfsCollectionNameSettingKey, null);
            _projectName           = _buildServerWatcher.ReplaceVariables(config.GetString(VstsTfsProjectNameSettingKey, null));
            _restApiToken          = config.GetString(VstsTfsRestApiTokenSettingKey, null);
            var tfsBuildDefinitionNameFilterSetting = config.GetString(VstsTfsBuildDefinitionNameFilterSettingKey, "");

            if (string.IsNullOrWhiteSpace(_tfsServer) ||
                string.IsNullOrWhiteSpace(_tfsTeamCollectionName) ||
                string.IsNullOrWhiteSpace(_projectName) ||
                string.IsNullOrWhiteSpace(_restApiToken) ||
                !BuildServerSettingsHelper.IsRegexValid(tfsBuildDefinitionNameFilterSetting))
            {
                return;
            }

            _tfsHelper = new TfsApiHelper(_httpClient);
            _tfsHelper.ConnectToTfsServer(_tfsServer, _tfsTeamCollectionName, _projectName, _restApiToken, tfsBuildDefinitionNameFilterSetting);
        }
예제 #7
0
        public void Initialize(IBuildServerWatcher buildServerWatcher, ISettingsSource config)
        {
            if (this.buildServerWatcher != null)
            {
                throw new InvalidOperationException("Already initialized");
            }

            this.buildServerWatcher = buildServerWatcher;

            ProjectNames = config.GetString("ProjectName", "").Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

            var buildIdFilerSetting = config.GetString("BuildIdFilter", "");

            if (!BuildServerSettingsHelper.IsRegexValid(buildIdFilerSetting))
            {
                return;
            }
            BuildIdFilter = new Regex(buildIdFilerSetting, RegexOptions.Compiled);
            var hostName = config.GetString("BuildServerUrl", null);

            LogAsGuestUrlParameter = config.GetBool("LogAsGuest", false) ? "&guest=1" : string.Empty;

            if (!string.IsNullOrEmpty(hostName))
            {
                httpClient = new HttpClient
                {
                    Timeout     = TimeSpan.FromMinutes(2),
                    BaseAddress = hostName.Contains("://")
                                          ? new Uri(hostName, UriKind.Absolute)
                                          : new Uri(string.Format("{0}://{1}", Uri.UriSchemeHttp, hostName), UriKind.Absolute)
                };
                httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));

                var buildServerCredentials = buildServerWatcher.GetBuildServerCredentials(this, true);

                UpdateHttpClientOptions(buildServerCredentials);

                if (ProjectNames.Length > 0)
                {
                    getBuildTypesTask.Clear();
                    foreach (var name in ProjectNames)
                    {
                        getBuildTypesTask.Add(
                            GetProjectFromNameXmlResponseAsync(name, CancellationToken.None)
                            .ContinueWith(
                                task => from element in task.Result.XPathSelectElements("/project/buildTypes/buildType")
                                select element.Attribute("id").Value,
                                TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.AttachedToParent));
                    }
                }
            }
        }
        void IBuildServerAdapter.Initialize(IBuildServerWatcher buildServerWatcher, ISettingsSource config, Func <ObjectId, bool> isCommitInRevisionGrid = null)
        {
            if (_buildServerWatcher != null)
            {
                throw new InvalidOperationException("Already initialized");
            }

            _buildServerWatcher = buildServerWatcher;

            _gitLabAddress = config.GetString(GitlabSettingsConstants.GitlabAddress, null);
            _gitLabKey     = config.GetString(GitlabSettingsConstants.GitlabKey, null);
            _projectName   = config.GetString(GitlabSettingsConstants.DefaultProjectId, null);
        }
예제 #9
0
        public void Initialize(IBuildServerWatcher buildServerWatcher, ISettingsSource config, Func <ObjectId, bool> isCommitInRevisionGrid = null)
        {
            if (_buildServerWatcher != null)
            {
                throw new InvalidOperationException("Already initialized");
            }

            _buildServerWatcher = buildServerWatcher;
            _settings           = IntegrationSettings.ReadFrom(config);

            if (!_settings.IsValid())
            {
                return;
            }

            var projectUrl = _buildServerWatcher.ReplaceVariables(_settings.ProjectUrl);

            _apiClient = new ApiClient(projectUrl, _settings.ApiToken);
        }
예제 #10
0
        public void Initialize(IBuildServerWatcher buildServerWatcher, ISettingsSource config, Action openSettings, Func <ObjectId, bool> isCommitInRevisionGrid = null)
        {
            if (_buildServerWatcher is not null)
            {
                throw new InvalidOperationException("Already initialized");
            }

            _buildServerWatcher = buildServerWatcher;

            var projectName = config.GetString("ProjectName", null);
            var hostName    = config.GetString("BuildServerUrl", null);

            if (!string.IsNullOrEmpty(hostName) && !string.IsNullOrEmpty(projectName))
            {
                var baseAddress = hostName.Contains("://")
                    ? new Uri(hostName, UriKind.Absolute)
                    : new Uri($"{Uri.UriSchemeHttp}://{hostName}:8080", UriKind.Absolute);

                _httpClient = new HttpClient(new HttpClientHandler {
                    UseDefaultCredentials = true
                })
                {
                    Timeout     = TimeSpan.FromMinutes(2),
                    BaseAddress = baseAddress
                };

                var buildServerCredentials = buildServerWatcher.GetBuildServerCredentials(this, true);

                UpdateHttpClientOptions(buildServerCredentials);

                string[] projectUrls = _buildServerWatcher.ReplaceVariables(projectName)
                                       .Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var projectUrl in projectUrls.Select(s => baseAddress + "job/" + s.Trim() + "/"))
                {
                    _lastProjectBuildTime[projectUrl] = -1;
                }
            }

            var ignoreBuilds = config.GetString("IgnoreBuildBranch", string.Empty);

            _ignoreBuilds = !string.IsNullOrWhiteSpace(ignoreBuilds) ? new Regex(ignoreBuilds) : null;
        }
예제 #11
0
        public void Initialize(IBuildServerWatcher buildServerWatcher, ISettingsSource config, Func <string, bool> isCommitInRevisionGrid)
        {
            if (_buildServerWatcher != null)
            {
                throw new InvalidOperationException("Already initialized");
            }

            _buildServerWatcher = buildServerWatcher;

            ProjectNames = buildServerWatcher.ReplaceVariables(config.GetString("ProjectName", ""))
                           .Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

            var buildIdFilerSetting = config.GetString("BuildIdFilter", "");

            if (!BuildServerSettingsHelper.IsRegexValid(buildIdFilerSetting))
            {
                return;
            }

            BuildIdFilter          = new Regex(buildIdFilerSetting, RegexOptions.Compiled);
            HostName               = config.GetString("BuildServerUrl", null);
            LogAsGuestUrlParameter = config.GetBool("LogAsGuest", false) ? "&guest=1" : string.Empty;

            if (!string.IsNullOrEmpty(HostName))
            {
                InitializeHttpClient(HostName);
                if (ProjectNames.Length > 0)
                {
                    _getBuildTypesTask.Clear();
                    foreach (var name in ProjectNames)
                    {
                        _getBuildTypesTask.Add(ThreadHelper.JoinableTaskFactory.RunAsync(async() =>
                        {
                            var response = await GetProjectFromNameXmlResponseAsync(name, CancellationToken.None).ConfigureAwait(false);
                            return(from element in response.XPathSelectElements("/project/buildTypes/buildType")
                                   select element.Attribute("id").Value);
                        }));
                    }
                }
            }
        }
예제 #12
0
        public void Initialize(IBuildServerWatcher buildServerWatcher, ISettingsSource config, Func <string, bool> isCommitInRevisionGrid)
        {
            if (this.buildServerWatcher != null)
            {
                throw new InvalidOperationException("Already initialized");
            }

            this.buildServerWatcher = buildServerWatcher;

            ProjectNames = config.GetString("ProjectName", "").Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

            var buildIdFilerSetting = config.GetString("BuildIdFilter", "");

            if (!BuildServerSettingsHelper.IsRegexValid(buildIdFilerSetting))
            {
                return;
            }
            BuildIdFilter = new Regex(buildIdFilerSetting, RegexOptions.Compiled);
            var hostName = config.GetString("BuildServerUrl", null);

            LogAsGuestUrlParameter = config.GetBool("LogAsGuest", false) ? "&guest=1" : string.Empty;

            if (!string.IsNullOrEmpty(hostName))
            {
                InitializeHttpClient(hostName, () => buildServerWatcher.GetBuildServerCredentials(this, true));

                if (ProjectNames.Length > 0)
                {
                    getBuildTypesTask.Clear();
                    foreach (var name in ProjectNames)
                    {
                        getBuildTypesTask.Add(
                            GetProjectFromNameXmlResponseAsync(name, CancellationToken.None)
                            .ContinueWith(
                                task => from element in task.Result.XPathSelectElements("/project/buildTypes/buildType")
                                select element.Attribute("id").Value,
                                TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.AttachedToParent));
                    }
                }
            }
        }
예제 #13
0
        public void Initialize(IBuildServerWatcher buildServerWatcher, ISettingsSource config)
        {
            if (this.buildServerWatcher != null)
                throw new InvalidOperationException("Already initialized");

            this.buildServerWatcher = buildServerWatcher;

            ProjectNames = config.GetString("ProjectName", "").Split(new char[]{'|'}, StringSplitOptions.RemoveEmptyEntries);
            BuildIdFilter = new Regex(config.GetString("BuildIdFilter", ""), RegexOptions.Compiled);
            var hostName = config.GetString("BuildServerUrl", null);
            if (!string.IsNullOrEmpty(hostName))
            {
                httpClient = new HttpClient
                    {
                        Timeout = TimeSpan.FromMinutes(2),
                        BaseAddress = hostName.Contains("://")
                                          ? new Uri(hostName, UriKind.Absolute)
                                          : new Uri(string.Format("{0}://{1}", Uri.UriSchemeHttp, hostName), UriKind.Absolute)
                    };
                httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));

                var buildServerCredentials = buildServerWatcher.GetBuildServerCredentials(this, true);

                UpdateHttpClientOptions(buildServerCredentials);

                if (ProjectNames.Length > 0)
                {
                    getBuildTypesTask.Clear();
                    foreach (var name in ProjectNames)
                    {
                        getBuildTypesTask.Add(
                            GetProjectFromNameXmlResponseAsync(name, CancellationToken.None)
                            .ContinueWith(
                            task => from element in task.Result.XPathSelectElements("/project/buildTypes/buildType")
                                   select element.Attribute("id").Value,
                           TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.AttachedToParent));
                    }

                }
            }
        }
예제 #14
0
        public void Initialize(
            IBuildServerWatcher buildServerWatcher,
            ISettingsSource config,
            Action openSettings,
            Func <ObjectId, bool> isCommitInRevisionGrid = null)
        {
            if (_buildServerWatcher != null)
            {
                throw new InvalidOperationException("Already initialized");
            }

            _buildServerWatcher = buildServerWatcher;

            ProjectName = config.GetString("GitLabProjectName", string.Empty);
            HostName    = config.GetString("GitLabBuildServerUrl", string.Empty);
            var token = config.GetString("GitLabToken", string.Empty);

            InitializeGitLabClient(HostName, token);

            _buildDefinitionsTask = ThreadHelper.JoinableTaskFactory.RunAsync(() =>
                                                                              _gitLabClient.Pipelines.GetAsync(ProjectName, _ => _.Scope = PipelineScope.All));
        }
예제 #15
0
        public void Initialize(IBuildServerWatcher buildServerWatcher, ISettingsSource config)
        {
            if (this.buildServerWatcher != null)
            {
                throw new InvalidOperationException("Already initialized");
            }

            this.buildServerWatcher = buildServerWatcher;

            ProjectName = config.GetString("ProjectName", null);
            var hostName = config.GetString("BuildServerUrl", null);

            if (!string.IsNullOrEmpty(hostName))
            {
                httpClient = new HttpClient
                {
                    Timeout     = TimeSpan.FromMinutes(2),
                    BaseAddress = hostName.Contains("://")
                                          ? new Uri(hostName, UriKind.Absolute)
                                          : new Uri(string.Format("{0}://{1}", Uri.UriSchemeHttp, hostName), UriKind.Absolute)
                };
                httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));

                var buildServerCredentials = buildServerWatcher.GetBuildServerCredentials(this, true);

                UpdateHttpClientOptions(buildServerCredentials);

                if (!string.IsNullOrEmpty(ProjectName))
                {
                    getBuildTypesTask =
                        GetProjectFromNameXmlResponseAsync(ProjectName, CancellationToken.None)
                        .ContinueWith(
                            task => from element in task.Result.XPathSelectElements("/project/buildTypes/buildType")
                            select element.Attribute("id").Value,
                            TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.AttachedToParent);
                }
            }
        }
예제 #16
0
        public void Initialize(IBuildServerWatcher buildServerWatcher, ISettingsSource config, Func <string, bool> isCommitInRevisionGrid)
        {
            if (_buildServerWatcher != null)
            {
                throw new InvalidOperationException("Already initialized");
            }

            _buildServerWatcher = buildServerWatcher;

            var projectName = config.GetString("ProjectName", null);
            var hostName    = config.GetString("BuildServerUrl", null);

            if (!string.IsNullOrEmpty(hostName) && !string.IsNullOrEmpty(projectName))
            {
                var baseAdress = hostName.Contains("://")
                                     ? new Uri(hostName, UriKind.Absolute)
                                     : new Uri(string.Format("{0}://{1}:8080", Uri.UriSchemeHttp, hostName), UriKind.Absolute);

                _httpClient = new HttpClient(new HttpClientHandler {
                    UseDefaultCredentials = true
                })
                {
                    Timeout     = TimeSpan.FromMinutes(2),
                    BaseAddress = baseAdress
                };

                var buildServerCredentials = buildServerWatcher.GetBuildServerCredentials(this, true);

                UpdateHttpClientOptions(buildServerCredentials);

                string[] projectUrls = _buildServerWatcher.ReplaceVariables(projectName)
                                       .Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var projectUrl in projectUrls.Select(s => baseAdress + "job/" + s.Trim() + "/"))
                {
                    AddGetBuildUrl(projectUrl);
                }
            }
        }
예제 #17
0
        public void Initialize(IBuildServerWatcher buildServerWatcher, ISettingsSource config)
        {
            if (this.buildServerWatcher != null)
                throw new InvalidOperationException("Already initialized");

            this.buildServerWatcher = buildServerWatcher;

            ProjectNames = config.GetString("ProjectName", "").Split(new char[]{'|'}, StringSplitOptions.RemoveEmptyEntries);

            var buildIdFilerSetting = config.GetString("BuildIdFilter", "");
            if (!BuildServerSettingsHelper.IsRegexValid(buildIdFilerSetting))
            {
                return;
            }
            BuildIdFilter = new Regex(buildIdFilerSetting, RegexOptions.Compiled);
            var hostName = config.GetString("BuildServerUrl", null);
            LogAsGuestUrlParameter = config.GetBool("LogAsGuest", false) ? "&guest=1" : string.Empty;

            if (!string.IsNullOrEmpty(hostName))
            {
                InitializeHttpClient(hostName, () => buildServerWatcher.GetBuildServerCredentials(this, true));

                if (ProjectNames.Length > 0)
                {
                    getBuildTypesTask.Clear();
                    foreach (var name in ProjectNames)
                    {
                        getBuildTypesTask.Add(
                            GetProjectFromNameXmlResponseAsync(name, CancellationToken.None)
                            .ContinueWith(
                            task => from element in task.Result.XPathSelectElements("/project/buildTypes/buildType")
                                   select element.Attribute("id").Value,
                           TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.AttachedToParent));
                    }
                }
            }
        }
예제 #18
0
 public void Initialize(IBuildServerWatcher buildServerWatcher, ISettingsSource config, Action openSettings, Func <ObjectId, bool>?isCommitInRevisionGrid = null)
 {
 }
예제 #19
0
        public void Initialize(
            IBuildServerWatcher buildServerWatcher,
            ISettingsSource config,
            Func <ObjectId, bool> isCommitInRevisionGrid = null)
        {
            if (_buildServerWatcher != null)
            {
                throw new InvalidOperationException("Already initialized");
            }

            _buildServerWatcher     = buildServerWatcher;
            _isCommitInRevisionGrid = isCommitInRevisionGrid;
            var accountName = config.GetString("AppVeyorAccountName", null);

            _accountToken = config.GetString("AppVeyorAccountToken", null);
            var projectNamesSetting = config.GetString("AppVeyorProjectName", null);

            if (accountName.IsNullOrWhiteSpace() && projectNamesSetting.IsNullOrWhiteSpace())
            {
                return;
            }

            _shouldLoadTestResults = config.GetBool("AppVeyorLoadTestsResults", false);

            _fetchBuilds = new HashSet <ObjectId>();

            _httpClientAppVeyor = GetHttpClient(WebSiteUrl, _accountToken);

            var useAllProjects = string.IsNullOrWhiteSpace(projectNamesSetting);

            string[] projectNames = null;
            if (!useAllProjects)
            {
                projectNames = _buildServerWatcher.ReplaceVariables(projectNamesSetting)
                               .Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
            }

            if (Projects.Count == 0 ||
                (!useAllProjects && Projects.Keys.Intersect(projectNames).Count() != projectNames.Length))
            {
                Projects.Clear();
                if (_accountToken.IsNullOrWhiteSpace())
                {
                    FillProjectsFromSettings(accountName, projectNames);
                }
                else
                {
                    if (accountName.IsNullOrWhiteSpace())
                    {
                        return;
                    }

                    ThreadHelper.JoinableTaskFactory.Run(
                        async() =>
                    {
                        var result = await GetResponseAsync(_httpClientAppVeyor, ApiBaseUrl, CancellationToken.None).ConfigureAwait(false);

                        if (result.IsNullOrWhiteSpace())
                        {
                            return;
                        }

                        var projects = JArray.Parse(result);
                        foreach (var project in projects)
                        {
                            var projectId   = project["slug"].ToString();
                            projectId       = accountName.Combine("/", projectId);
                            var projectName = project["name"].ToString();
                            var projectObj  = new Project
                            {
                                Name     = projectName,
                                Id       = projectId,
                                QueryUrl = BuildQueryUrl(projectId)
                            };

                            if (useAllProjects || projectNames.Contains(projectObj.Name))
                            {
                                Projects.Add(projectObj.Name, projectObj);
                            }
                        }
                    });
                }
            }

            var builds = Projects.Where(p => useAllProjects || projectNames.Contains(p.Value.Name)).Select(p => p.Value);

            _allBuilds =
                FilterBuilds(builds.SelectMany(project => QueryBuildsResults(project)));
        }
예제 #20
0
        public void Initialize(IBuildServerWatcher buildServerWatcher, ISettingsSource config,
                               Func <string, bool> isCommitInRevisionGrid)
        {
            if (_buildServerWatcher != null)
            {
                throw new InvalidOperationException("Already initialized");
            }

            IsCommitInRevisionGrid = isCommitInRevisionGrid;
            var accountName = config.GetString("AppVeyorAccountName", null);

            _accountToken = config.GetString("AppVeyorAccountToken", null);
            if (string.IsNullOrEmpty(accountName) || string.IsNullOrEmpty(_accountToken))
            {
                return;
            }

            _shouldLoadTestResults = config.GetBool("AppVeyorLoadTestsResults", false);
            _gitHubToken           = config.GetString("AppVeyorGitHubToken", null);
            _shouldDisplayGitHubPullRequestBuilds = config.GetBool("AppVeyorDisplayGitHubPullRequests", false) &&
                                                    !string.IsNullOrWhiteSpace(_gitHubToken);

            _fetchBuilds        = new HashSet <string>();
            _buildServerWatcher = buildServerWatcher;
            var projectNamesSetting = config.GetString("AppVeyorProjectName", null);

            _httpClientAppVeyor = GetHttpClient(WebSiteUrl, _accountToken);

            _httpClientGitHub = GetHttpClient("https://api.github.com/", _gitHubToken);
            _httpClientGitHub.DefaultRequestHeaders.Add("User-Agent", "Anything");

            var useAllProjets = string.IsNullOrWhiteSpace(projectNamesSetting);

            string[] projectNames = null;
            if (!useAllProjets)
            {
                projectNames = projectNamesSetting.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
            }
            if (Projects.Count == 0 ||
                (!useAllProjets && Projects.Keys.Intersect(projectNames).Count() != projectNames.Length))
            {
                GetResponseAsync(_httpClientAppVeyor, ApiBaseUrl, CancellationToken.None)
                .ContinueWith(
                    task =>
                {
                    var projects = JArray.Parse(task.Result);
                    foreach (var project in projects)
                    {
                        var projectId   = project["slug"].ToString();
                        var projectName = project["name"].ToString();
                        if (useAllProjets)
                        {
                            Projects.Add(projectName, new Project
                            {
                                Name     = projectName,
                                Id       = projectId,
                                QueryUrl = BuildQueryUrl(accountName, projectId)
                            });
                        }
                        else
                        {
                            if (projectNames.Contains(projectName))
                            {
                                Projects.Add(projectName,
                                             new Project
                                {
                                    Name     = projectName,
                                    Id       = projectId,
                                    QueryUrl = BuildQueryUrl(accountName, projectId)
                                });
                            }
                        }
                    }
                }).Wait();
            }
            var builds = Projects.Where(p => useAllProjets || projectNames.Contains(p.Value.Name)).Select(p => p.Value);

            _allBuilds =
                FilterBuilds(builds.SelectMany(project => QueryBuildsResults(accountName, project.Id, project.QueryUrl)));
        }
예제 #21
0
        public void Initialize(
            IBuildServerWatcher buildServerWatcher,
            ISettingsSource config,
            Action openSettings,
            Func <ObjectId, bool> isCommitInRevisionGrid = null)
        {
            if (_buildServerWatcher is not null)
            {
                throw new InvalidOperationException("Already initialized");
            }

            _buildServerWatcher     = buildServerWatcher;
            _isCommitInRevisionGrid = isCommitInRevisionGrid;
            string accountName  = config.GetString("AppVeyorAccountName", null);
            string accountToken = config.GetString("AppVeyorAccountToken", null);

            _shouldLoadTestResults = config.GetBool("AppVeyorLoadTestsResults", false);

            _fetchBuilds = new HashSet <ObjectId>();

            _httpClientAppVeyor = GetHttpClient(WebSiteUrl, accountToken);

            // projectId has format accountName/repoName
            // accountName may be any accessible project (for instance upstream)
            // if AppVeyorAccountName is set, projectNamesSetting may exclude the accountName part
            string projectNamesSetting = config.GetString("AppVeyorProjectName", "");
            var    projectNames        = _buildServerWatcher.ReplaceVariables(projectNamesSetting)
                                         .Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries)
                                         .Where(p => p.Contains("/") || !string.IsNullOrEmpty(accountName))
                                         .Select(p => p.Contains("/") ? p : accountName.Combine("/", p))
                                         .ToList();

            if (projectNames.Count == 0)
            {
                if (string.IsNullOrWhiteSpace(accountName) || string.IsNullOrWhiteSpace(accountToken))
                {
                    // No projectIds in settings, cannot query
                    return;
                }

                // No settings, query projects for this account
                ThreadHelper.JoinableTaskFactory.Run(
                    async() =>
                {
                    // v2 tokens requires a separate prefix
                    // (Documentation specifies that this is applicable for all requests, not the case though)
                    string apiBaseUrl = !string.IsNullOrWhiteSpace(accountName) && !string.IsNullOrWhiteSpace(accountToken) && accountToken.StartsWith("v2.")
                            ? $"{WebSiteUrl}/api/account/{accountName}/projects/"
                            : ApiBaseUrl;

                    // get the project ids for this account - no possibility to check if they are for the current repo
                    var result = await GetResponseAsync(_httpClientAppVeyor, apiBaseUrl, CancellationToken.None).ConfigureAwait(false);

                    if (string.IsNullOrWhiteSpace(result))
                    {
                        return;
                    }

                    foreach (var project in JArray.Parse(result))
                    {
                        // "slug" and "name" are normally the same
                        var repoName  = project["slug"].ToString();
                        var projectId = accountName.Combine("/", repoName);
                        projectNames.Add(projectId);
                    }
                });
            }

            _allBuilds = FilterBuilds(projectNames.SelectMany(project => QueryBuildsResults(project)));

            return;
예제 #22
0
        public void Initialize(IBuildServerWatcher buildServerWatcher, ISettingsSource config)
        {
            if (_buildServerWatcher != null)
                throw new InvalidOperationException("Already initialized");

            _buildServerWatcher = buildServerWatcher;

            var projectName = config.GetString("ProjectName", null);
            var hostName = config.GetString("BuildServerUrl", null);

            if (!string.IsNullOrEmpty(hostName) && !string.IsNullOrEmpty(projectName))
            {
                var baseAdress = hostName.Contains("://")
                                     ? new Uri(hostName, UriKind.Absolute)
                                     : new Uri(string.Format("{0}://{1}:8080", Uri.UriSchemeHttp, hostName), UriKind.Absolute);

                _httpClient = new HttpClient
                    {
                        Timeout = TimeSpan.FromMinutes(2),
                        BaseAddress = baseAdress
                    };

                var buildServerCredentials = buildServerWatcher.GetBuildServerCredentials(this, true);

                UpdateHttpClientOptions(buildServerCredentials);

                var projectUrl = baseAdress + "job/" + projectName + "/";

                _getBuildUrls = GetResponseAsync(FormatToGetJson(projectUrl), CancellationToken.None)
                    .ContinueWith(
                        task =>
                            {
                                JObject jobDescription = JObject.Parse(task.Result);
                                return jobDescription["builds"].Select(b => b["url"].ToObject<string>());
                            },
                        TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.AttachedToParent);
            }
        }