Hi All,
I given a pull request from one branch to other with one reviewer and reviewer approved it and he merged it.
In this context.
Here I able to get ll the pullrequest deatails i.e., ID,Title,Author,Reviewers,Source,Destination but
I need to capture the modified file name. i.e.,
How to get this file name. here .. I'm using RepositoryMergeRequestCheck, RepositorySettingsValidator in my class..
Thanks in advance
Anil
Now I able to get the file path with commitservice, The problem is in my callback's onChange() method I did return false.
public boolean onChange(Change change) throws IOException {
//change.getPath().getName() , Here getting the filePath
call_method_to_update_to_ticket_portals(filePath);
return false;
}
Below thread helped me to correct it.
https://answers.atlassian.com/questions/295383/check-changed-files-in-pull-request
Thanks all
Anil
Hi Anil,
I think you're looking for PullRequestService.streamChanges. That allows you to get all modified files, including the type of change (add, copy, rename, delete, modify).
Cheers,
Michael
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Michael ,
Thanks for the reply I'l implement this and let you know.
Same like this while commiting the file to my repository.
Example: git commit -m "some text" test.txt.
So in above case how to get the file name i.e., test.txt with some hook. pre/post hook.
Thanks
Anil
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Stash pre/post hooks won't run until you push your changes to Stash. They won't run when you commit in your local clone.
In a pre/post hook (on the Stash server), you'll receive a list of RefChange objects, one for each branch that was updated in the push. If you want to get a list of changed paths for the branch in question, you can use CommitService.streamChanges
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Michael,
Thanks for the suggestion.
In My postReceiveHook I did like this
public void postReceive(RepositoryHookContext context, Collection<RefChange> refChanges){
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()){
ChangesRequest changeReq = new ChangesRequest.Builder(context.getRepository(),changeset.getId()).build();
//Initialized this commitService in constructor
commitService.streamChanges(changeReq, new ChangeCallback() {
@Override
public void onStart() throws IOException {}
@Override
public void onEnd(boolean arg0) throws IOException {}
@Override
public boolean onChange(Change change) throws IOException {
//change.getPath().getName() , Here getting the filePath
call_method_to_update_to_ticket_portals(filePath);
return false;
}
});
}
Test1: Single file commit is worked.
$git commit -m "Ticket123 is fixed" test1.txt
$git push origin master
Test2: In my cloned repository, I have two files which were modified and committed.
$git commit -m "Ticket123 is fixed" test1.txt
$git commit -m "Ticket123 is fixed" test2.txt
$git push origin master
Here I'm getting the filePath name test1.txt only, but I should get both the filenames.
I suspect the problem with the above code of,
ChangesRequest changeReq = new
ChangesRequest.Builder(context.getRepository(),changeset.getId()).build();
Here, how can I get all the local committed files.
How to use untilId and sinceId above.
I tried,
ChangesRequest changeReq = newChangesRequest.Builder(context.getRepository(),
changeset.getId()).sinceId(refChange.fromHash()).build();
then also its showing me only one file name.
~Anil
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.
Anil,
In your code example, you're doing two loops: one to iterate over the commits and the second loop to iterate over the changes for each commit. With your example commits, you should be seeing test1.txt on the first commit and test2.txt on the second commit. Perhaps you haven't debugged all the way through the first loop?
You don't need to loop over the commits though. You can directly call streamChanges, which will be more efficient anyway:
public void postReceive(RepositoryHookContext context, Collection<RefChange> refChanges){ for (RefChange refChange : refChanges) { ChangesRequest changeReq = new ChangesRequest.Builder( context.getRepository(), refChange.getToHash()) .sinceId(refChange.getFromHash()) .build(); commitService.streamChanges(changeReq, yourCallbackHere); }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Michael,
I'm looping the commits because, Earlier I'm checking the commits with valid ticket (checking this in my pre-hook) and based on the ticket number I'm updating the ticket portals with commi_message,commit_id,updaed_date...etc., (ticket portals updation I'm doing in post-hook)
Here I want to update the file name so I used the streamChanges..
I think with your suggestion,
ChangesRequest changeReq =
new
ChangesRequest.Builder( context.getRepository(), refChange.getToHash())
.sinceId(refChange.getFromHash())
.build();
commitService.streamChanges(changeReq, yourCallbackHere);
commitService.streamChanges(changeReq, new ChangeCallback() {
@Override
public void onStart() throws IOException {}
@Override
public void onEnd(boolean arg0) throws IOException {}
@Override
public boolean onChange(Change change) throws IOException {
//change.getPath().getName() , Here getting the filePath
call_method_to_update_to_ticket_portals(filePath);
return false;
}
});
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'd probably split things a bit differently. I'd use a pre-hook to detect whether your commits have valid ticket numbers. I'd then use a post-hook to update the tickets portal. After all, you won't know for sure that the push has been accepted until the post-hook is called. Even if _your_ pre-hook doesn't reject the push, another hook might and you'd end up with inconsistent state in your tickets portal?
Michael
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In fact I'm also doing the same.
I'm validating the ticket validation in commited message with my pre-hook. If not It will reject.
In post-hook I'm trying to update to portals. Inorder to get the ticket number I traverse through the commits in loop.
But, with commmitService#streamChanges( request, mycallback)..
here my call back calling only once..But i'm having mutiple changes(more files) in single commit. how to get all the files details..
Anil
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Michael,
Observed that my callback not calling as per the changes.
What I'm doing now to read the commits inorder to get the ticket number to which it should update and get all the changes (All files) is :
In My post hook:
postReceive(){
for (RefChange refChange : refChanges) {
ChangesetsBetweenRequest request = new ChangesetsBetweenRequest.Builder( context.getRepository()).exclude(refChange.getFromHash()) .include(refChange.getToHash()).build();
final Page<Changeset> csComm = commitService.getChangesetsBetween( request, PAGE_REQUEST);
for (Changeset changeset : csComm .getValues()){
//FETCHING COMMIT RELATED DETAILS HERE
}
ChangesRequest changeReq = new ChangesRequest.Builder(context.getRepository(),refChange.getToHash()).sinceId(refChange.getFromHash()).build();
final Page<Change> csChange = commitService.getChanges(changeReq, PAGE_REQUEST);
for (Change change : csChange .getValues()) {
//Fetching all the files here, change.getPath().getName());
}
}//post receive end
Is it fine. I checked it it given me all the files which I changed but I suspect the efficiency.
Anil
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.
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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.