chore: update bash to follow shellcheck recommendations (#6102)
This commit is contained in:
parent
9912577a2b
commit
0e8bbfb8ba
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
# Initialize a comma-separated string to hold PR numbers that need a comment
|
# Initialize a comma-separated string to hold PR numbers that need a comment
|
||||||
|
@ -6,13 +6,23 @@ PRS_NEEDING_COMMENT=""
|
||||||
|
|
||||||
# Function to process a single PR
|
# Function to process a single PR
|
||||||
process_pr() {
|
process_pr() {
|
||||||
|
if [[ -z "${GITHUB_REPOSITORY:-}" ]]; then
|
||||||
|
echo "‼️ Missing \$GITHUB_REPOSITORY - this must be run from GitHub Actions"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "${GITHUB_OUTPUT:-}" ]]; then
|
||||||
|
echo "‼️ Missing \$GITHUB_OUTPUT - this must be run from GitHub Actions"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
local PR_NUMBER=$1
|
local PR_NUMBER=$1
|
||||||
echo "🔄 Processing PR #$PR_NUMBER"
|
echo "🔄 Processing PR #${PR_NUMBER}"
|
||||||
|
|
||||||
# Get PR body with error handling
|
# Get PR body with error handling
|
||||||
local PR_BODY
|
local PR_BODY
|
||||||
if ! PR_BODY=$(gh pr view "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --json body -q .body 2>/dev/null); then
|
if ! PR_BODY=$(gh pr view "${PR_NUMBER}" --repo "${GITHUB_REPOSITORY}" --json body -q .body 2>/dev/null); then
|
||||||
echo " ⚠️ Could not fetch PR #$PR_NUMBER details"
|
echo " ⚠️ Could not fetch PR #${PR_NUMBER} details"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -20,67 +30,67 @@ process_pr() {
|
||||||
local ISSUE_NUMBER=""
|
local ISSUE_NUMBER=""
|
||||||
|
|
||||||
# Pattern 1: Direct reference like #123
|
# Pattern 1: Direct reference like #123
|
||||||
if [ -z "$ISSUE_NUMBER" ]; then
|
if [[ -z "${ISSUE_NUMBER}" ]]; then
|
||||||
ISSUE_NUMBER=$(echo "$PR_BODY" | grep -oE '#[0-9]+' | head -1 | sed 's/#//' 2>/dev/null || echo "")
|
ISSUE_NUMBER=$(echo "${PR_BODY}" | grep -oE '#[0-9]+' | head -1 | sed 's/#//' 2>/dev/null || echo "")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Pattern 2: Closes/Fixes/Resolves patterns (case-insensitive)
|
# Pattern 2: Closes/Fixes/Resolves patterns (case-insensitive)
|
||||||
if [ -z "$ISSUE_NUMBER" ]; then
|
if [[ -z "${ISSUE_NUMBER}" ]]; then
|
||||||
ISSUE_NUMBER=$(echo "$PR_BODY" | grep -iE '(closes?|fixes?|resolves?) #[0-9]+' | grep -oE '#[0-9]+' | head -1 | sed 's/#//' 2>/dev/null || echo "")
|
ISSUE_NUMBER=$(echo "${PR_BODY}" | grep -iE '(closes?|fixes?|resolves?) #[0-9]+' | grep -oE '#[0-9]+' | head -1 | sed 's/#//' 2>/dev/null || echo "")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$ISSUE_NUMBER" ]; then
|
if [[ -z "${ISSUE_NUMBER}" ]]; then
|
||||||
echo "⚠️ No linked issue found for PR #$PR_NUMBER, adding status/need-issue label"
|
echo "⚠️ No linked issue found for PR #${PR_NUMBER}, adding status/need-issue label"
|
||||||
if ! gh pr edit "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --add-label "status/need-issue" 2>/dev/null; then
|
if ! gh pr edit "${PR_NUMBER}" --repo "${GITHUB_REPOSITORY}" --add-label "status/need-issue" 2>/dev/null; then
|
||||||
echo " ⚠️ Failed to add label (may already exist or have permission issues)"
|
echo " ⚠️ Failed to add label (may already exist or have permission issues)"
|
||||||
fi
|
fi
|
||||||
# Add PR number to the list
|
# Add PR number to the list
|
||||||
if [ -z "$PRS_NEEDING_COMMENT" ]; then
|
if [[ -z "${PRS_NEEDING_COMMENT}" ]]; then
|
||||||
PRS_NEEDING_COMMENT="$PR_NUMBER"
|
PRS_NEEDING_COMMENT="${PR_NUMBER}"
|
||||||
else
|
else
|
||||||
PRS_NEEDING_COMMENT="$PRS_NEEDING_COMMENT,$PR_NUMBER"
|
PRS_NEEDING_COMMENT="${PRS_NEEDING_COMMENT},${PR_NUMBER}"
|
||||||
fi
|
fi
|
||||||
echo "needs_comment=true" >> $GITHUB_OUTPUT
|
echo "needs_comment=true" >> "${GITHUB_OUTPUT}"
|
||||||
else
|
else
|
||||||
echo "🔗 Found linked issue #$ISSUE_NUMBER"
|
echo "🔗 Found linked issue #${ISSUE_NUMBER}"
|
||||||
|
|
||||||
# Remove status/need-issue label if present
|
# Remove status/need-issue label if present
|
||||||
if ! gh pr edit "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --remove-label "status/need-issue" 2>/dev/null; then
|
if ! gh pr edit "${PR_NUMBER}" --repo "${GITHUB_REPOSITORY}" --remove-label "status/need-issue" 2>/dev/null; then
|
||||||
echo " status/need-issue label not present or could not be removed"
|
echo " status/need-issue label not present or could not be removed"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get issue labels
|
# Get issue labels
|
||||||
echo "📥 Fetching labels from issue #$ISSUE_NUMBER"
|
echo "📥 Fetching labels from issue #${ISSUE_NUMBER}"
|
||||||
local ISSUE_LABELS=""
|
local ISSUE_LABELS=""
|
||||||
if ! ISSUE_LABELS=$(gh issue view "$ISSUE_NUMBER" --repo "$GITHUB_REPOSITORY" --json labels -q '.labels[].name' 2>/dev/null | tr '\n' ',' | sed 's/,$//' || echo ""); then
|
if ! ISSUE_LABELS=$(gh issue view "${ISSUE_NUMBER}" --repo "${GITHUB_REPOSITORY}" --json labels -q '.labels[].name' 2>/dev/null | tr '\n' ',' | sed 's/,$//' || echo ""); then
|
||||||
echo " ⚠️ Could not fetch issue #$ISSUE_NUMBER (may not exist or be in different repo)"
|
echo " ⚠️ Could not fetch issue #${ISSUE_NUMBER} (may not exist or be in different repo)"
|
||||||
ISSUE_LABELS=""
|
ISSUE_LABELS=""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get PR labels
|
# Get PR labels
|
||||||
echo "📥 Fetching labels from PR #$PR_NUMBER"
|
echo "📥 Fetching labels from PR #${PR_NUMBER}"
|
||||||
local PR_LABELS=""
|
local PR_LABELS=""
|
||||||
if ! PR_LABELS=$(gh pr view "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --json labels -q '.labels[].name' 2>/dev/null | tr '\n' ',' | sed 's/,$//' || echo ""); then
|
if ! PR_LABELS=$(gh pr view "${PR_NUMBER}" --repo "${GITHUB_REPOSITORY}" --json labels -q '.labels[].name' 2>/dev/null | tr '\n' ',' | sed 's/,$//' || echo ""); then
|
||||||
echo " ⚠️ Could not fetch PR labels"
|
echo " ⚠️ Could not fetch PR labels"
|
||||||
PR_LABELS=""
|
PR_LABELS=""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo " Issue labels: $ISSUE_LABELS"
|
echo " Issue labels: ${ISSUE_LABELS}"
|
||||||
echo " PR labels: $PR_LABELS"
|
echo " PR labels: ${PR_LABELS}"
|
||||||
|
|
||||||
# Convert comma-separated strings to arrays
|
# Convert comma-separated strings to arrays
|
||||||
local ISSUE_LABEL_ARRAY PR_LABEL_ARRAY
|
local ISSUE_LABEL_ARRAY PR_LABEL_ARRAY
|
||||||
IFS=',' read -ra ISSUE_LABEL_ARRAY <<< "$ISSUE_LABELS"
|
IFS=',' read -ra ISSUE_LABEL_ARRAY <<< "${ISSUE_LABELS}"
|
||||||
IFS=',' read -ra PR_LABEL_ARRAY <<< "$PR_LABELS"
|
IFS=',' read -ra PR_LABEL_ARRAY <<< "${PR_LABELS}"
|
||||||
|
|
||||||
# Find labels to add (on issue but not on PR)
|
# Find labels to add (on issue but not on PR)
|
||||||
local LABELS_TO_ADD=""
|
local LABELS_TO_ADD=""
|
||||||
for label in "${ISSUE_LABEL_ARRAY[@]}"; do
|
for label in "${ISSUE_LABEL_ARRAY[@]}"; do
|
||||||
if [ -n "$label" ] && [[ ! " ${PR_LABEL_ARRAY[*]} " =~ " ${label} " ]]; then
|
if [[ -n "${label}" ]] && [[ " ${PR_LABEL_ARRAY[*]} " != *" ${label} "* ]]; then
|
||||||
if [ -z "$LABELS_TO_ADD" ]; then
|
if [[ -z "${LABELS_TO_ADD}" ]]; then
|
||||||
LABELS_TO_ADD="$label"
|
LABELS_TO_ADD="${label}"
|
||||||
else
|
else
|
||||||
LABELS_TO_ADD="$LABELS_TO_ADD,$label"
|
LABELS_TO_ADD="${LABELS_TO_ADD},${label}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
@ -88,65 +98,65 @@ process_pr() {
|
||||||
# Find labels to remove (on PR but not on issue)
|
# Find labels to remove (on PR but not on issue)
|
||||||
local LABELS_TO_REMOVE=""
|
local LABELS_TO_REMOVE=""
|
||||||
for label in "${PR_LABEL_ARRAY[@]}"; do
|
for label in "${PR_LABEL_ARRAY[@]}"; do
|
||||||
if [ -n "$label" ] && [[ ! " ${ISSUE_LABEL_ARRAY[*]} " =~ " ${label} " ]]; then
|
if [[ -n "${label}" ]] && [[ " ${ISSUE_LABEL_ARRAY[*]} " != *" ${label} "* ]]; then
|
||||||
# Don't remove status/need-issue since we already handled it
|
# Don't remove status/need-issue since we already handled it
|
||||||
if [ "$label" != "status/need-issue" ]; then
|
if [[ "${label}" != "status/need-issue" ]]; then
|
||||||
if [ -z "$LABELS_TO_REMOVE" ]; then
|
if [[ -z "${LABELS_TO_REMOVE}" ]]; then
|
||||||
LABELS_TO_REMOVE="$label"
|
LABELS_TO_REMOVE="${label}"
|
||||||
else
|
else
|
||||||
LABELS_TO_REMOVE="$LABELS_TO_REMOVE,$label"
|
LABELS_TO_REMOVE="${LABELS_TO_REMOVE},${label}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Apply label changes
|
# Apply label changes
|
||||||
if [ -n "$LABELS_TO_ADD" ]; then
|
if [[ -n "${LABELS_TO_ADD}" ]]; then
|
||||||
echo "➕ Adding labels: $LABELS_TO_ADD"
|
echo "➕ Adding labels: ${LABELS_TO_ADD}"
|
||||||
if ! gh pr edit "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --add-label "$LABELS_TO_ADD" 2>/dev/null; then
|
if ! gh pr edit "${PR_NUMBER}" --repo "${GITHUB_REPOSITORY}" --add-label "${LABELS_TO_ADD}" 2>/dev/null; then
|
||||||
echo " ⚠️ Failed to add some labels"
|
echo " ⚠️ Failed to add some labels"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$LABELS_TO_REMOVE" ]; then
|
if [[ -n "${LABELS_TO_REMOVE}" ]]; then
|
||||||
echo "➖ Removing labels: $LABELS_TO_REMOVE"
|
echo "➖ Removing labels: ${LABELS_TO_REMOVE}"
|
||||||
if ! gh pr edit "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --remove-label "$LABELS_TO_REMOVE" 2>/dev/null; then
|
if ! gh pr edit "${PR_NUMBER}" --repo "${GITHUB_REPOSITORY}" --remove-label "${LABELS_TO_REMOVE}" 2>/dev/null; then
|
||||||
echo " ⚠️ Failed to remove some labels"
|
echo " ⚠️ Failed to remove some labels"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$LABELS_TO_ADD" ] && [ -z "$LABELS_TO_REMOVE" ]; then
|
if [[ -z "${LABELS_TO_ADD}" ]] && [[ -z "${LABELS_TO_REMOVE}" ]]; then
|
||||||
echo "✅ Labels already synchronized"
|
echo "✅ Labels already synchronized"
|
||||||
fi
|
fi
|
||||||
echo "needs_comment=false" >> $GITHUB_OUTPUT
|
echo "needs_comment=false" >> "${GITHUB_OUTPUT}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# If PR_NUMBER is set, process only that PR
|
# If PR_NUMBER is set, process only that PR
|
||||||
if [ -n "${PR_NUMBER:-}" ]; then
|
if [[ -n "${PR_NUMBER:-}" ]]; then
|
||||||
if ! process_pr "$PR_NUMBER"; then
|
if ! process_pr "${PR_NUMBER}"; then
|
||||||
echo "❌ Failed to process PR #$PR_NUMBER"
|
echo "❌ Failed to process PR #${PR_NUMBER}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# Otherwise, get all open PRs and process them
|
# Otherwise, get all open PRs and process them
|
||||||
# The script logic will determine which ones need issue linking or label sync
|
# The script logic will determine which ones need issue linking or label sync
|
||||||
echo "📥 Getting all open pull requests..."
|
echo "📥 Getting all open pull requests..."
|
||||||
if ! PR_NUMBERS=$(gh pr list --repo "$GITHUB_REPOSITORY" --state open --limit 1000 --json number -q '.[].number' 2>/dev/null); then
|
if ! PR_NUMBERS=$(gh pr list --repo "${GITHUB_REPOSITORY}" --state open --limit 1000 --json number -q '.[].number' 2>/dev/null); then
|
||||||
echo "❌ Failed to fetch PR list"
|
echo "❌ Failed to fetch PR list"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$PR_NUMBERS" ]; then
|
if [[ -z "${PR_NUMBERS}" ]]; then
|
||||||
echo "✅ No open PRs found"
|
echo "✅ No open PRs found"
|
||||||
else
|
else
|
||||||
# Count the number of PRs
|
# Count the number of PRs
|
||||||
PR_COUNT=$(echo "$PR_NUMBERS" | wc -w | tr -d ' ')
|
PR_COUNT=$(echo "${PR_NUMBERS}" | wc -w | tr -d ' ')
|
||||||
echo "📊 Found $PR_COUNT open PRs to process"
|
echo "📊 Found ${PR_COUNT} open PRs to process"
|
||||||
|
|
||||||
for pr_number in $PR_NUMBERS; do
|
for pr_number in ${PR_NUMBERS}; do
|
||||||
if ! process_pr "$pr_number"; then
|
if ! process_pr "${pr_number}"; then
|
||||||
echo "⚠️ Failed to process PR #$pr_number, continuing with next PR..."
|
echo "⚠️ Failed to process PR #${pr_number}, continuing with next PR..."
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
@ -154,10 +164,10 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ensure output is always set, even if empty
|
# Ensure output is always set, even if empty
|
||||||
if [ -z "$PRS_NEEDING_COMMENT" ]; then
|
if [[ -z "${PRS_NEEDING_COMMENT}" ]]; then
|
||||||
echo "prs_needing_comment=[]" >> $GITHUB_OUTPUT
|
echo "prs_needing_comment=[]" >> "${GITHUB_OUTPUT}"
|
||||||
else
|
else
|
||||||
echo "prs_needing_comment=[$PRS_NEEDING_COMMENT]" >> $GITHUB_OUTPUT
|
echo "prs_needing_comment=[${PRS_NEEDING_COMMENT}]" >> "${GITHUB_OUTPUT}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "✅ PR triage completed"
|
echo "✅ PR triage completed"
|
||||||
|
|
|
@ -1,38 +1,39 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
# This script creates an alias for the Gemini CLI
|
# This script creates an alias for the Gemini CLI
|
||||||
|
|
||||||
# Determine the project directory
|
# Determine the project directory
|
||||||
PROJECT_DIR=$(cd "$(dirname "$0")/.." && pwd)
|
PROJECT_DIR=$(cd "$(dirname "$0")/.." && pwd)
|
||||||
ALIAS_COMMAND="alias gemini='node $PROJECT_DIR/scripts/start.js'"
|
ALIAS_COMMAND="alias gemini='node "${PROJECT_DIR}/scripts/start.js"'"
|
||||||
|
|
||||||
# Detect shell and set config file path
|
# Detect shell and set config file path
|
||||||
if [[ "$SHELL" == *"/bash" ]]; then
|
if [[ "${SHELL}" == *"/bash" ]]; then
|
||||||
CONFIG_FILE="$HOME/.bashrc"
|
CONFIG_FILE="${HOME}/.bashrc"
|
||||||
elif [[ "$SHELL" == *"/zsh" ]]; then
|
elif [[ "${SHELL}" == *"/zsh" ]]; then
|
||||||
CONFIG_FILE="$HOME/.zshrc"
|
CONFIG_FILE="${HOME}/.zshrc"
|
||||||
else
|
else
|
||||||
echo "Unsupported shell. Only bash and zsh are supported."
|
echo "Unsupported shell. Only bash and zsh are supported."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "This script will add the following alias to your shell configuration file ($CONFIG_FILE):"
|
echo "This script will add the following alias to your shell configuration file (${CONFIG_FILE}):"
|
||||||
echo " $ALIAS_COMMAND"
|
echo " ${ALIAS_COMMAND}"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Check if the alias already exists
|
# Check if the alias already exists
|
||||||
if grep -q "alias gemini=" "$CONFIG_FILE"; then
|
if grep -q "alias gemini=" "${CONFIG_FILE}"; then
|
||||||
echo "A 'gemini' alias already exists in $CONFIG_FILE. No changes were made."
|
echo "A 'gemini' alias already exists in ${CONFIG_FILE}. No changes were made."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
read -p "Do you want to proceed? (y/n) " -n 1 -r
|
read -p "Do you want to proceed? (y/n) " -n 1 -r
|
||||||
echo ""
|
echo ""
|
||||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
if [[ "${REPLY}" =~ ^[Yy]$ ]]; then
|
||||||
echo "$ALIAS_COMMAND" >> "$CONFIG_FILE"
|
echo "${ALIAS_COMMAND}" >> "${CONFIG_FILE}"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Alias added to $CONFIG_FILE."
|
echo "Alias added to ${CONFIG_FILE}."
|
||||||
echo "Please run 'source $CONFIG_FILE' or open a new terminal to use the 'gemini' command."
|
echo "Please run 'source ${CONFIG_FILE}' or open a new terminal to use the 'gemini' command."
|
||||||
else
|
else
|
||||||
echo "Aborted. No changes were made."
|
echo "Aborted. No changes were made."
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue