Exemplo n.º 1
0
        public override async Task ExecuteAsync(IOperationExecutionContext context)
        {
            var gitlab = new GitLabClient(this.ApiUrl, this.UserName, this.Password, this.GroupName);
            var data   = new Dictionary <string, object> {
                ["title"] = this.Title
            };

            if (this.AdditionalProperties != null)
            {
                foreach (var p in this.AdditionalProperties)
                {
                    data.Add(p.Key, p.Key == "confidential" ? bool.Parse(p.Value?.ToString()) : p.Key == "weight" ? int.Parse(p.Value?.ToString()) : p.Value);
                }
            }
            if (!string.IsNullOrEmpty(this.Body))
            {
                data.Add("description", this.Body);
            }
            if (this.Labels != null)
            {
                data.Add("labels", string.Join(",", this.Labels));
            }
            if (this.Assignees != null)
            {
                data.Add("assignee_ids", (await Task.WhenAll(this.Assignees.Select(name => gitlab.FindUserAsync(name, context.CancellationToken))).ConfigureAwait(false)).Where(id => id.HasValue));
            }
            if (!string.IsNullOrEmpty(this.Milestone))
            {
                data.Add("milestone_id", await gitlab.CreateMilestoneAsync(this.Milestone, this.ProjectName, context.CancellationToken).ConfigureAwait(false));
            }
            this.IssueId = await gitlab.CreateIssueAsync(this.ProjectName, data, context.CancellationToken).ConfigureAwait(false);
        }
Exemplo n.º 2
0
        public override async Task ConfigureAsync(IOperationExecutionContext context)
        {
            var gitlab = new GitLabClient(this.Template.ApiUrl, this.Template.UserName, this.Template.Password, this.Template.GroupName);
            var id     = await gitlab.CreateMilestoneAsync(this.Template.Title, this.Template.ProjectName, context.CancellationToken).ConfigureAwait(false);

            var data = new Dictionary <string, object> {
                ["title"] = this.Template.Title
            };

            if (this.Template.StartDate != null)
            {
                data.Add("start_date", AH.NullIf(this.Template.StartDate, string.Empty));
            }
            if (this.Template.DueDate != null)
            {
                data.Add("due_date", AH.NullIf(this.Template.DueDate, string.Empty));
            }
            if (this.Template.Description != null)
            {
                data.Add("description", this.Template.Description);
            }
            if (this.Template.State.HasValue)
            {
                data.Add("state_event", this.Template.State == GitLabMilestoneConfiguration.OpenOrClosed.open ? "activate" : "close");
            }

            await gitlab.UpdateMilestoneAsync(id, this.Template.ProjectName, data, context.CancellationToken).ConfigureAwait(false);
        }