Exemple #1
0
        public async Task <HookResponse> Hook([FromBody] HookRequest request)
        {
            var words = request.Text.Trim().Split(' ');

            if (words.Length != 2)
            {
                return(new HookResponse
                {
                    Text = $"You must specify packages version. Example: \"{request.TriggerWord} 2.6.4\""
                });
            }

            var packageVersion = words.Last();

            var options = _configuration.GetSection("artifactory").Get <ArtifactoryOptions>();

            var artifactory = new Artifactory(options.Host, options.User, options.Password);

            var searchQueryBuilds = options.Packages.Select(p =>
            {
                Action <ISearchQueryBuilder> action = (ISearchQueryBuilder q) =>
                                                      q.WhereName().Match($"{p}*{packageVersion}*");

                return(action);
            }).ToArray();

            var artifactsList = await artifactory.Search()
                                .Or(searchQueryBuilds)
                                .Build()
                                .Execute();

            var artifacts = artifactsList.Results.Select(a =>
                                                         new ArtifactModel(a, options.PackageNamePattern, ":white_check_mark:"))
                            .GroupBy(a => a.Name)
                            .Select(gr => gr.OrderByDescending(it => it.Version).First())
                            .ToList();

            foreach (var notFoundPackage in options.Packages.Where(p => !artifacts.Any(a => a.Name == p)))
            {
                artifacts.Add(new ArtifactModel(notFoundPackage, ":x:"));
            }

            return(new HookResponse
            {
                Text = GetTable(artifacts)
            });
        }
 /// <summary>
 /// Subscribe rest hook to receive updates
 /// </summary>
 /// <param name="projectId">Project Id</param>
 /// <param name="request">Hook filter</param>
 public Task <Hook> HookSubscribeAsync(string projectId, HookRequest request)
 {
     VerifyAndSetupClient();
     return(PavilotClient.V1ProjectsHooksPostAsync(projectId, request));
 }
Exemple #3
0
        public ActionResult Post([FromBody] HookRequest hookRequest)
        {
            _logger.LogInformation(hookRequest.text);

            return(Accepted());
        }