0
0

Azure DevOpsのプライベートリポジトリから特定のディレクトリだけをZIPでダウンロードする

Posted at

概要

Azure DevOpsで管理しているソースコードから一部ファイル群だけほしい状況があり、試しにbashで取得できないか試行しました。一部ファイル群だけほしいのは、プログラム中で取得する必要があるが、リポジトリが巨大で全部をcloneする時間が惜しかったからです。

コード

#!/bin/bash

organization="organization"
project="project"
repository="repository"
directory="directory"
pat="personal access token"
localPath="path"

# 特定のディレクトリだけをダウンロード
url="https://dev.azure.com/${organization}/${project}/_apis/git/repositories/${repository}/items/items?path=${directory}&versionDescriptor%5BversionOptions%5D=0&versionDescriptor%5BversionType%5D=0&versionDescriptor%5Bversion%5D=master&resolveLfs=true&\$format=zip&api-version=7.2-preview&download=true"

curl -u ":${pat}" -L "${url}" -o "${localPath}"

注意点

  • personal access tokenはbearerではなくbasic
  • versionDescriptor[BversionOptions]=0などのカッコはちゃんとBase64 URLエンコードを施す
  • $もエスケープする

雑感

URLの形式がわからず、GitHub Copilotに生成してもらいましたが、ほぼ正しく生成してくれました。
とても便利。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0