Last active
August 15, 2017 19:36
-
-
Save dcinzona/76f9b3e4f7a397bdcc4d1b77bcb94d56 to your computer and use it in GitHub Desktop.
JIRA Issue Aggregator by Week
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Jira_Issue_Aggregator { | |
| public static void aggregate(){ | |
| List<Jira_Issue_Week_Aggregation__c> aggrs = [SELECT Id FROM Jira_Issue_Week_Aggregation__c]; | |
| if(aggrs.size() > 0){ | |
| delete aggrs; | |
| } | |
| Map<string, Jira_Issue_Week_Aggregation__c> aggrMap = new Map<string, Jira_Issue_Week_Aggregation__c>(); | |
| Set<Date> dates = new Set<Date>(); | |
| Set<String> resolutions = new Set<string>(); | |
| for(Jira_Issue__c j : [SELECT ID, Created_Date_Date_Value__c, Date_Completed__c, Story_Points__c, Resolution__c, Status__c | |
| FROM Jira_Issue__c | |
| WHERE Story_Points__c > 0 | |
| AND Issue_Type__c = 'Story' | |
| AND Resolution__c in ('Done','Unresolved') | |
| ORDER BY Created_Date_Date_Value__c ASC]){ | |
| //dates.add(j.Created_Date_Date_Value__c.toStartOfWeek()); | |
| //resolutions.add(j.Resolution__c); | |
| boolean CreatedAndClosedSameWeek = j.Date_Completed__c != null && j.Date_Completed__c.toStartOfWeek() == j.Created_Date_Date_Value__c.toStartOfWeek(); | |
| String CreatedStartWk = j.Created_Date_Date_Value__c.toStartOfWeek().format() + '['+j.Resolution__c +':'+j.Status__c+']'; | |
| String ClosedStartWk = j.Date_Completed__c != null ? j.Date_Completed__c.toStartOfWeek().format() + '['+j.Resolution__c +':'+j.Status__c+']' : 'N/A'; | |
| boolean validClose = j.Status__c == 'Done' || j.Status__c == 'Deployed' || j.Status__c == 'Deployment Deferred'; | |
| if(aggrMap.containsKey(CreatedStartWk)){ | |
| Jira_Issue_Week_Aggregation__c aggrc = aggrMap.get(CreatedStartWk); | |
| System.debug('Contains Key:' + CreatedStartWk); | |
| System.debug(aggrc); | |
| aggrc.Points_Added__c = aggrc.Points_Added__c + j.Story_Points__c; | |
| if(CreatedAndClosedSameWeek && validClose){ | |
| //aggrc.Points_Closed__c += j.Story_Points__c; | |
| } | |
| }else{ | |
| Jira_Issue_Week_Aggregation__c aggrn = new Jira_Issue_Week_Aggregation__c(); | |
| aggrn.Week_Date__c = j.Created_Date_Date_Value__c.toStartOfWeek(); | |
| //aggrn.Week_Group__c = CreatedStartWk; | |
| aggrn.Points_Added__c = j.Story_Points__c; | |
| if(CreatedAndClosedSameWeek && validClose){ | |
| aggrn.Points_Closed__c = j.Story_Points__c; | |
| }else{ | |
| aggrn.Points_Closed__c = 0; | |
| } | |
| aggrn.Resolution__c = j.Resolution__c; | |
| aggrn.Status__c = j.Status__c; | |
| aggrMap.put(CreatedStartWk, aggrn); | |
| } | |
| /* */ | |
| if(j.Date_Completed__c != null && validClose){ | |
| if(aggrMap.containsKey(ClosedStartWk)){ | |
| Jira_Issue_Week_Aggregation__c aggrd = aggrMap.get(ClosedStartWk); | |
| aggrd.Points_Closed__c = aggrd.Points_Closed__c + j.Story_Points__c; | |
| }else{ | |
| Jira_Issue_Week_Aggregation__c aggrn = new Jira_Issue_Week_Aggregation__c(); | |
| aggrn.Week_Date__c = j.Date_Completed__c.toStartOfWeek(); | |
| //aggrn.Week_Group__c = ClosedStartWk; | |
| aggrn.Points_Added__c = CreatedAndClosedSameWeek ? j.Story_Points__c : 0; | |
| aggrn.Points_Closed__c = j.Story_Points__c; | |
| aggrn.Resolution__c = j.Resolution__c; | |
| aggrn.Status__c = j.Status__c; | |
| aggrMap.put(ClosedStartWk, aggrn); | |
| } | |
| } | |
| /* */ | |
| } | |
| insert aggrMap.values(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Name | Apex Type | |
|---|---|---|
| OwnerId | reference | |
| IsDeleted | boolean | |
| Name | string | |
| CreatedDate | datetime | |
| CreatedById | reference | |
| LastModifiedDate | datetime | |
| LastModifiedById | reference | |
| SystemModstamp | datetime | |
| LastViewedDate | datetime | |
| LastReferencedDate | datetime | |
| Week_Date__c | date | |
| Points_Added__c | double | |
| Points_Closed__c | double | |
| Week_Group__c | string | |
| Remaining_Points__c | double | |
| Resolution__c | string | |
| Status__c | string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment