public void MigrateToIssue(MigrateJiraIssuesToGithub.Models.Issue jiraIssue, List<MilestoneGitHub> milestones, List<LabelGitHub> labels, ref Issue githubIssue) { if (String.IsNullOrEmpty(jiraIssue.SprintName)) { jiraIssue.SprintName = "1.0 Inicial"; } if (githubIssue == null) { var newIssue = new NewIssue(jiraIssue.Title) { Body = jiraIssue.Content, Milestone = milestones.First(m => m.Title == jiraIssue.SprintName).Number }; foreach (var label in jiraIssue.Labels) { newIssue.Labels.Add(label); } var nIssue = newIssue; var taskResult = Task.Run<Octokit.Issue>(async () => await client.Issue.Create(githubOrganizationName, githubRepositoryName, nIssue)); githubIssue = taskResult.Result; } //todo: archive... // obs.: atribuir usuário à tarefa /*if (issueYAA923.Assigned != null) { try { client.Issue.Assignee.CheckAssignee(githubOrganizationName, githubRepositoryName, issueYAA923.Assigned.Name); //"gBritz" } catch (Exception ex) { Log("ERROR: Não conseguiu atribuir ao usuário " + issueYAA923.Assigned.Name); //obs.: caso não exista no projeto, irá gerar erro ao cadastrar issue var msg = String.Format("Originalmente atribuído para o {0} ({1}) no jira.", issueYAA923.Assigned.Name, issueYAA923.Assigned.Email); client.Issue.Comment.Create(githubOrganizationName, githubRepositoryName, issueResult.Number, msg); } }*/ var sbStatusComment = new StringBuilder(); sbStatusComment.AppendFormat(@" **Status in Jira** {0} ({1}) `Created` at {1:dd/MM/yyyy hh:mm:ss} ", jiraIssue.Creator.Name, jiraIssue.Creator.Email, jiraIssue.CreateAt); if (jiraIssue.InProgress != null && jiraIssue.InProgressAt.HasValue) { sbStatusComment.AppendFormat(@" {0} ({1}) set `In Progress` at {2:dd/MM/yyyy hh:mm:ss}", jiraIssue.InProgress.Name, jiraIssue.InProgress.Email, jiraIssue.InProgressAt); } if (jiraIssue.Resolved != null && jiraIssue.ResolvedAt.HasValue) { sbStatusComment.AppendFormat(@" {0} ({1}) set `Resolved` at {2:dd/MM/yyyy hh:mm:ss}", jiraIssue.Resolved.Name, jiraIssue.Resolved.Email, jiraIssue.ResolvedAt); } if (jiraIssue.Closer != null && jiraIssue.ClosedAt.HasValue) { sbStatusComment.AppendFormat(@" {0} ({1}) set `Closed` at {2:dd/MM/yyyy hh:mm:ss}", jiraIssue.Closer.Name, jiraIssue.Closer.Email, jiraIssue.ClosedAt); } client.Issue.Comment.Create(githubOrganizationName, githubRepositoryName, githubIssue.Number, sbStatusComment.ToString()); // obs.: adicionar comentários foreach (var comment in jiraIssue.Comments) { var commentAuthor = String.Format(@" **Commentary** by {0} ({1}) ", comment.Creator.Name, comment.Creator.Email); client.Issue.Comment.Create(githubOrganizationName, githubRepositoryName, githubIssue.Number, commentAuthor + comment.Body); } // obs.: fechar issue if (jiraIssue.ClosedAt.HasValue) { var issueUpdate = new IssueUpdate { State = ItemState.Closed }; client.Issue.Update(githubOrganizationName, githubRepositoryName, githubIssue.Number, issueUpdate); } Log(String.Format("Info: Issue {0} created", jiraIssue.JiraKey)); }
public Boolean TryMigrateToIssue(MigrateJiraIssuesToGithub.Models.Issue jiraIssue, List<MilestoneGitHub> milestones, List<LabelGitHub> labels, ref Issue githubIssue) { var result = false; try { MigrateToIssue(jiraIssue, milestones, labels, ref githubIssue); result = true; } catch (Exception ex) { Log(String.Format("ERROR: issue key {0} has error {1}.", jiraIssue.JiraKey, ex.Message)); } return result; }