BitBucket: Use commit hash instead of branch name when the branch is not URL-safe.

Apparently, the "/src" subsection of the BitBucket API doesn't do well with branch names that contain slashes. urlencode() doesn't help. See #409 for the initial report.
This commit is contained in:
Yahnis Elsts 2021-01-28 19:10:17 +02:00
parent 0edd15f678
commit 369c19ab1a
1 changed files with 9 additions and 1 deletions

View File

@ -59,8 +59,16 @@ if ( !class_exists('Puc_v4p10_Vcs_BitBucketApi', false) ):
return null;
}
//The "/src/{stuff}/{path}" endpoint doesn't seem to handle branch names that contain slashes.
//If we don't encode the slash, we get a 404. If we encode it as "%2F", we get a 401.
//To avoid issues, if the branch name is not URL-safe, let's use the commit hash instead.
$ref = $branch->name;
if ((urlencode($ref) !== $ref) && isset($branch->target->hash)) {
$ref = $branch->target->hash;
}
return new Puc_v4p10_Vcs_Reference(array(
'name' => $branch->name,
'name' => $ref,
'updated' => $branch->target->date,
'downloadUrl' => $this->getDownloadUrl($branch->name),
));