Beispiel #1
0
 public LabelCreateRequestValidatorTest()
 {
     request = new LabelCreateRequest()
     {
         Name = "test"
     };
     validator = new LabelCreateRequestValidator();
 }
        /// <summary>
        ///     Create a label
        /// </summary>
        /// <param name="request">label to create</param>
        /// <returns>Added label</returns>
        public async Task <Label> CreateLabelAsync(LabelCreateRequest request)
        {
            Arguments.CheckNotNull(request, nameof(request));

            var response = await _service.PostLabelsAsync(request).ConfigureAwait(false);

            return(response.Label);
        }
        /// <summary>
        ///     Clone a label.
        /// </summary>
        /// <param name="clonedName">name of cloned label</param>
        /// <param name="label">label to clone</param>
        /// <returns>cloned label</returns>
        public async Task <Label> CloneLabelAsync(string clonedName, Label label)
        {
            Arguments.CheckNonEmptyString(clonedName, nameof(clonedName));
            Arguments.CheckNotNull(label, nameof(label));

            var cloned =
                new LabelCreateRequest(label.OrgID, clonedName, new Dictionary <string, string>(label.Properties));

            return(await CreateLabelAsync(cloned));
        }
        public async Task CreateLabelEmptyProperties()
        {
            var name = GenerateName("Cool Resource");

            var request = new LabelCreateRequest(_organization.Id, name);

            var label = await _labelsApi.CreateLabelAsync(request);

            Assert.IsNotNull(label);
            Assert.IsNotEmpty(label.Id);
            Assert.AreEqual(name, label.Name);
        }
Beispiel #5
0
        public async Task <LabelCreateResponse> CreateLabel(LabelCreateRequest request)
        {
            var response = new LabelCreateResponse();

            var currentUser = _cacheManager.GetCachedCurrentUser(request.CurrentUserId);

            if (!currentUser.IsAdmin)
            {
                response.SetInvalid();
                return(response);
            }

            var project = await _projectRepository.Select(x => x.Uid == request.ProjectUid);

            if (project.IsNotExist())
            {
                response.SetInvalidBecauseNotFound("project");
                return(response);
            }

            if (project.OrganizationId != currentUser.OrganizationId)
            {
                response.SetInvalid();
                return(response);
            }

            if (await _organizationRepository.Any(x => x.Id == project.OrganizationId && !x.IsActive))
            {
                response.SetInvalid();
                return(response);
            }

            if (await _labelRepository.Any(x => x.Key == request.LabelKey && x.ProjectId == project.Id))
            {
                response.ErrorMessages.Add("label_key_must_be_unique");
                response.Status = ResponseStatus.Failed;
                return(response);
            }

            var label     = _labelFactory.CreateEntityFromRequest(request, project);
            var uowResult = await _labelUnitOfWork.DoCreateWork(request.CurrentUserId, label);

            if (uowResult)
            {
                response.Item   = _labelFactory.CreateDtoFromEntity(label);
                response.Status = ResponseStatus.Success;
                return(response);
            }

            response.SetFailed();
            return(response);
        }
Beispiel #6
0
        public Label CreateEntityFromRequest(LabelCreateRequest request, Project project)
        {
            var entity = new Label();

            entity.Key         = request.LabelKey;
            entity.Name        = request.LabelKey;
            entity.Description = request.Description;

            entity.OrganizationId   = project.OrganizationId;
            entity.OrganizationUid  = project.OrganizationUid;
            entity.OrganizationName = project.OrganizationName;
            entity.ProjectId        = project.Id;
            entity.ProjectUid       = project.Uid;
            entity.ProjectName      = project.Name;
            entity.IsActive         = true;

            return(entity);
        }
        public async Task <ActionResult <LabelCreateResult> > CreateLabels(
            string toOwnerName, string toRepoName,
            [FromBody] LabelCreateRequest labelCreateRequest)
        {
            var accessToken = await HttpContext.GetTokenAsync("access_token");

            var gitHub = GitHubUtils.GetGitHubClient(accessToken);

            var destinationLabels = await gitHub.Issue.Labels.GetAllForRepository(toOwnerName, toRepoName);

            var listOfLabelsToCreate = labelCreateRequest.Labels
                                       .Where(labelNeeded =>
                                              !destinationLabels
                                              .Any(destinationLabel =>
                                                   string.Equals(
                                                       labelNeeded.Text,
                                                       destinationLabel.Name,
                                                       StringComparison.OrdinalIgnoreCase)))
                                       .ToList();

            try
            {
                foreach (var labelToCreate in listOfLabelsToCreate)
                {
                    await gitHub.Issue.Labels.Create(toOwnerName, toRepoName, new NewLabel(labelToCreate.Text, labelToCreate.Color));
                }

                return(Ok(
                           new LabelCreateResult
                {
                    LabelsCreated = listOfLabelsToCreate,
                }));
            }
            catch (Exception ex)
            {
                return(BadRequest(
                           new LabelCreateResult
                {
                    Exception = ex,
                }));
            }
        }
Beispiel #8
0
        public async Task <ActionResult <LabelCreateResult> > CreateLabels(
            string toOwnerName, string toRepoName,
            [FromBody] LabelCreateRequest labelCreateRequest)
        {
            try
            {
                var labelCreateResult = await IssueMoverService.CreateLabels(toOwnerName, toRepoName, labelCreateRequest);

                return(Ok(labelCreateResult));
            }
            catch (Exception ex)
            {
                return(BadRequest(
                           new LabelCreateResult
                {
                    ExceptionMessage = ex.Message,
                    ExceptionStackTrace = ex.StackTrace,
                }));
            }
        }
Beispiel #9
0
        public async Task <IActionResult> Create(LabelCreateModel model)
        {
            if (model.IsNotValid())
            {
                model.SetInputModelValues();
                return(View(model));
            }

            var request  = new LabelCreateRequest(CurrentUser.Id, model.OrganizationUid, model.ProjectUid, model.Key, model.Description);
            var response = await _labelService.CreateLabel(request);

            if (response.Status.IsNotSuccess)
            {
                model.MapMessages(response);
                model.SetInputModelValues();
                return(View(model));
            }

            CurrentUser.IsActionSucceed = true;
            return(Redirect($"/Label/Detail/{response.Item.Uid}"));
        }
        /// <summary>
        ///     Create a label
        /// </summary>
        /// <param name="request">label to create</param>
        /// <returns>Added label</returns>
        public async Task <Label> CreateLabelAsync(LabelCreateRequest request)
        {
            Arguments.CheckNotNull(request, nameof(request));

            return(await _service.PostLabelsAsync(request).ContinueWith(t => t.Result.Label));
        }
        public async Task <LabelCreateResult> CreateLabels(string destinationOwner, string destinationRepo, LabelCreateRequest labelCreateRequest)
        {
            var gitHub = await GitHubAccessor.GetGitHubClient();

            var destinationLabels = await gitHub.Issue.Labels.GetAllForRepository(destinationOwner, destinationRepo);

            var listOfLabelsToCreate = labelCreateRequest.Labels
                                       .Where(labelNeeded =>
                                              !destinationLabels
                                              .Any(destinationLabel =>
                                                   string.Equals(
                                                       labelNeeded.Text,
                                                       destinationLabel.Name,
                                                       StringComparison.OrdinalIgnoreCase)))
                                       .ToList();

            foreach (var labelToCreate in listOfLabelsToCreate)
            {
                await gitHub.Issue.Labels.Create(destinationOwner, destinationRepo, new NewLabel(labelToCreate.Text, labelToCreate.Color));
            }

            return(new LabelCreateResult
            {
                LabelsCreated = listOfLabelsToCreate,
            });
        }
 public async Task <LabelCreateResult> CreateLabels(string destinationOwner, string destinationRepo, LabelCreateRequest labelCreateRequest)
 {
     return(await Http.PostJsonAsync <LabelCreateResult>($"https://localhost:44347/api/createlabels/{destinationOwner}/{destinationRepo}", labelCreateRequest));
 }
        /// <summary>
        ///     Create a label
        /// </summary>
        /// <param name="request">label to create</param>
        /// <returns>Added label</returns>
        public async Task <Label> CreateLabelAsync(LabelCreateRequest request)
        {
            Arguments.CheckNotNull(request, nameof(request));

            return((await _service.PostLabelsAsync(request)).Label);
        }
        public static LabelCreateRequest GetLabelCreateRequest()
        {
            var request = new LabelCreateRequest(CurrentUserId, UidOne, UidOne, StringOne, StringOne);

            return(request);
        }