コード例 #1
0
ファイル: Ticket.cs プロジェクト: KilskyreMan/JiraToTfs
 public Comment(User author, string body, DateTime createdOn)
 {
     Author = author;
     Body = JiraString.StripNonPrintable(body);
     CreatedOn = createdOn;
     Updated = createdOn;
 }
コード例 #2
0
ファイル: Ticket.cs プロジェクト: KilskyreMan/JiraToTfs
 public Ticket()
 {
     ID = "";
     Description = "";
     TicketType = "";
     TicketState = State.Unknown;
     Comments = new List<Comment>();
     ExternalReference = "";
     Project = "";
     Url = "";
     Summary = "";
     Links = new List<Link>();
     CreatedOn = new DateTime();
     LastModified = new DateTime();
     ClosedOn = new DateTime();
     CreatedBy = new User();
     AssignedTo = new User();
     Epic = "";
     Parent = "";
     StoryPoints = 0;
     Attachments = new List<Attachment>();
     Priority = "";
 }
コード例 #3
0
ファイル: JiraProject.cs プロジェクト: KilskyreMan/JiraToTfs
        public IEnumerable<Ticket> Tickets(IAvailableTicketTypes availableTypes)
        {
            var map = new JiraTypeMap(this, availableTypes);
            foreach (var jiraKey in jira.EnumerateIssues(jiraProject))
            {
                var issueRef = new IssueRef
                {
                    id = jiraKey.id,
                    key = jiraKey.key
                };
                var jiraTicket = jira.LoadIssue(issueRef);

                onDetailedProcessing(jiraTicket.key + " - " + jiraTicket.fields.summary);

                var ticket = new Ticket();
                ticket.TicketType = map[jiraTicket.fields.issuetype.name];
                ticket.ID = jiraTicket.key;
                ticket.Summary = JiraString.StripNonPrintable(jiraTicket.fields.summary);

                var status = jiraTicket.fields.status.statusCategory.key.ToUpper();
                switch (status)
                {
                    case "NEW":
                        ticket.TicketState = Ticket.State.Todo;
                        break;
                    case "DONE":
                        ticket.TicketState = Ticket.State.Done;
                        break;
                    case "INDETERMINATE":
                        ticket.TicketState = Ticket.State.InProgress;
                        break;
                    default:
                        ticket.TicketState = Ticket.State.Unknown;
                        break;
                }

                ticket.Parent = jiraTicket.fields.parent.key;

                ticket.Description = JiraString.StripNonPrintable(jiraTicket.fields.description);
                if (PreferHtml &&
                    string.IsNullOrWhiteSpace(jiraTicket.renderedFields.description) == false)
                {
                    ticket.Description = JiraString.StripNonPrintable(jiraTicket.renderedFields.description);
                }
                ticket.CreatedOn = jiraTicket.fields.created;
                ticket.LastModified = jiraTicket.fields.updated;

                ticket.CreatedBy = new User(jiraTicket.fields.reporter.displayName,
                    jiraTicket.fields.reporter.name,
                    jiraTicket.fields.reporter.emailAddress);
                ticket.AssignedTo = new User(jiraTicket.fields.assignee.displayName,
                    jiraTicket.fields.assignee.name,
                    jiraTicket.fields.assignee.emailAddress);

                ticket.Epic = jiraTicket.fields.customfield_10800;
                ticket.ExternalReference = jiraTicket.key;
                ticket.Url = jiraServer + "/browse/" + jiraTicket.key;
                int.TryParse(jiraTicket.fields.customfield_10004, out ticket.StoryPoints);

                foreach (var link in jiraTicket.fields.issuelinks)
                {
                    if (string.Compare(link.inwardIssue.key, jiraTicket.key) != 0)
                    {
                        ticket.Links.Add(new Link(link.inwardIssue.key, link.type.name));
                    }
                    if (string.Compare(link.outwardIssue.key, jiraTicket.key) != 0)
                    {
                        ticket.Links.Add(new Link(link.outwardIssue.key, link.type.name));
                    }
                }

                foreach (var jiraComment in jiraTicket.fields.comments)
                {
                    var author = new User(jiraComment.author.displayName,
                        jiraComment.author.name, jiraComment.author.emailAddress);
                    var comment = new Comment(author, jiraComment.body, jiraComment.created);
                    if (jiraComment.updated.Date > jiraComment.created.Date)
                    {
                        comment.Updated = jiraComment.updated;
                    }
                    ticket.Comments.Add(comment);
                }

                foreach (var attachment in jiraTicket.fields.attachment)
                {
                    ticket.Attachments.Add(new Attachment(attachment.filename, attachment.content));
                }

                ticket.Priority = jiraTicket.fields.priority.name;
                ticket.Project = jiraTicket.fields.project.name;
                if (jiraTicket.fields.resolutiondate != null)
                {
                    ticket.ClosedOn = jiraTicket.fields.resolutiondate;
                }

                yield return (ticket);
            }
        }
