0

How to access a java file which is sitting in repo in a specific package. Bit bucket has meta data info like pullrequest api,last commit REST APIs. can you suggest/help me with sample rest call and also how to pass username and password? given that I know fully qualified class name including project.

note: we are using bitbucket which hosted with our organization.

Ex: https://bitbucket.org/repo/my-project branch: tempBranch file:src/main/java/temp/Main.java

I would like to access/view full content on Main.java with in the Rest call. is there any REST api exist for this ?

user12
  • 239
  • 2
  • 6
  • 18

2 Answers2

0

Strangely there is no way to do this using the latest version (2.0) of the bitbucket.org (cloud) API.

The available data from the /repositories/{username}/{repo} endpoint may lead you to somewhere.

You can access files in the 'downloads' of your repo using the /repositories/{username}/{repo}/downloads/{filename} endpoint.


However There is an endpoint for what you need in version 1.0 of the API. Based on testing this still works.

Peter Reid
  • 5,139
  • 2
  • 37
  • 33
0

It is available (aug 2022) - see Get file or directory contents

Implementation as follows - # GET /2.0/repositories/{workspace}/{repo_slug}/src/{commit}/{path} create app password for the user, if you have pipeline bitbucket-pipelines.yml in the source, then you can save it using:

$pairCloud         = "{... your user ...}:{... your app password ...}" 
$credentialsCloud  = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($pairCloud))
$headersBasicCloud = @{"accept" = "application/json"; "authorization" = "Basic $credentialsCloud"} 
$bbCloudApi2Url    = "https://api.bitbucket.org/2.0"

$workspace = "... put your workspace ..."
$repo      = "... put your repo_slug ..."
$commit    = "... put your commit ..."

$pplUrl    = "$bbCloudApi2Url/repositories/$workspace/$repo/src/$commit/bitbucket-pipelines.yml"

$ymlppl  = Invoke-WebRequest -Uri $pplUrl -Headers $headersBasicCloud
$ymlppl.Content | Out-File "bitbucket-pipelines.yml"
Sasha Bond
  • 984
  • 10
  • 13