示例#1
0
        public async Task <bool> UpdateAzureDevOpsSetting(string patToken, TableStorageAuth tableStorageAuth, string settingsTable,
                                                          string organization, string project, string repository, string branch, string buildName, string buildId, string resourceGroupName, int itemOrder)
        {
            string partitionKey          = "AzureDevOpsSettings";
            string rowKey                = CreateAzureDevOpsSettingsPartitionKey(organization, project, repository, buildName);
            AzureDevOpsSettings settings = new AzureDevOpsSettings
            {
                RowKey                  = rowKey,
                PatToken                = patToken,
                Organization            = organization,
                Project                 = project,
                Repository              = repository,
                Branch                  = branch,
                BuildName               = buildName,
                BuildId                 = buildId,
                ProductionResourceGroup = resourceGroupName,
                ItemOrder               = itemOrder
            };

            string json = JsonConvert.SerializeObject(settings);
            AzureStorageTableModel newItem = new AzureStorageTableModel(partitionKey, rowKey, json);
            TableStorageCommonDA   tableDA = new TableStorageCommonDA(tableStorageAuth, settingsTable);

            return(await tableDA.SaveItem(newItem));
        }
示例#2
0
 public AzureDevOpsIterationWorkItemsRetriever(HttpClient authorizedAuthorizedHttpClient,
                                               IOptions <AzureDevOpsSettings> azureDevOpsSettingsOptions
                                               )
 {
     _azureDevOpsSettings  = azureDevOpsSettingsOptions.Value;
     _authorizedHttpClient = authorizedAuthorizedHttpClient;
 }
示例#3
0
 public DescriptiveTitleActor(ILogger logger, IOptions <AzureDevOpsSettings> azureDevOpsSettingsOptions,
                              IOptions <List <DevOpsChatUserMap> > devOpsChatUserMapOptions, IOptions <CurrentIterationInfo> currentIterationOptions)
 {
     _logger = logger;
     _azureDevOpsSettings = azureDevOpsSettingsOptions.Value;
     _devOpsChatUserMaps  = devOpsChatUserMapOptions.Value;
     _currentIteration    = currentIterationOptions.Value;
     Receive <IReadOnlyList <JObject> >(HandleIncomingWorkItems);
 }
