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

Bitbucket: "Resource not found" retrieving Changesets from branch containing "/" #376

Closed
Hainv201 opened this issue Jul 23, 2021 · 5 comments

Comments

@Hainv201
Copy link

The plugins is not able to retrieve changesets from branches contains "/" on their branch name from Bitbucket.
Examples:
Retrieving feature/ChangeRequests ... failed (Resource not found).
Retrieving feature/DescriptiveNames ... failed (Resource not found).
Retrieving feature/initial_commit ... failed (Resource not found).

Problem:

if( !preg_match( '/*|^[a-zA-Z0-9_., -]*$/', $f_master_branch ) ) {
echo 'Invalid parameter: 'Primary Branch'';
trigger_error( ERROR_GENERIC, ERROR );
}
From SourceBitBucket.php is not allow to have "/" in the branch name

@dregad
Copy link
Member

dregad commented Jul 24, 2021

Can you please check if replacing the above-mentioned code block by

$this->ensure_branch_valid( $f_master_branch );

fixes the problem ?

@Hainv201
Copy link
Author

Hainv201 commented Jul 28, 2021

@dregad Thanks for your answer. It helps to use branch with "/" as the Primary Branch or I used "*" as the Primary Branch and then I tried to retrieve changesets, it did not work. I got the same messages.
Based on the implementation on the SourceBitBucket.php, I think somehow, the plugin thinks the branch with "/" in it's name is a commit of the parent branch.

@dregad
Copy link
Member

dregad commented Dec 28, 2021

I had a look at this today, apologies for the long delay.

So there are 2 issues:

Validation of branch selection

Can be fixed as mentioned in my earlier note (#376 (comment)). Note that it would actually be more appropriate to use

$this->validate_branch_list( $f_master_branch );

Resource not found error

I confirm the issue, which occurs when importing changesets for a branch having / in its name.

The plugin makes the following Bitbucket API call :
repositories/$t_username/$t_reponame/commit/$t_commit_id, where in the loop's first iteration $t_commit_id is the branch name, e.g. https://bitbucket.org/api/2.0/repositories/dregad/test/commit/release/v2

{
  "type": "error",
  "error": {
    "message": "Resource not found",
    "detail": "There is no API hosted at this URL.\n\nFor information about our API's, please refer to the documentation at: https://developer.atlassian.com/bitbucket/api/2/reference/"
  }
}

So AFAICT, this is actually caused by the Bitbucket API itself. I found this: https://jira.atlassian.com/browse/BCLOUD-9969

As a workaround, we could lookup the branch's target commit if the name contains a /.

@dregad dregad closed this as completed Dec 28, 2021
@dregad dregad reopened this Dec 28, 2021
@5dive
Copy link

5dive commented Dec 28, 2021

See if this PR helps you:

jenkins-x/go-scm#295
sorry, fix is for go-scm

@dregad
Copy link
Member

dregad commented Dec 28, 2021

@5dive thanks for the link
I think I got this already - pretty much the same approach, i.e. if the branch contains a /, get the commit SHA via repositories/$t_username/$t_reponame/refs/branches/$t_branch (target->hash)

@dregad dregad changed the title Retrieve Changesets from branch contains "/" from Bitbucket Bitbucket: "Resource not found" retrieving Changesets from branch containing "/" Dec 28, 2021
@dregad dregad added this to the 2.5.0 milestone Dec 28, 2021
@dregad dregad closed this as completed in bfc6bdb Dec 28, 2021
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

3 participants