コード例 #4
0
ファイル: TfsUsers.cs プロジェクト: KilskyreMan/JiraToTfs
        public TfsTeamProjectCollection Impersonate(User userToImpersonate)
        {
            TfsTeamProjectCollection impersonated_User = null;
            try
            {
                if (canImpersonate)
                {
                    if (userToImpersonate.IsSameUser(tfsProject.Tfs.AuthorizedIdentity.DisplayName) == false)
                    {
                        impersonated_Users.TryGetValue(userToImpersonate, out impersonated_User);
                        if (impersonated_User == null)
                        {
                            var tfsUser = defaultCreator;
                            foreach (var user in tfsUsers)
                            {
                                if (userToImpersonate.IsSameUser(user.GetAttribute("Mail", ""))
                                    || userToImpersonate.IsSameUser(user.DisplayName))
                                {
                                    tfsUser = user.DisplayName;
                                    break;
                                }
                            }

                            var toImpersonate = getId(tfsUser);
                            if (toImpersonate != null)
                            {
                                impersonated_User = new TfsTeamProjectCollection(tfsProject.Tfs.Uri, toImpersonate.Descriptor);
                                var workItemStore = (WorkItemStore)impersonated_User.GetService(typeof(WorkItemStore));

                                if (workItemStore.Projects[tfsProject.Project].HasWorkItemWriteRights == true)
                                {
                                    impersonated_Users[userToImpersonate] = impersonated_User;
                                }
                                else if (OnFailedToImpersonate != null)
                                {
                                    OnFailedToImpersonate(
                                        string.Format("Failed to impersonate '{0}'. (This person does not have rights to create work items in TFS.)", userToImpersonate.DisplayName));
                                    return tfsProject.Tfs;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (OnFailedToImpersonate != null)
                {
                    OnFailedToImpersonate(
                        string.Format("Failed to impersonate '{0}'. ({1})", userToImpersonate.DisplayName, ex.Message));
                    return tfsProject.Tfs;
                }
            }
            return (impersonated_User?? tfsProject.Tfs);
        }
コード例 #5
0
ファイル: TfsUsers.cs プロジェクト: KilskyreMan/JiraToTfs
 public bool CanAddTicket(User toCheck)
 {
     var ableToAdd = true;
     if (unableToAddTickets.Contains(toCheck) == false)
     {
         var impersonated_User = Impersonate(toCheck);
         if (impersonated_User != null)
         {
             var workItemStore = (WorkItemStore) impersonated_User.GetService(typeof (WorkItemStore));
             if (workItemStore.Projects[tfsProject.Project].HasWorkItemWriteRights == false)
             {
                 unableToAddTickets.Add(toCheck);
                 ableToAdd = false;
             }
         }
     }
     return ableToAdd;
 }
コード例 #6
0
ファイル: TfsUsers.cs プロジェクト: KilskyreMan/JiraToTfs
        public void AssignUser(User toAssign, WorkItem workItem)
        {
            if (toAssign.HasIdentity)
            {
                var assignedUser = (string) workItem[CoreField.AssignedTo];

                var matched = false;
                foreach (string tfsUser in workItem.Fields[CoreField.AssignedTo].AllowedValues)
                {
                    matched = toAssign.IsSameUser(tfsUser);
                    if (matched)
                    {
                        assignedUser = tfsUser;
                        break;
                    }
                }

                if (matched == false)
                {
                    if (String.IsNullOrWhiteSpace(defaultAsignee) == false)
                    {
                        assignedUser = defaultAsignee;
                    }
                    failedImpersonations.Add(toAssign);
                }
                workItem[CoreField.AssignedTo] = assignedUser;
            }
        }