It's all about the answers!

Ask a question

How are previous change set comments retrieved using the API


Ed Koezly (46154) | asked Mar 06 '09, 1:26 p.m.
How can I see the history of change set comments?

Comment from Jean-Michel in Enhancement https://jazz.net/jazz/web/projects/Rational%20Team%20Concert#action=com.ibm.team.workitem.viewWorkItem&id=72237
There are APIs today which allow you to retrieve the old comments on a change set, so nothing is lost. Once you have a IChangeSet in hand, simply get the IItemManager.fetchAllStateHandles(), then for each handle get the states. Each state has the comment.


I can see the current comment with changeset.getComment(), but I haven't been able get the previous states.
What code should I use?

public static void getChangeSetComments(ITeamRepository repo, IProgressMonitor monitor) throws TeamRepositoryException, ItemNotFoundException, ComponentNotInWorkspaceException {
IWorkspaceManager wm = SCMPlatform.getWorkspaceManager(repo);
IChangeSetSearchCriteria criteria = IChangeSetSearchCriteria.FACTORY.newInstance();

//Get any 10 changesets.
List<IChangeSetHandle> changeSets = wm.findChangeSets(criteria, 10, monitor);

for (IChangeSetHandle changeSetHandle : changeSets) {
//For each changeset
final IChangeSet changeSet =
(IChangeSet) repo.itemManager().fetchCompleteItem(changeSetHandle, IItemManager.REFRESH, monitor);

//For the given change set, get all the states. Each state will have a comment.

<B> //These next lines are where I don't know what to do. I put some code here just to experiment.
//I'm going in a circle. fetchAllStateHandles returns a few rows per change set, but it's not
//the number of revisions. cs.GetComment() returns the most recent change set comment.
final List&lt;IChangeSet&gt; stateList = (List&lt;IChangeSet&gt;) repo.itemManager().fetchAllStateHandles(changeSet,monitor);
for (IChangeSetHandle csHandle : stateList) {
final IChangeSet cs =
(IChangeSet) repo.itemManager().fetchCompleteItem(csHandle, IItemManager.REFRESH, monitor);
System.out.println(&quot;state comment=&quot;+cs.getComment());
</B> };

System.out.println(&quot;comment=&quot;+changeSet.getComment());
}
return;
}
}

If there's a Junit or API documentation I should look at, please point me to it.

Thank you

2 answers



permanent link
Jean-Michel Lemieux (2.5k11) | answered Mar 08 '09, 10:32 p.m.
JAZZ DEVELOPER
This should work. Here is a snippet that I just tested locally and it prints all the comments given to a particular change set.

void showChangesetHistory(IChangeSet cs, IWorkspaceConnection wc, IProgressMonitor monitor)
throws TeamRepositoryException {
SubMonitor progress = SubMonitor.convert(monitor, 100);
IItemManager mgr = wc.teamRepository().itemManager();
List&lt;IChangeSetHandle&gt; handles = mgr.fetchAllStateHandles(cs, progress.newChild(40));
List&lt;IChangeSet&gt; csStates = mgr.fetchCompleteStates(handles, progress.newChild(50));

StringBuffer buf = new StringBuffer();
for (IChangeSet c : csStates) {
buf.append(c.getComment() + &quot;\n&quot;);
}
buf.toString();

}

permanent link
Ed Koezly (46154) | answered Mar 10 '09, 5:34 p.m.
It works for me, too. Thank you!

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.