Problem while creating Pull request....

Haidar Ali April 29, 2014

I am writing hook while creating Pull request but I am facing the following issue, in hook I have omplemented these interface RepositoryMergeRequestCheck, RepositorySettingsValidator, RepositoryRescopeContext, MergeRequestCheckService, MergeRequestCheck and override the related methods but only check() method is calling of RepositoryMergeRequestCheck interface.

But our requirement is while creating pull request I want to show some message like "Pull request Initiated" and once Merge is happened I want to show something else but My problem is only check method is executing and I am not able to differentiate that controls came in check method for initiated the pull request or Merge has been completed.

Please guide me how to achieve these functionaly. Please provide the some code snippets.


1 answer

0 votes
jhinch _Atlassian_
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 30, 2014

For a pull request hook, you should only be implementing RepositoryMergeRequestCheck and optionally RepositorySettingsValidator. RepositoryRescopeContext and
MergeRequestCheckService are not interfaces you shouldn't be implementing. They are in fact interfaces which Stash core implements.

I'm a little confused as to what you are hoping to achieve. Where are you hoping to provide the message? Merge checks are for preventing pull requests from being merged so perhaps they aren't what you are looking for.

Haidar Ali April 30, 2014

Thanks for reply...

I am using RepositoryMergeRequestCheck now and implemented the method check() in it and I want to achieve below functionality,


1) I want to print some message when pull request created.

2) And also I want to print some other message when created pull request has been approved and merged.

My problem is both the cases check method executing and I am not able to differentiate method is calling whether for #1 or #2.

So I am looking for track to identifying both calls in check method.

jhinch _Atlassian_
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 1, 2014

Where are you 'printing' these messages to? A log file? The UI? I don't think a merge check is what you are after.

You can create event listeners for PullRequestApprovedEvent and PullRequestMergedEvent

Haidar Ali May 1, 2014

Thanks a lot for quick response.

I want to printing message in log files. Given solution is helping us. we'll keep you post once we see progress on this.

Haidar Ali May 5, 2014

Hi,

As suggested, we are able to acheive the required functionality. Thanks a lot for the suggestion.

One more issue I am facing...Can you please suggest me something to acheiving this,

Problem : Suppose one branch in GIT saying that DEV1 and administrator committed some files and pushed the same to server.

I have also checkout the same branch and worked something on it and committed the message locally but I am not able to push my work directly on server because I dont have permission for that. So I have created local branch on DEV1 and pushed the same.

I wrote HOOK which take care of commit message which is in pre-defined format in regular expression. If committed message match then user can push there code otherwise hook will reject the push.

My problem is, when we create the local branch i want to read only those commit message which I added after administrator change but it is returning all the commit messages which is already committed by administator in DEV1.

We are using below code snippets in pre-HOOK,

-----------------------------------------------------------------------------------------------------

public boolean onReceive(RepositoryHookContext context, Collection<RefChange> refChanges, HookResponse hookResponse)

{

for (RefChange refChange : refChanges)

{

ChangesetsBetweenRequest request = new ChangesetsBetweenRequest.Builder( context.getRepository()).exclude(refChange.getFromHash()) .include(refChange.getToHash()).build();

final Page<Changeset> cs = commitService.getChangesetsBetween( request, PAGE_REQUEST);

for (Changeset changeset : cs.getValues()) {

commit_msg = changeset.getMessage();

}

}

}

Please suggest me how can we read the latest commit messages.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events