I've working on a Stash plugin that adds a button to the Pull Request Overview page.
The button works as it should, with one minor detail - I want it enabled or disabled (hidden, or grayed out) based on some conditions. I've tried making a conditions class for it, but am running into issues.
Using advise from here: https://answers.atlassian.com/questions/209313/stash-merge-check-hook-for-deploying-changed-code
I'm trying to pass a PullRequst object (com.atlassian.stash.pull.PullRequest) into the constructor, and running into issues when trying to load the plugin into Stash.
Initially, when loading the addon, I got this error:
"Unsatisfied dependency expressed through constructor argument with index 0 of type [com.attlassian.stash.pull.PullRequest]: : No unique bean of type [com.atlassian.stash.pull.PullRequest] is definded."
Quick searching brought me to this: https://developer.atlassian.com/display/DOCS/UnsatisfiedDependencyException+-+Error+creating+bean+with+name
So I add a component-import to my atlassian-plugin.xml, but then I get this error after trying to load the plugin.
"DependencyWaiterApplicationContextExecutor Unabel to create application context for [com.company.plugin], unsatisfied depenencies: Dependency on [(objectClass=com.atlassian.stash.pull.PullRequest)] (from bean [&pullRequest]).
I'm guessing I'm either missing a dependency for PullRequest (how do I find out what it's dependent upon?) , or it's not publicly available to be imported in such a manner.
What I need in the grand scheme of things is info for the specific pull request (project, repo, PR#, reviewers, etc). I can get this via REST, but was hoping it would be cleaner via the java API.
Community moderators have prevented the ability to post new answers.
Hi Justin,
The problem is that you're trying to inject a data object into a constructor. You can only inject things that have been declared as components (or Spring OSGI beans if you prefer).
Which pull request would you want to inject? Remember that the injection only happens once on plugin start. You probably want to inject the PullRequestService instead and then find one depending on project+repo+pr# that you have in the URL?
Alternatively, to save you some effort, if you're in a Resource class you can take this shortcut:
import com.atlassian.stash.rest.util.ReseourcePatterns; @Path(ResourcePatterns.PULL_REQUEST_URI + "/something") public class MyResource { @GET public void foo(@Context PullRequest pr) {...} }
You would need to import stast-rest-common in your maven file to get access to ResourcePatterns. The @Context only works if you use the PULL_REQUEST_URI though. This does mean your URL will be something like:
/rest/myplugin/1.0/projects/A/repos/B/pull-requests/123/something
I hope that helps.
Charles
PS. Before you ask, I know this could be better documented. If you're wondering how to tell what is a component this might be a good place to start:
https://answers.atlassian.com/questions/253072/verifying-commiter-and-content-of-a-change-in-repository-hook/256127
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.