How to fetch versions (version name,startdate,releasedate) details by using projectID

Hi Team,

I have couple of versions in my project.

I need to fetch startdate and release date of versions and do some calculations on it.

image2016-11-25 14:52:57.png

import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.project.version.VersionManager

 

def projectKey = issue.getProjectId() //this will give me project_id

i need to fetch versions startdate,versions releasedate by passing project_id.

-----------------

I have done some R&D on how to achieve this,

getAllVersions() //this will give me all the versions present in system

Date getReleaseDate() it will give release date of version

Date getStartDate() it will give start date of version

Reference:https://docs.atlassian.com/jira/server/com/atlassian/jira/project/version/Version.html#getStartDate--

https://docs.atlassian.com/software/jira/docs/api/latest/com/atlassian/jira/project/ProjectManager.html

 

I am new to groovy,can any one please help me with pseudo code to achieve this.

 

Thanks in advance,

 

 

 

 

 

 

 

 

2 answers

 
 
Project p =ComponentAccessor.getProjectManager().getProjectObj("long");
Collection<Version> versions=p.getVersions();
for(Version v:versions){
    v.getReleaseDate()
    v.getStartDate()
}

Thank you Shamith Shankar smile

I do have another question, i have stored my project's version's startdate in a array list. Now i wanted to sort that list and fetch "Nearest date,smallest date,largest date" 

 image2016-12-1 12:47:8.png

I want 1-oct-2016 and 29-jun-2015

 

 

My code:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.ComponentManager
import java.util.*

projectCount = new ProjectCount(issues)//creating object for this classs

public class ProjectCount {
def issues
def versions
def versionStart
public ProjectCount(issues) {
this.issues = issues

calMetr1(this.issues)
}

public def calMetr1(issues){
versionStart = new ArrayList<Date>()
def project = issues.get(0).getProjectObject()
// get the versions for this project
this.versions = project.getVersions() 
//i am storing version startDate in arraylist,my project can contains null vales also
for(version in versions)
{
versionStart.add(version.getStartDate())

}
// i want to sort my list and pick the nearest date from it and display it(though VM template)

//i have tried using versionStart.sort(),versionStart.last() but no luck sad
}
}

 

can you please help me with this 

 

Thanks in advance

versionStart.max(),versionStart.min() worked.

Do we have any other way

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted yesterday in Statuspage

How do your teams prepare for really high (planned) traffic days like Cyber Monday?

Hi there! Shannon from Statuspage here.  👋  With Cyber Monday quickly approaching, we're looking to hear from Atlassian customers – specifically from teams who touch incident response li...

42 views 0 4
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you