import-issue.sh
1 #!/bin/bash 2 # 3 # Import a GitHub issue into Radicle. 4 # 5 set -e 6 7 if ! command -v curl > /dev/null; then 8 echo "Error: curl is not installed" ; exit 1 9 fi 10 11 if ! command -v jq > /dev/null; then 12 echo "Error: jq is not installed" ; exit 1 13 fi 14 15 if ! command -v rad > /dev/null; then 16 echo "Error: rad is not installed" ; exit 1 17 fi 18 19 if ! command -v pcregrep > /dev/null; then 20 echo "Error: pcregrep is not installed" ; exit 1 21 fi 22 23 if ! command -v sed > /dev/null; then 24 echo "Error: sed is not installed" ; exit 1 25 fi 26 27 function removeImgTags { 28 local html 29 html="$(cat)" 30 local imgTags 31 imgTags="$(echo "$html" | pcregrep -M '<img [^>]*>')" 32 33 # shellcheck disable=SC2066 34 for imgTag in "$imgTags"; do 35 html="$(echo "$html" | sed -z "s@$imgTag@@")" 36 done 37 echo "$html" 38 } 39 40 # Check if the correct number of arguments is provided 41 if [ "$#" -ne 3 ]; then 42 echo "Usage: $0 <org> <repo> <issue>" 43 exit 1 44 fi 45 46 owner="$1" 47 repo="$2" 48 issue="$3" 49 50 url="https://api.github.com/repos/${owner}/${repo}/issues/${issue}" 51 52 # Fetch the issue data using the GitHub API 53 response="$(curl -s "$url")" 54 55 # Extract the title and body from the JSON response 56 title="$(echo "$response" | jq -r '.title')" 57 body="$(echo "$response" | jq -r '.body' | removeImgTags)" 58 labels="$(echo "$response" | jq -r '.labels | .[].name')" 59 60 tags=() 61 for label in $labels; do 62 tags+=("--label" "$label") 63 done 64 65 rad issue open --title "$title" "${tags[@]}" --description "$body" --no-announce