|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Post Issue Analysis to GitHub |
| 4 | +# This script posts the root cause analysis to a GitHub issue |
| 5 | + |
| 6 | +set -e |
| 7 | + |
| 8 | +ISSUE_NUMBER="${1:-12}" |
| 9 | +ANALYSIS_FILE=".github/ISSUE_12_ANALYSIS.md" |
| 10 | +REPO_OWNER="DevExpGbb" |
| 11 | +REPO_NAME="agentic-platform-engineering" |
| 12 | + |
| 13 | +# Colors for output |
| 14 | +RED='\033[0;31m' |
| 15 | +GREEN='\033[0;32m' |
| 16 | +YELLOW='\033[1;33m' |
| 17 | +NC='\033[0m' # No Color |
| 18 | + |
| 19 | +echo "================================================" |
| 20 | +echo " GitHub Issue Analysis Poster" |
| 21 | +echo "================================================" |
| 22 | +echo "" |
| 23 | + |
| 24 | +# Check if analysis file exists |
| 25 | +if [ ! -f "$ANALYSIS_FILE" ]; then |
| 26 | + echo -e "${RED}Error: Analysis file not found at $ANALYSIS_FILE${NC}" |
| 27 | + exit 1 |
| 28 | +fi |
| 29 | + |
| 30 | +echo -e "${GREEN}✓ Analysis file found${NC}" |
| 31 | + |
| 32 | +# Clean the comment body (remove the note section) |
| 33 | +COMMENT_BODY=$(sed '/^---$/,$ d' "$ANALYSIS_FILE" | sed -e 's/$/\\n/' | tr -d '\n') |
| 34 | + |
| 35 | +# Method 1: Try gh CLI |
| 36 | +if command -v gh &> /dev/null && [ -n "$GITHUB_TOKEN" ] || gh auth status &> /dev/null 2>&1; then |
| 37 | + echo -e "${GREEN}Using GitHub CLI...${NC}" |
| 38 | + gh issue comment "$ISSUE_NUMBER" --body-file "$ANALYSIS_FILE" |
| 39 | + echo -e "${GREEN}✓ Comment posted successfully using gh CLI!${NC}" |
| 40 | + exit 0 |
| 41 | +fi |
| 42 | + |
| 43 | +# Method 2: Try curl with GITHUB_TOKEN |
| 44 | +if [ -n "$GITHUB_TOKEN" ]; then |
| 45 | + echo -e "${GREEN}Using curl with GITHUB_TOKEN...${NC}" |
| 46 | + |
| 47 | + RESPONSE=$(curl -s -w "\n%{http_code}" -X POST \ |
| 48 | + -H "Accept: application/vnd.github+json" \ |
| 49 | + -H "Authorization: Bearer $GITHUB_TOKEN" \ |
| 50 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 51 | + "https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/issues/$ISSUE_NUMBER/comments" \ |
| 52 | + -d @<(jq -Rs '{body: .}' < "$ANALYSIS_FILE")) |
| 53 | + |
| 54 | + HTTP_CODE=$(echo "$RESPONSE" | tail -n1) |
| 55 | + BODY=$(echo "$RESPONSE" | sed '$d') |
| 56 | + |
| 57 | + if [ "$HTTP_CODE" = "201" ]; then |
| 58 | + echo -e "${GREEN}✓ Comment posted successfully using curl!${NC}" |
| 59 | + COMMENT_URL=$(echo "$BODY" | jq -r '.html_url') |
| 60 | + echo "Comment URL: $COMMENT_URL" |
| 61 | + exit 0 |
| 62 | + else |
| 63 | + echo -e "${RED}✗ Failed to post comment. HTTP code: $HTTP_CODE${NC}" |
| 64 | + echo "$BODY" | jq . |
| 65 | + exit 1 |
| 66 | + fi |
| 67 | +fi |
| 68 | + |
| 69 | +# Method 3: Provide instructions for manual posting |
| 70 | +echo -e "${YELLOW}No authentication method available.${NC}" |
| 71 | +echo "" |
| 72 | +echo "To post this analysis to issue #$ISSUE_NUMBER, use one of these methods:" |
| 73 | +echo "" |
| 74 | +echo "Method 1 - GitHub CLI:" |
| 75 | +echo " gh issue comment $ISSUE_NUMBER --body-file $ANALYSIS_FILE" |
| 76 | +echo "" |
| 77 | +echo "Method 2 - GitHub Web UI:" |
| 78 | +echo " 1. Go to: https://github.com/$REPO_OWNER/$REPO_NAME/issues/$ISSUE_NUMBER" |
| 79 | +echo " 2. Copy the contents of: $ANALYSIS_FILE" |
| 80 | +echo " 3. Paste into a new comment" |
| 81 | +echo "" |
| 82 | +echo "Method 3 - Trigger the workflow:" |
| 83 | +echo " gh workflow run post-issue-analysis.yml -f issue_number=$ISSUE_NUMBER" |
| 84 | +echo "" |
| 85 | +echo "Method 4 - Use curl with your token:" |
| 86 | +echo " export GITHUB_TOKEN=your_token_here" |
| 87 | +echo " bash .github/scripts/post-to-issue.sh $ISSUE_NUMBER" |
| 88 | +echo "" |
| 89 | + |
| 90 | +exit 1 |
0 commit comments