JIRA Remote API - How to query "subversion commit" field using REST /SOAP Java client for an Issue?
I have created a java client using JIRA REST services. I am successfully able to fetch comments and other fields related to an issue. But I am not able to get how to fetch associated Sub-version commit fileds value for that given issue id.
Can anyone help me to figure it out.
Thanks.
Community moderators have prevented the ability to post new answers.
The subversion data that Jira is not accessable through an API. The information is stored in external files under the directory
/<jira-base-directory>/Application Data\JIRA\caches\indexes\plugins\atlassian-subversion-revisions
I would think it would be easier to do a svn log yourself and maintain the data yourself verses figuring out the plugin file structure and have a dependency on the internal structure of the plugin.
Thanks for the reply.
Since I am a newbie on JIRA stuff could you please eloborate your approach of svn log. How to do that?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the reply.
Since I am a newbie on JIRA stuff could you please eloborate your approach of svn log. How to do that? (Using Java)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You run svn log either on the individual projects or the whole respository. This will give you the comments entered into svn where you extract the changeset, date and Jira issue ID. Given the comment dates from Jira and svn, you can associate jira comments to changesets. You can either do one of the follow items for future changes:
1) Modify svn to push out additional changes to a service that keeps recording the information
2) Pull the information from svn log command based upon the last time the command was run.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As already mentioned, the JIRA Subversion plugin stores its information in <jira-base-directory>/Application Data/JIRA/caches/indexes/plugins/atlassian-subversion-revisions, which is a Lucene database. You can access this database (in read-only mode) as work-around for the lack of a web API.
It's faily easy to write a small Java program that queries this Lucene database for svn revisions associated with given JIRA task. You can use the the Java JRE and lucene JAR already included in JIRA, so no additional dependencies are needed.
Example code:
import java.util.Arrays; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.WhitespaceAnalyzer; import org.apache.lucene.index.IndexReader; import org.apache.lucene.document.Document; import org.apache.lucene.queryParser.QueryParser; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.TopDocs; import org.apache.lucene.store.FSDirectory; import org.apache.lucene.util.Version; /** Query a JIRA SVN Plugin database for SVN commits, based on issue name. */ public class QueryJiraSvn { private QueryJiraSvn () {} /** Entry point */ public static void main (String[] args) throws Exception { if (args.length > 0 && ("-h".equals(args[0]) || "-help".equals(args[0]))) { String usage = "Usage:\tjava QueryJiraSvn [-index dir] [-field f] [-query string]\n"; System.out.println(usage); System.exit(0); } String index = null; // e.g. "C:\Atlassian\Application Data\JIRA\caches\indexes\plugins\atlassian-subversion-revisions" String field = null; // e.g. "key" String query = null; // e.g. "PROJECT-123" for (int i = 0; i < args.length; i++) { if ("-index".equals(args[i])) { index = args[i+1]; i++; } else if ("-field".equals(args[i])) { field = args[i+1]; i++; } else if ("-query".equals(args[i])) { query = args[i+1]; i++; } } int revs[] = null; { Analyzer analyzer = new WhitespaceAnalyzer(Version.LUCENE_31); QueryParser parser = new QueryParser(Version.LUCENE_31, field, analyzer); Query query_obj = parser.parse(query.trim()); //System.out.println("Searching for: " + query_obj.toString(field)); IndexReader reader = IndexReader.open(FSDirectory.open(new File(index)), true /*read-only*/); IndexSearcher searcher = new IndexSearcher(reader); revs = SearchForRevs(searcher, query_obj, false); searcher.close(); } // output revision list for (int i = 0; i < revs.length; i++) { System.out.print(revs[i]); if (i < revs.length-1) System.out.print(","); } } /** Search for the list of revisions associated with a JIRA issue. */ public static int[] SearchForRevs (IndexSearcher searcher, Query query, boolean debug) throws IOException { TopDocs results = searcher.search(query, 1); results = searcher.search(query, results.totalHits); ScoreDoc[] hits = results.scoreDocs; int revs[] = new int[results.totalHits]; for (int i = 0; i < hits.length; i++) { // output raw format if (debug) System.out.println("doc="+hits[i].doc); Document doc = searcher.doc(hits[i].doc); String key = doc.get("key"); // e.g. "PROJECT-123" String repo = doc.get("repository"); // integer value String author = doc.get("author"); String rev = doc.get("revision"); // rev number String message = doc.get("message"); revs[i] = Integer.parseInt(rev); if (debug) System.out.println(key+": repo="+repo+", author="+author+", rev="+rev+", message="+message); } // sort revision list Arrays.sort(revs); return revs; } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have to fetch the SVN commit messages of a particular issue of JIRA.(https://jira2.####.com/browse/ABCD-1234)
Can I get some help of API or any link or any method regarding how to fetch the commit messages?
Thanks in advance.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.