Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/github-cli/devcontainer-feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"extensions": {
"type": "string",
"default": "",
"description": "Comma-separated list of GitHub CLI extensions to install (e.g. 'dlvhdr/gh-dash,github/gh-copilot')."
"description": "Comma-separated list of GitHub CLI extensions to install (e.g. 'dlvhdr/gh-dash,github/gh-copilot'). Append ':<tag>' to pin a version (e.g. 'github/gh-stack:v1.0.0')."
}
},
"customizations": {
Expand Down
20 changes: 17 additions & 3 deletions src/github-cli/scripts/install-extensions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,32 @@ trim() {
install_extension() {
local extension="$1"
local extensions_root
local repo
local tag
local repo_name
local install_args=()
local clone_args=()

repo="${extension%%:*}"
if [ "${repo}" != "${extension}" ]; then
tag="${extension#*:}"
fi

extensions_root="${XDG_DATA_HOME:-"${HOME}/.local/share"}/gh/extensions"
repo_name="${extension##*/}"
repo_name="${repo##*/}"

if [ -n "${tag}" ]; then
install_args=(--pin "${tag}")
clone_args=(--branch "${tag}")
fi

mkdir -p "${extensions_root}"
if [ ! -d "${extensions_root}/${repo_name}" ]; then
if ! gh extension install "${extension}"; then
if ! gh extension install "${repo}" "${install_args[@]}"; then
git \
-c credential.helper= \
-c credential.helper='!gh auth git-credential' \
clone --depth 1 "https://github.com/${extension}.git" "${extensions_root}/${repo_name}"
clone --depth 1 "${clone_args[@]}" "https://github.com/${repo}.git" "${extensions_root}/${repo_name}"
fi
fi
}
Expand Down
2 changes: 2 additions & 0 deletions test/github-cli/install_extensions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ check "gh-extension-installed" gh extension list | grep -q 'dlvhdr/gh-dash'
check "gh-extension-installed-2" gh extension list | grep -q 'github/gh-copilot'
check "gh-extension-installed-3" gh extension list | grep -q 'github/gh-aw'
check "gh-aw-runs" gh aw version
check "gh-extension-pinned-tag" grep -q 'tag: v0.88.8' "${XDG_DATA_HOME:-"${HOME}/.local/share"}/gh/extensions/gh-aw/manifest.yml"
check "gh-extension-pinned-flag" grep -q 'ispinned: true' "${XDG_DATA_HOME:-"${HOME}/.local/share"}/gh/extensions/gh-aw/manifest.yml"

# Report result
reportResults
2 changes: 1 addition & 1 deletion test/github-cli/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"features": {
"github-cli": {
"version": "latest",
"extensions": "dlvhdr/gh-dash,github/gh-copilot,github/gh-aw"
"extensions": "dlvhdr/gh-dash,github/gh-copilot,github/gh-aw:v0.88.8"
}
}
}
Expand Down