Skip to content
Merged
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
14 changes: 10 additions & 4 deletions gh-cli/get-actions-usage-in-organization.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,16 @@ resolve_sha_to_tag() {

# Check if we have tags cached for this action
if [ ! -f "$action_cache_file" ]; then
# Fetch and cache all tags for this action
gh api repos/"$action_name"/git/refs/tags --paginate 2>/dev/null | \
jq -r '.[] | "\(.object.sha)|\(.ref | sub("refs/tags/"; ""))"' 2>/dev/null > "$action_cache_file" || \
touch "$action_cache_file"
# Fetch and cache all tags for this action (handles both lightweight and annotated tags)
{
# Get lightweight tags
gh api repos/"$action_name"/git/refs/tags --paginate 2>/dev/null | \
jq -r '.[] | "\(.object.sha)|\(.ref | sub("refs/tags/"; ""))"' 2>/dev/null

# Get annotated tags (dereference to commit SHA)
gh api repos/"$action_name"/tags --paginate 2>/dev/null | \
jq -r '.[] | "\(.commit.sha)|\(.name)"' 2>/dev/null
} | sort -u > "$action_cache_file" || touch "$action_cache_file"
fi

# Look up the SHA in the cached tags
Expand Down
29 changes: 26 additions & 3 deletions gh-cli/get-actions-usage-in-repository.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,34 @@ resolve_sha_to_tag() {

# Only process if it looks like a SHA (40 character hex string)
if [[ ${#sha} -eq 40 && "$sha" =~ ^[a-f0-9]+$ ]]; then
# Try to find a tag that points to this commit SHA
# Try to find a tag that points to this commit SHA (handles both lightweight and annotated tags)
local tag_name
# First try to find a semantic version tag (prefer v1.2.3 over v1)
tag_name=$(gh api repos/"$action_name"/git/refs/tags --paginate 2>/dev/null | jq -r --arg sha "$sha" '.[] | select(.object.sha == $sha) | .ref | sub("refs/tags/"; "")' 2>/dev/null | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+' | head -1)
tag_name=$(
{
# Get lightweight tags
gh api repos/"$action_name"/git/refs/tags --paginate 2>/dev/null | \
jq -r --arg sha "$sha" '.[] | select(.object.sha == $sha) | .ref | sub("refs/tags/"; "")' 2>/dev/null

# Get annotated tags (dereference to commit SHA)
gh api repos/"$action_name"/tags --paginate 2>/dev/null | \
jq -r --arg sha "$sha" '.[] | select(.commit.sha == $sha) | .name' 2>/dev/null
} | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+' | head -1
)

# If no semantic version found, fall back to any tag
if [ -z "$tag_name" ]; then
tag_name=$(gh api repos/"$action_name"/git/refs/tags --paginate 2>/dev/null | jq -r --arg sha "$sha" '.[] | select(.object.sha == $sha) | .ref | sub("refs/tags/"; "")' 2>/dev/null | head -1)
tag_name=$(
{
# Get lightweight tags
gh api repos/"$action_name"/git/refs/tags --paginate 2>/dev/null | \
jq -r --arg sha "$sha" '.[] | select(.object.sha == $sha) | .ref | sub("refs/tags/"; "")' 2>/dev/null

# Get annotated tags (dereference to commit SHA)
gh api repos/"$action_name"/tags --paginate 2>/dev/null | \
jq -r --arg sha "$sha" '.[] | select(.commit.sha == $sha) | .name' 2>/dev/null
} | head -1
)
fi

if [ -n "$tag_name" ] && [ "$tag_name" != "null" ]; then
Expand Down Expand Up @@ -93,4 +113,7 @@ if [ "$resolve_shas" == "true" ]; then
results=$(echo -e "$temp_results" | sed '/^$/d')
fi

# Sort results alphabetically
results=$(echo -e "$results" | sort)

echo -e "$results"