Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: is fork sync supported? #163

Closed
KaiserZip opened this issue Oct 24, 2018 · 21 comments
Closed

Question: is fork sync supported? #163

KaiserZip opened this issue Oct 24, 2018 · 21 comments
Assignees
Milestone

Comments

@KaiserZip
Copy link

Hello,

Is the "sync" feature supported by your java api?

equivalent of:
https://docs.atlassian.com/DAC/rest/stash/3.7.2/stash-repository-ref-sync-rest.html
"Enables or disables synchronization for the specified repository"

Thanks in advance for your answer, and great job for the work you did :)
Brgds

@cdancy
Copy link
Owner

cdancy commented Oct 25, 2018

Not currently supported but would definitely be good to have. Are you interested in submitting a PR or did you want one of us to take care of it? I'm off for the next few days and maybe be able to knock things out.

@KaiserZip
Copy link
Author

I'm afraid I wouldn't know how to implement the feature... but if one of you wants to work on it, I would be definitely interested :)

@cdancy
Copy link
Owner

cdancy commented Oct 26, 2018

Ok let me see what I can knock out. Stay tuned...

@KaiserZip
Copy link
Author

Hi Christopher,
Did you have time to work on this one? :)
Thanks

@cdancy
Copy link
Owner

cdancy commented Jan 6, 2019

Actually been meaning to circle back on this as there is interest here to have this feature. Let me see what I can make happen over the next couple days.

@cdancy
Copy link
Owner

cdancy commented Jan 14, 2019

Initial impl put together here: #166. Should finish up things tomorrow once I can write some live tests and finish the synchronize endpoint

@cdancy cdancy added this to the v2.4.0 milestone Jan 14, 2019
@KaiserZip
Copy link
Author

nice job thanks :) is it ready for merge?

@cdancy cdancy modified the milestones: v2.4.0, v2.3.1 Feb 16, 2019
@cdancy
Copy link
Owner

cdancy commented Feb 16, 2019

@KaiserZip PR has just been merged to master and am doing a release shortly. Sorry things took so long but had some issues writing integration tests and simply didn't have the time to sort things out until now. Stay tuned...

@cdancy
Copy link
Owner

cdancy commented Feb 16, 2019

Version 2.4.0 has been released. Give things a go and let me know if you have any questions.

@cdancy cdancy closed this as completed Feb 16, 2019
@KaiserZip
Copy link
Author

KaiserZip commented Feb 18, 2019

Thanks @cdancy I've moved from 2.3.0 to 2.4.0 and this works like a charm:

client.api().syncApi().enable(fork, repo, true);

But I've noticed that on 2.4.0 my following call is now broken:

client.api().pullRequestApi().create(project, repo, prRequest);

failing with:

message=Failed to parse output: message=com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 9 path $, exceptionName=com.google.gson.JsonSyntaxException, conflicted=false, vetoes=[]}]

when reverting back to 2.3.0 it works fine :)
any idea why?

Thanks for your support :)

@cdancy
Copy link
Owner

cdancy commented Feb 19, 2019

@KaiserZip is it reproducible? Can you possibly run this code with debug turned out to get more logs? This generally pops when an unknown response is returned. When you do this does the actual PR get created but the call just fails?

@KaiserZip
Copy link
Author

When you do this does the actual PR get created but the call just fails?

nope, with 2.4.0 call fails with above error + PR is not created
and with 2.3.0 call is successfull + PR is created

The diff between both versions is only PR 166 + PR 168 right?

@KaiserZip
Copy link
Author

Okay I think I've spotted the problem:

I am using this code:

MinimalRepository fromRepo = MinimalRepository.create("myRepo", null, ProjectKey.create("fromProject"));
MinimalRepository toRepo = MinimalRepository.create("myRepo", null, ProjectKey.create("toProject"));

Reference fromRef = Reference.create("myBranch", fromRepo);
Reference toRef = Reference.create("myBranch", toRepo);

CreatePullRequest prRequest = CreatePullRequest.create("prTitle", "prDescription", fromRef, toRef, null, null);
client.api().pullRequestApi().create("toProject", "myRepo", prRequest);

The resulting java objects seem correct, but at some point there's a java->json transformation when building the http payload of the request sent to bitbucket server, and the json itself is different between both versions:

bitbucket-rest:2.3.0:

{"title":"prTitle","description":"prDescription","state":"OPEN","open":true,"closed":false,"fromRef":{"id":"myBranch","repository":{"slug":"myRepo","project":{"key":"fromProject"}},"displayId":"myBranch"},"toRef":{"id":"myBranch","repository":{"slug":"myRepo","project":{"key":"toProject"}},"displayId":"myBranch"},"locked":false}

bitbucket-rest:2.4.0:

{"title":"prTitle","description":"description","state":"OPEN","open":true,"closed":false,"fromRef":{"id":[],"repository":"myBranch","state":{"slug":"myRepo","project":{"key":"fromProject"}},"latestCommit":"myBranch"},"toRef":{"id":[],"repository":"myBranch","state":{"slug":"myRepo","project":{"key":"toProject"}},"latestCommit":"myBranch"},"locked":false}

In 2nd case the server replies with an error 500, leading to MalformedJsonException and PR not being created...

Any clue why this java->json transformation is messed-up with 2.4.0? :)

Thanks

@cdancy
Copy link
Owner

cdancy commented Feb 20, 2019

That's interesting. No idea at the moment but poking around now. Stay tuned...

@KaiserZip
Copy link
Author

shouldn't we have

@SerializedNames({ "errors", "id", "repository", "state", "tag", "displayId", "latestCommit" })

instead of

@SerializedNames({ "id", "repository", "state", "tag", "displayId", "latestCommit", "errors" })

in Reference.java?

@cdancy
Copy link
Owner

cdancy commented Feb 20, 2019

No that just produces more errors unfortunately :(

I do however believe it has something to do with the fact that the Reference pojo now implements ErrorsHolder on account of the SyncApi. If I can't find a sane way around things we'll have to break things out about a bit.

@cdancy
Copy link
Owner

cdancy commented Feb 20, 2019

yeah so what I'm going with is to revert the changes to Reference so that your code will work and then change the SyncApi to return a SyncState instead of trying to piggyback on the Reference object which is causing issues. Might take a day or 2 as I'm busy at the moment.

@KaiserZip
Copy link
Author

KaiserZip commented Feb 21, 2019

yes for sure it is linked to the fact that Reference now implements ErrorsHolder and the errors is now at first index instead of id

for instance, as a test, I've manually added a fake error to my fromRef:

List<Error> errors = Arrays.asList(Error.create("err1", "err1", "err1", true, null));
Reference fromRef = Reference.create("myBranch", fromFork, null, null, "myBranch", null, errors );

and in the resulting json, the error can be seen instead of the id:

"fromRef":{"id":[{"context":"err1","message":"err1","exceptionName":"err1","conflicted":true,"vetoes":[]}],"repository":"myBranch","state":{"slug":"myRepo","project":{"key":"fromProject"}},"latestCommit":"myBranch"}

@cdancy
Copy link
Owner

cdancy commented Feb 26, 2019

@KaiserZip version 2.4.3 has been released with the fix. Let me know how things work out for you.

@cdancy
Copy link
Owner

cdancy commented Feb 26, 2019

It should be noted that SyncApi.synchronize now returns a SyncState object instead of Reference object. It's a breaking change, which is no good, but there really is no other way around this. It was an over aggressive optimization on my part.

@KaiserZip
Copy link
Author

works perfectly, thanks a lot! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants