Commits

Federico Silva Armas committed 632d04a

Fix regression introduced by previous change.

  • Participants
  • Parent commits af68112

Comments (0)

Files changed (3)

Atlassian.Jira/CustomField.cs

             {
                 if (String.IsNullOrEmpty(_name)) 
                 {
-                    _name = _issue.Jira.GetFieldsForEdit(_issue.Key.Value, _issue.Project).First(f => f.Id == _id).Name;
+                    _name = _issue.Jira.GetFieldsForEdit(_issue).First(f => f.Id == _id).Name;
                 }
 
                 return _name; 

Atlassian.Jira/CustomFieldCollection.cs

         {
             _getFieldIdProvider = fieldName =>
             {
-                var customField = _issue.Jira.GetFieldsForEdit(_issue.Key.Value, _issue.Project)
+                var customField = _issue.Jira.GetFieldsForEdit(_issue)
                     .FirstOrDefault(f => f.Name.Equals(fieldName, StringComparison.OrdinalIgnoreCase));
 
                 if (customField == null)
         {
             _getFieldIdProvider = name =>
             {
-                var customField = _issue.Jira.GetFieldsForAction(_issue.Key.Value, _issue.Project, actionId)
+                var customField = _issue.Jira.GetFieldsForAction(_issue, actionId)
                     .FirstOrDefault(f => f.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
 
                 if (customField == null)

Atlassian.Jira/Jira.cs

                 return function(_token, this.RemoteSoapService);
             }
         }
-
-        internal IEnumerable<JiraNamedEntity> GetFieldsForAction(string issueKey, string projectKey, string actionId)
+        
+        internal IEnumerable<JiraNamedEntity> GetFieldsForAction(Issue issue, string actionId)
         {
-            if (!_cachedFieldsForAction.ContainsKey(projectKey, actionId))
+            if (issue.Key == null)
+            {
+                issue = GetOneIssueFromProject(issue.Project);
+            }
+
+            if (!_cachedFieldsForAction.ContainsKey(issue.Project, actionId))
             {
                 WithToken((token, service) =>
                 {
-                    _cachedFieldsForAction.Add(projectKey, actionId, _jiraSoapService.GetFieldsForAction(token, issueKey, actionId)
+                    _cachedFieldsForAction.Add(issue.Project, actionId, _jiraSoapService.GetFieldsForAction(token, issue.Key.Value, actionId)
                         .Select(f => new JiraNamedEntity(f)));
                 });
             }
 
-            return _cachedFieldsForAction[projectKey, actionId];
+            return _cachedFieldsForAction[issue.Project, actionId];
         }
 
-        internal IEnumerable<JiraNamedEntity> GetFieldsForEdit(string issueKey, string projectKey)
+        internal IEnumerable<JiraNamedEntity> GetFieldsForEdit(Issue issue)
         {
-            if (!_cachedFieldsForEdit.ContainsKey(projectKey))
+            if (issue.Key == null)
+            {
+                issue = GetOneIssueFromProject(issue.Project);
+            }
+
+            if (!_cachedFieldsForEdit.ContainsKey(issue.Project))
             {
                 WithToken(token =>
                 {
-                    _cachedFieldsForEdit.Add(projectKey, _jiraSoapService.GetFieldsForEdit(token, issueKey)
+                    _cachedFieldsForEdit.Add(issue.Project, _jiraSoapService.GetFieldsForEdit(token, issue.Key.Value)
                         .Select(f => new JiraNamedEntity(f)));
                 });
             }
 
-            return _cachedFieldsForEdit[projectKey];
+            return _cachedFieldsForEdit[issue.Project];
+        }
+
+        private Issue GetOneIssueFromProject(string projectKey)
+        {
+            var tempIssue = this.GetIssuesFromJql(String.Format("project = \"{0}\"", projectKey) ,1)
+                                .FirstOrDefault();
+
+            if (tempIssue == null)
+            {
+                throw new InvalidOperationException("Project must contain at least one issue to be able to retrieve issue fields.");
+            }
+
+            return tempIssue;
         }
     }
 }