Example #1
0
        private async void btnCreateIssues_Click(object sender, EventArgs e)
        {
            List <IssueToCreate> list = (List <IssueToCreate>)issueToCreateBindingSource.DataSource;

            while (list.Count > 0)
            {
                IssueToCreate issue = list[0];

                // validate that the title is not empty and not the default.
                if (string.IsNullOrEmpty(issue.Title))
                {
                    MessageBox.Show(this, "Cannot create an issue with an empty or default title.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    continue;
                }

                // assign the epic to the issue!
                issue.Epic = (IssueDescription)cboEpics.SelectedItem;

                (bool success, string errorMsg) = await _issueManager.TryCreateNewIssueAsync(issue);

                if (!success)
                {
                    MessageBox.Show($"Could not create issue {issue.Title} in repository {issue.Organization}\\{issue.Repository} {Environment.NewLine} {errorMsg}");
                    continue;
                }
                else
                {
                    // update the datasource
                    list.Remove(issue);
                    issueToCreateBindingSource.DataSource = list;
                    issueToCreateBindingSource.ResetBindings(false);
                }
            }
        }
Example #2
0
        private async void BtnCreateIssue_Click(object sender, EventArgs e)
        {
            (string owner, string repo) = UIHelpers.GetRepoOwner(cboAvailableRepos.SelectedItem);

            // build up the list of labels to appen
            List <string> selectedLabels = new List <string>();

            foreach (object item in lstSelectedTags.Items)
            {
                selectedLabels.Add(item.ToString());
            }

            IssueToCreate issueToCreate = new IssueToCreate()
            {
                Repository   = repo,
                Organization = owner,
                AssignedTo   = cboAssignees.Text,
                Title        = txtIssueTitle.Text,
                Description  = txtDescription.Text,
                Labels       = selectedLabels,
                Epic         = (cboEpics.SelectedItem as IssueDescription),
                Milestone    = (cboMilestones.SelectedItem as IssueMilestone),
                Estimate     = txtEstimate.Text,
                CreateAsEpic = chkMakeEpic.Checked
            };

            // validate that the title is not empty and not the default.
            if (string.IsNullOrEmpty(issueToCreate.Title) || StringComparer.OrdinalIgnoreCase.Equals(issueToCreate.Title, s_settings.DefaultTitle))
            {
                MessageBox.Show(this, "Cannot create an issue with an empty or default title.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // have we created this issue again?
            if (issueToCreate.Equals(s_previouslyCreatedIssue))
            {
                if (MessageBox.Show(this, "This issue has already been created, re-create?", "Create duplicate?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
                {
                    // if we don't want to re-create the issue
                    return;
                }
            }

            // Try to create the issue
            (bool success, string errorMessage) = await s_issueManager.TryCreateNewIssueAsync(issueToCreate);

            // if an error happened, show the message.
            if (!success)
            {
                MessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            // store the current issue as the previous issue.
            s_previouslyCreatedIssue = issueToCreate;
        }
Example #3
0
        private async Task <List <IssueToCreate> > LoadDataFromFileAsync(string fileName)
        {
            // This loads the data from a CSV file with this format:
            // Org,Repo,Title,Description,AssignedTo,Milestone,Estimate,Labels
            using IDisposable scope = _logger.CreateScope($"Loading issues from {fileName}");

            List <IssueToCreate> issues = new List <IssueToCreate>();

            using (StreamReader sr = new StreamReader(fileName))
                using (CsvReader csv = new CsvReader(sr, CultureInfo.InvariantCulture))
                {
                    csv.Read();
                    csv.ReadHeader();

                    while (csv.Read())
                    {
                        csv.Configuration.MissingFieldFound = null;

                        IssueToCreate issue = new IssueToCreate
                        {
                            Organization = csv.GetField <string>("Organization")?.Trim(),
                            Repository   = csv.GetField <string>("Repository")?.Trim(),
                            Title        = csv.GetField <string>("Title")?.Trim(),
                            Description  = csv.GetField <string>("Description")?.Trim(),
                            AssignedTo   = csv.GetField <string>("AssignedTo")?.Trim(),
                            Estimate     = csv.GetField <string>("Estimate")?.Trim(),
                            CreateAsEpic = csv.GetField <bool>("IsEpic")
                        };

                        string milestone = csv.GetField <string>("Milestone");
                        if (!string.IsNullOrWhiteSpace(milestone))
                        {
                            milestone       = milestone.Trim();
                            issue.Milestone = await _issueManager.GetMilestoneAsync(issue.Organization, issue.Repository, milestone);
                        }

                        string labels = csv.GetField <string>("Labels");
                        if (!string.IsNullOrWhiteSpace(labels))
                        {
                            labels       = labels.Trim();
                            issue.Labels = new List <string>(labels.Split(','));
                        }

                        issues.Add(issue);
                    }
                }

            return(issues);
        }
Example #4
0
        public async Task <JsonResult> CreateIssue(string type, string priority, string summary, string description, string[] labels)
        {
            string postBody = "";

            if (type == "New Feature")
            {
                var data = new IssueToCreate();
                data.fields.project.key    = "IECF";
                data.fields.summary        = summary;
                data.fields.labels         = labels;
                data.fields.description    = description;
                data.fields.issuetype.name = type;
                data.fields.priority.name  = priority;
                data.fields.assignee.name  = "enviuser";

                postBody = ServiceStack.Text.JsonSerializer.SerializeToString(data);
            }
            if (type == "Bug")
            {
                var data = new IssueToCreateBug();
                data.fields.project.key             = "IECF";
                data.fields.summary                 = summary;
                data.fields.labels                  = labels;
                data.fields.description             = description;
                data.fields.issuetype.name          = type;
                data.fields.priority.name           = priority;
                data.fields.assignee.name           = "enviuser";
                data.fields.customfield_11410.value = "Rooted";

                postBody = ServiceStack.Text.JsonSerializer.SerializeToString(data);
            }
            HttpClient  client   = PrepareHttpClient();
            HttpContent content  = new StringContent(postBody, Encoding.UTF8, "application/json");
            var         response = await client.PostAsync("issue", content);

            string key = "";

            if (response.IsSuccessStatusCode)
            {
                dynamic jsonResponse = JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync().Result);
                key = jsonResponse.key.ToString();
            }

            else
            {
                key = "error";
            }
            string[] fileNames = Directory.GetFiles(Server.MapPath("~/JiraAttachments/"))
                                 .Select(path => Path.GetFileName(path))
                                 .ToArray();
            client.DefaultRequestHeaders.Add("X-Atlassian-Token", "nocheck");
            if (key.Length != 0)
            {
                foreach (string fileName in fileNames)
                {
                    MultipartFormDataContent content2 = null;
                    string filepath = "";
                    if (fileName.Length != 0)
                    {
                        filepath = Path.Combine(Server.MapPath("~/JiraAttachments/"), fileName);
                        content2 = new MultipartFormDataContent();
                        HttpContent fileContent = new ByteArrayContent(System.IO.File.ReadAllBytes(filepath));

                        string mimeType = System.Web.MimeMapping.GetMimeMapping(fileName);
                        //specifying MIME Type
                        fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse(mimeType);

                        content2.Add(fileContent, "file", fileName);

                        var response2 = await client.PostAsync("issue/" + key + "/attachments", content2);

                        if (response2.IsSuccessStatusCode)
                        {
                            var file         = Path.GetFileName(fileName);
                            var physicalPath = Path.Combine(Server.MapPath("~/JiraAttachments/"), file);

                            if (System.IO.File.Exists(physicalPath))
                            {
                                System.IO.File.Delete(physicalPath);
                            }
                        }
                    }
                }
            }

            return(Json(key, JsonRequestBehavior.AllowGet));
        }