示例#4
0
        private HttpClient GetHttpClientAsync(AzureDevOpsSettings azureDevOps, string accessToken)
        {
            // Trigger Azure DevOps build
            HttpClient httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
            httpClient.BaseAddress = new Uri($"https://dev.azure.com/{azureDevOps.Organization}/{azureDevOps.Project}/_apis/");
            return(httpClient);
        }
        private static CurrentIterationInfo GetCurrentIterationSettings(HttpClient azureAuthorizedHttpClient,
                                                                        AzureDevOpsSettings azureDevOpsSettings)
        {
            var currentIterationContent = azureAuthorizedHttpClient.GetStringAsync(
                $"https://dev.azure.com/{azureDevOpsSettings.Organization}/{azureDevOpsSettings.Project}/{azureDevOpsSettings.Team}/" +
                $"_apis/work/teamsettings/iterations?api-version=6.1-preview.1&$timeframe=current").Result;

            var iterationJson = JObject.Parse(currentIterationContent).SelectToken($".value[0]") as JObject;

            var iterationInfo = iterationJson !.ToObject <CurrentIterationInfo>();

            iterationInfo !.FinishDate = DateTime.Parse(iterationJson !["attributes"] !["finishDate"] !.Value <string>());
        private static IHttpClientBuilder AddAzureDevOpsTypedHttpClient(this IServiceCollection services, IConfiguration config)
        {
            AzureDevOpsSettings azureDevOpsSettings = config.GetSection("Integrations:AzureDevOpsSettings").Get <AzureDevOpsSettings>();
            string token = config["AccessTokenDevOps"];

            return(services.AddHttpClient <IAzureDevOpsBuildClient, AzureDevOpsBuildClient>(client =>
            {
                client.BaseAddress = new Uri($"{azureDevOpsSettings.BaseUri}build/builds/");
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", token);
            }).AddHttpMessageHandler <EnsureSuccessHandler>());
        }
示例#7
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="releaseRepository">Document db repository</param>
 /// <param name="httpContextAccessor">IHttpContextAccessor</param>
 /// <param name="azureDevOpsBuildClient">IAzureDevOpsBuildClient</param>
 /// <param name="azureDevOpsOptions">IOptionsMonitor of Type AzureDevOpsSettings</param>
 public ReleaseService(
     ReleaseRepository releaseRepository,
     IHttpContextAccessor httpContextAccessor,
     IAzureDevOpsBuildClient azureDevOpsBuildClient,
     IOptionsMonitor <AzureDevOpsSettings> azureDevOpsOptions)
 {
     _azureDevOpsSettings    = azureDevOpsOptions.CurrentValue;
     _releaseRepository      = releaseRepository;
     _azureDevOpsBuildClient = azureDevOpsBuildClient;
     _httpContext            = httpContextAccessor.HttpContext;
     _org = _httpContext.GetRouteValue("org")?.ToString();
     _app = _httpContext.GetRouteValue("app")?.ToString();
 }
示例#8
0
 /// <summary>
 /// Constructor
 /// </summary>
 public DeploymentService(
     IOptionsMonitor <AzureDevOpsSettings> azureDevOpsOptions,
     IAzureDevOpsBuildClient azureDevOpsBuildClient,
     IHttpContextAccessor httpContextAccessor,
     IDeploymentRepository deploymentRepository,
     IReleaseRepository releaseRepository,
     IApplicationInformationService applicationInformationService)
 {
     _azureDevOpsBuildClient        = azureDevOpsBuildClient;
     _deploymentRepository          = deploymentRepository;
     _releaseRepository             = releaseRepository;
     _applicationInformationService = applicationInformationService;
     _azureDevOpsSettings           = azureDevOpsOptions.CurrentValue;
     _httpContext = httpContextAccessor.HttpContext;
     _org         = _httpContext.GetRouteValue("org")?.ToString();
     _app         = _httpContext.GetRouteValue("app")?.ToString();
 }
        /// <summary>
        /// Initialize for the tests
        /// </summary>
        public ReleaseServiceTests()
        {
            _releaseDbRepoMock           = new Mock <ReleaseRepository>();
            _azureDevOpsBuildServiceMock = new Mock <IAzureDevOpsBuildService>();
            _sourceControlMock           = new Mock <ISourceControl>();
            _giteaWrapperMock            = new Mock <IGitea>();

            Mock <IHttpContextAccessor> httpContextAccessorMock = new Mock <IHttpContextAccessor>();
            DefaultHttpContext          context = new DefaultHttpContext();

            httpContextAccessorMock.Setup(_ => _.HttpContext).Returns(context);
            AzureDevOpsSettings azureDevOpsSettings = new AzureDevOpsSettings();
            Mock <IOptionsMonitor <AzureDevOpsSettings> > optionsMonitorMock = new Mock <IOptionsMonitor <AzureDevOpsSettings> >();

            optionsMonitorMock.Setup(x => x.CurrentValue).Returns(azureDevOpsSettings);

            _sut = new ReleaseService(
                _releaseDbRepoMock.Object,
                httpContextAccessorMock.Object,
                _azureDevOpsBuildServiceMock.Object,
                optionsMonitorMock.Object);
        }
示例#10
0
        public async Task <Revision> QueueBuild(AzureDevOpsSettings azureDevOps,
                                                QueueBuildRequest queueBuildRequest, string accessToken)
        {
            var credentials = new VssOAuthAccessTokenCredential(accessToken);
            var connection  = new VssConnection(
                new Uri($"https://dev.azure.com/{azureDevOps.Organization}"),
                credentials);

            try
            {
                var buildClient = connection.GetClient <BuildHttpClient>();
                var definition  = await buildClient.GetDefinitionAsync(azureDevOps.Project, int.Parse(azureDevOps.BuildDefinition));

                Dictionary <string, string> parameters = queueBuildRequest.Variables.ToDictionary(v => v.Key, v => v.Value);
                Build build = new Build
                {
                    Definition   = definition,
                    Project      = definition.Project,
                    SourceBranch = queueBuildRequest.Branch,
                    Parameters   = JsonConvert.SerializeObject(parameters)
                };
                var response = await buildClient.QueueBuildAsync(build);

                var revision = new Revision()
                {
                    RevisionNumber = response.Id.ToString(),
                    Requestor      = response.RequestedBy.DisplayName,
                    CreatedTime    = DateTimeOffset.Now
                };

                return(revision);
            }
            catch (Exception)
            {
                return(null);
            }
        }
示例#11
0
        public async Task <Release> QueueRelease(AzureDevOpsSettings azureDevOps,
                                                 QueueReleaseRequest queueReleaseRequest, string accessToken, string projectName, string revisionNumber, string commitNumber)
        {
            Dictionary <string, string> parameters = new Dictionary <string, string>()
            {
                { "DUSTPARTICLE_PROJECT", azureDevOps.Project },
                { "DUSTPARTICLE_PIPELINE", azureDevOps.ArtifactResourcePipeline },
                { "DUSTPARTICLE_BUILDID", revisionNumber },
                { "DUSTPARTICLE_SOURCEVERSION", commitNumber },
                { "DUSTPARTICLE_RELEASETAG", queueReleaseRequest.Name }
            };
            TriggerBuildRequest request = new TriggerBuildRequest()
            {
                Parameters = JsonConvert.SerializeObject(parameters),
                Definition = new BuildDefinition()
                {
                    Id = azureDevOps.ReleaseDefinition
                }
            };

            string     url        = "build/builds?api-version=5.1";
            HttpClient httpClient = GetHttpClientAsync(azureDevOps, accessToken);
            var        response   = await httpClient.PostAsJsonAsync(url, request);

            if (response.IsSuccessStatusCode)
            {
                Release returnRelease = new Release();
                returnRelease.Status         = "InProgress";
                returnRelease.ProjectName    = projectName;
                returnRelease.RevisionNumber = revisionNumber;
                returnRelease.ReleaseLabel   = queueReleaseRequest.Name;
                returnRelease.ReleaseNotes   = queueReleaseRequest.ReleaseNotes;
                return(returnRelease);
            }
            return(null);
        }
示例#12
0
 public PullRequestClientFactory(IOptions <AzureDevOpsSettings> settings)
 {
     this.settings = settings.Value;
 }
示例#13
0
 private IterationWorkItemsRetrieverTransform(AzureDevOpsSettings settings, HttpClient httpClient)
 {
     _settings   = settings;
     _httpClient = httpClient;
 }