Update to use gh cli
This commit is contained in:
parent
57e35b6a4f
commit
fedcf6e9ef
1 changed files with 73 additions and 10 deletions
|
|
@ -237,32 +237,95 @@ source .env
|
|||
# Input file containing Continue CLI analysis output
|
||||
ANALYSIS_FILE="analysis-results.txt"
|
||||
|
||||
# File to track created issues to prevent duplicates
|
||||
ISSUE_TRACKING_FILE=".created_issues.json"
|
||||
|
||||
# Check if analysis file exists
|
||||
if [ ! -f "$ANALYSIS_FILE" ]; then
|
||||
echo "❌ Analysis file not found: $ANALYSIS_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Function to create a GitHub issue
|
||||
# Check if GitHub CLI is installed
|
||||
if ! command -v gh &> /dev/null; then
|
||||
echo "❌ GitHub CLI (gh) not found. Please install it first:"
|
||||
echo " https://cli.github.com/manual/installation"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Make sure gh is authenticated
|
||||
if ! gh auth status &> /dev/null; then
|
||||
echo "❌ GitHub CLI not authenticated. Please run 'gh auth login' first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create issue tracking file if it doesn't exist
|
||||
if [ ! -f "$ISSUE_TRACKING_FILE" ]; then
|
||||
echo "[]" > "$ISSUE_TRACKING_FILE"
|
||||
fi
|
||||
|
||||
# Function to check if an issue with this title already exists
|
||||
issue_exists() {
|
||||
local title="$1"
|
||||
local issue_hash=$(echo "$title" | md5sum | cut -d' ' -f1)
|
||||
|
||||
# Check in our tracking file
|
||||
if grep -q "\"$issue_hash\"" "$ISSUE_TRACKING_FILE"; then
|
||||
return 0 # Issue exists
|
||||
fi
|
||||
|
||||
# Also check actual GitHub issues to be doubly sure
|
||||
if gh issue list --repo "$GITHUB_OWNER/$GITHUB_REPO" --search "$title in:title" --json title | grep -q "$title"; then
|
||||
# Add to tracking file if found on GitHub but not in our tracking
|
||||
local tracking_data=$(cat "$ISSUE_TRACKING_FILE")
|
||||
echo "$tracking_data" | jq --arg hash "$issue_hash" '. += [$hash]' > "$ISSUE_TRACKING_FILE"
|
||||
return 0 # Issue exists
|
||||
fi
|
||||
|
||||
return 1 # Issue doesn't exist
|
||||
}
|
||||
|
||||
# Function to record that we created an issue
|
||||
record_issue() {
|
||||
local title="$1"
|
||||
local issue_hash=$(echo "$title" | md5sum | cut -d' ' -f1)
|
||||
|
||||
local tracking_data=$(cat "$ISSUE_TRACKING_FILE")
|
||||
echo "$tracking_data" | jq --arg hash "$issue_hash" '. += [$hash]' > "$ISSUE_TRACKING_FILE"
|
||||
}
|
||||
|
||||
# Function to create a GitHub issue using GitHub CLI
|
||||
create_github_issue() {
|
||||
local title="$1"
|
||||
local body="$2"
|
||||
local labels="$3"
|
||||
|
||||
# Check if this issue already exists
|
||||
if issue_exists "$title"; then
|
||||
echo "ℹ️ Issue already exists: $title"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "Creating issue: $title"
|
||||
|
||||
response=$(curl -s -X POST \
|
||||
-H "Authorization: token $GITHUB_PERSONAL_ACCESS_TOKEN" \
|
||||
-H "Accept: application/vnd.github.v3+json" \
|
||||
-d "{\"title\":\"$title\", \"body\":\"$body\", \"labels\":$labels}" \
|
||||
"https://api.github.com/repos/$GITHUB_OWNER/$GITHUB_REPO/issues")
|
||||
# Convert labels from JSON array format to comma-separated list
|
||||
# Remove brackets, quotes, and add commas
|
||||
labels_list=$(echo $labels | sed 's/\[//g' | sed 's/\]//g' | sed 's/"//g' | sed 's/,/,/g')
|
||||
|
||||
issue_number=$(echo "$response" | grep -o '"number": [0-9]*' | head -1 | cut -d' ' -f2)
|
||||
# Create issue using GitHub CLI
|
||||
issue_url=$(gh issue create \
|
||||
--repo "$GITHUB_OWNER/$GITHUB_REPO" \
|
||||
--title "$title" \
|
||||
--body "$body" \
|
||||
--label "$labels_list" \
|
||||
--web)
|
||||
|
||||
if [ -n "$issue_number" ]; then
|
||||
echo "✅ Created issue #$issue_number"
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "✅ Created issue: $issue_url"
|
||||
# Record that we created this issue
|
||||
record_issue "$title"
|
||||
else
|
||||
echo "❌ Failed to create issue: $response"
|
||||
echo "❌ Failed to create issue"
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue