/// <summary> /// Hits the Jira API to retrieve a single story. Utilizes a per-class-instance in-memory cache so /// that subsequent calls for the same ID do not result in additional network traffic. /// </summary> public async Task <JiraStory> GetStoryAsync(string storyId, bool refreshCache = false) { if (!refreshCache && StoryCache.ContainsKey(storyId)) { return(StoryCache[storyId]); } var json = await GetJiraSearchResultJsonAsync(HttpUtility.UrlEncode("id=" + storyId)); try { var payload = JsonConvert.DeserializeObject <JiraSearchApiResponse>(json); var allStories = payload.Issues; // reality check if (payload.TotalResults == 0) { throw new NotFoundException($"Jira story '{storyId}' was not found."); } if (payload.TotalResults > 1) { throw new Exception($"Expected to find a single result for {storyId}. Found {payload.TotalResults} results instead."); } var story = new JiraStory( allStories.Single() ); StoryCache[storyId] = story; return(story); } catch (JsonSerializationException ex) { throw new ApplicationException("Error processing this response: " + json, ex); } }
public WorkItem(string releaseNum, JiraStory story, JiraStory epic) { this.StoryNumber = story.Id; this.ReleaseNumber = releaseNum; this.Status = JiraHelper.GetWorkItemStatus(story); this.EpicWorkItemId = story.EpicStoryId; this.EpicName = (epic != null) ? epic.Title : null; this.Title = story.Title; this.Type = JiraHelper.GetWorkItemType(story); this.StoryPointsOriginal = story.StoryPoints.HasValue ? (int)story.StoryPoints.Value : (int?)null; this.StoryPoints = story.StoryPoints.HasValue ? (int)story.StoryPoints.Value : 0; this.BillToClient = GetBillToClient(story); }
private string GetBillToClient(JiraStory story) { if (story.Labels.IsNullOrEmpty()) { return("R&D"); } var billToLabel = story.Labels .Where(l => l.StartsWithIgnoringCase("BillTo")) .FirstOrDefault(); var billToClient = billToLabel?.Extract("BillTo(.*)"); if (billToClient.IsNullOrEmpty() || billToClient.IsInIgnoringCase("RD", "R&D", "Defect", "DefectResolution")) { return("R&D"); } return(billToClient); }