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

Get the content of a merge in a merge request check?

Andreas Borkenhagen February 12, 2014

Hey,

I dont't find any interface or method to get the content / involved files of a merge request nor any Atlassian Plugin SDK API documentation at all.

May you help?

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
cofarrell
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.
February 14, 2014

Hi Andreas,

I may. You want to inject the PullRequestService into the contructor of your MergeCheck class, and use either streamChanges() or streamChangesets() with the PullRequest, depending on what you're looking for. This is (untested) code. The AbstractChangeCallback was only introduced in Stash 2.10. Otherwise you need to implement all the methods on ChangeCallback.

import com.atlassian.stash.content.*;
import com.atlassian.stash.pull.*;
import com.atlassian.stash.scm.pull.MergeRequestCheck;

public class MyMergeCheck implements MergeCheck {
    public PullRequestService pullRequestService;

    public MyMergeCheck(PullRequestService pullRequestService) {
        this.pullRequestService = pullRequestService;
    }

    void check(MergeRequest request) {
        PullRequest pr = request.getPullRequest();
        pullRequestService.streamChanges(pr.getToRef().getRepository().getId(), pr.getId(), new AbstractChangeCallback() {
            public boolean onChange(Change change) {
                // TODO
            }
        });
    }
}

Let me know how you go. If you get stuck I recommend pushing what you have to a public repository on Bitbucket/Github to make it easier to compare notes.

Good luck.

Charles

Andreas Borkenhagen February 16, 2014

My comment disappeared after sending :/

Once again:

Thanks for providing this solution. I managed to detect wether a pom.xml would be involved in the merge or not.

Now i am trying to expect a certain number of approvals for the merge request, if there is a pom.xml change detected, but i failed using the example code:

https://bitbucket.org/Holzroller2k/stash-plugins

The number of approvers is always zero.

Andreas Borkenhagen February 16, 2014

Test test - don't see my comment

cofarrell
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.
February 16, 2014

Hi Andreas,

I've sent you a pull request, and in particular pay attention to the last commit - you were counting "reviewers" but not the other participants who may have approved.

I hope that helps.

Charles

Andreas Borkenhagen February 17, 2014

Wow, that's what i call service :)

TAGS
AUG Leaders

Atlassian Community Events