簡體   English   中英

如何直接在 Azure Git 存儲庫中更新 excel 輸入文件,而無需將整個項目文件夾下載到本地計算機

[英]How to update excel input file directly in Azure Git repository without downloading the entire project folder to local machine

我在 Azure Z0BCC70105AD27957B66B7 中有一個 java maven 項目(Eclipse)。 這是一個基於 excel 中給出的輸入在系統中創建數據的測試項目。 目前,我已使用 git 在本地計算機上克隆了整個項目,更新輸入 excel 文件並推送到 Azure 存儲庫,然后再運行測試。 有沒有辦法直接在存儲庫中推送對輸入 excel 文件的更改,而無需將整個項目文件夾下載到本地?

也許,使用Azure DevOps Services REST / Pushes - Create

POST https://dev.azure.com/fabrikam/_apis/git/repositories/{repositoryId}/pushes?api-version=6.0

但與一個簡單的腳本相比,這似乎需要做很多工作,每次你在本地修改你的 Excel 文件時:

  • git add
  • git commit
  • git push

直接上傳就行了...

上傳

...自然,它會創建一個提交,但這很容易。 我之前在沒有 IDE 的情況下通過簡單地在線編輯存儲庫中的現有文件進行了代碼更改。

您可以使用 REST 和 Powershell 來更新遠程倉庫上的文件....例如:

$user = ""
$token = "<PAT>" #https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=preview-page

$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
$orgUrl = "https://dev.azure.com/<org>"
$teamProject = "TestProject"
$repoName = "Repo1"

$localFilePath = 'c:/temp/tst.xlsx'
$gitFilePath = 'testfolder/tst.xlsx'
$gitBranch = "master"

$restApiUpdateFile = "$orgUrl/$teamProject/_apis/git/repositories/$repoName/pushes?api-version=6.1-preview.2"
$restApiGetMasterRef = "$orgUrl/$teamProject/_apis/git/repositories/$repoName/refs?filter=heads/$gitBranch`&api-version=6.1-preview.1"

$fileContentToUpdate = [convert]::ToBase64String((Get-Content -path $localFilePath -Encoding byte))

function InvokeGetRequest ($GetUrl)
{    
    return Invoke-RestMethod -Uri $GetUrl -Method Get -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}    
}

function InvokePostRequest ($PostUrl, $body)
{   
    return Invoke-RestMethod -Uri $PostUrl -Method Post -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}  -Body $body
}

$updateBody = @"
{
    "refUpdates": [
      {
        "name": "refs/heads/{gitbranchpath}",
        "oldObjectId": "{mainBranchObjectId}"
      }
    ],
    "commits": [
      {
        "comment": "Updates file",
        "changes": [
          {
            "changeType": "edit",
            "item": {
              "path": "{filePathToUpdate}"
            },
            "newContent": {
              "content": "{newFileContentToUpdate}",
              "contentType": "base64encoded"
            }
          }
        ]
      }
    ]
  }
"@

$res = InvokeGetRequest $restApiGetMasterRef

$updateBody = $updateBody.Replace("{gitbranchpath}", $gitBranch);
$updateBody = $updateBody.Replace("{mainBranchObjectId}", $res.value[0].objectId);
$updateBody = $updateBody.Replace("{filePathToUpdate}", $gitFilePath);
$updateBody = $updateBody.Replace("{newFileContentToUpdate}", $fileContentToUpdate);


InvokePostRequest $restApiUpdateFile $updateBody

我們無法在 web 瀏覽器上的 Git 存儲庫中直接打開和編輯 Excel 文件。

我嘗試了幾個基於 Git 的版本控制平台(Azure Git Repos、GutHub、GitLab、Bitbucket 等)。 然后都不允許用戶直接打開和編輯 Git 存儲庫中的 Excel 文件。

我也沒有找到任何可用的擴展可以幫助做到這一點。

因此,您需要將Excel文件下載到MS Office安裝的本地,然后在本地打開並編輯。

暫無
暫無

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

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