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

How to get the commited source code in Stash

Stefan Kohler
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.
June 7, 2012

Hi,

As the development resources for Stash are a bit limited at this point in time, I'll try my luck here.

I'm trying to get to the commited source code on a RepositoryPushEvent, so that I can analyze it.
But the only information you'll get from a event are the date, user and the repository he just pushed to.

What would be the preferred way of getting to the changesets and source code via a plugin?

PageRequest pageRequest = new PageRequestImpl(0, 1);
Page<Changeset> changesets = historyService.getChangesets(repository, null, null, pageRequest);

gives my an AuthenticationCredentialsNotFoundException.

Cheers,
Stefan

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Michael Heemskerk
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 11, 2012

Hi Stefan,

It sounds like you really want is a git post-receive hook style notification. We're planning to add better support for git service hooks in upcoming releases, but for now the information in the RepositoryPushEvent is all that is available, which is fairly limited.

With regards to the getChangesets command you're running: by passing in a null branch you'll get the latest changesets on the default branch (typically master) only. This may or may not be what you want. It depends on what you want to achieve with your plugin, but you may want to have a look at ChangesetIndexer which will give you a callback for every changeset that is added or removed (e.g. when a branch is deleted). Point of warning though: getting the modified sources for all changesets can be very expensive and can put the server under significant load.

You're getting the AuthenticationCredentialsNotFoundException because the HistoryService#getChangesets method is secured; you need at least read-access to the repository before you can get the list of changesets from the repository. The RepositoryPushEvent is sent asynchronously which means that your event listener runs without an authenticated context. You can work around this by using:

SecurityService securityService = ...;

Page<Changeset> result = securityService.doWithPermission(".. a reason here.. (used for logging)", Permission.REPO_READ, new Operation<Page<Changeset>, RuntimeException>() {
    Page<Changeset> perform() {
       ... // your code here
    }
});

Hope this helps!

Cheers

Stefan Kohler
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.
June 19, 2012

Thnx!

Got the Stash sourcecode now, made it a bit easier to find what I was looking for.
Your suggestion to look at the ChangesetIndexer was spot on, thanks!

Warning noted, will keep server load in mind!

Cheers

TAGS
AUG Leaders

Atlassian Community Events