簡體   English   中英

如何使用 REST API 訪問 bitbucket 中的源代碼?

[英]How to access source code in bitbucket using REST API?

如何訪問 java 文件,該文件位於特定 package 的存儲庫中。 位桶具有元數據信息,例如 pullrequest api,last commit REST API。 你能建議/幫助我使用示例 rest 調用以及如何傳遞用戶名和密碼嗎? 鑒於我知道完全合格的 class 名稱,包括項目。

注意:我們使用的是由我們組織托管的 bitbucket。

例如: https://bitbucket.org/repo/my-project分支:tempBranch 文件:src/main/java/temp/Main.java

我想通過 Rest 調用訪問/查看 Main.java 的全部內容。 是否有任何 REST api 存在於此?

奇怪的是,沒有辦法使用最新版本(2.0)的bitbucket.org(雲)API來執行此操作。

來自/repositories/{username}/{repo}端點的可用數據可能會將您帶到某個地方。

您可以使用/repositories/{username}/{repo}/downloads/{filename}端點訪問/repositories/{username}/{repo}/downloads/{filename} “下載”中的/repositories/{username}/{repo}/downloads/{filename}


但是,在API的1.0版本中需要滿足的終結點 根據測試,這仍然有效。

它可用(2022 年 8 月) - 請參閱獲取文件或目錄內容

實現如下 - # GET /2.0/repositories/{workspace}/{repo_slug}/src/{commit}/{path}為用戶創建應用程序密碼,如果源中有管道bitbucket-pipelines.yml ,那么你可以使用以下方法保存它:

$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"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM