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
Community moderators have prevented the ability to post new answers.
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
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
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.