Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

JIRA Remote API - How to query "subversion commit" field using REST /SOAP Java client for an Issue?

Yogendra Jat November 22, 2012

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.

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
Norman Abramovitz
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 22, 2012

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.

Yogendra Jat November 25, 2012

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?

Yogendra Jat November 25, 2012

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)

Norman Abramovitz
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 25, 2012

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.

2 votes
Fredrik Orderud
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 27, 2013

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 &gt; 0 &amp;&amp; ("-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 &lt; 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 &lt; revs.length; i++) {
            System.out.print(revs[i]);
            
            if (i &lt; 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 &lt; 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;
    }
}

0 votes
VIPUL AGARWAL February 5, 2019

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.

TAGS
AUG Leaders

Atlassian Community Events