report-issue.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/bin/sh
  2. # This is a convenience script for reporting issues that include a base
  3. # template of information. See https://github.com/docker/docker/pull/8845
  4. set -e
  5. DOCKER_ISSUE_URL=${DOCKER_ISSUE_URL:-"https://github.com/docker/docker/issues/new"}
  6. DOCKER_ISSUE_NAME_PREFIX=${DOCKER_ISSUE_NAME_PREFIX:-"Report: "}
  7. DOCKER=${DOCKER:-"docker"}
  8. DOCKER_COMMAND="${DOCKER}"
  9. export DOCKER_COMMAND
  10. # pulled from https://gist.github.com/cdown/1163649
  11. function urlencode() {
  12. # urlencode <string>
  13. local length="${#1}"
  14. for (( i = 0; i < length; i++ )); do
  15. local c="${1:i:1}"
  16. case $c in
  17. [a-zA-Z0-9.~_-]) printf "$c" ;;
  18. *) printf '%%%02X' "'$c"
  19. esac
  20. done
  21. }
  22. function template() {
  23. # this should always match the template from CONTRIBUTING.md
  24. cat <<- EOM
  25. Description of problem:
  26. \`docker version\`:
  27. `${DOCKER_COMMAND} -D version`
  28. \`docker info\`:
  29. `${DOCKER_COMMAND} -D info`
  30. \`uname -a\`:
  31. `uname -a`
  32. Environment details (AWS, VirtualBox, physical, etc.):
  33. How reproducible:
  34. Steps to Reproduce:
  35. 1.
  36. 2.
  37. 3.
  38. Actual Results:
  39. Expected Results:
  40. Additional info:
  41. EOM
  42. }
  43. function format_issue_url() {
  44. if [ ${#@} -ne 2 ] ; then
  45. return 1
  46. fi
  47. local issue_name=$(urlencode "${DOCKER_ISSUE_NAME_PREFIX}${1}")
  48. local issue_body=$(urlencode "${2}")
  49. echo "${DOCKER_ISSUE_URL}?title=${issue_name}&body=${issue_body}"
  50. }
  51. echo -ne "Do you use \`sudo\` to call docker? [y|N]: "
  52. read -r -n 1 use_sudo
  53. echo ""
  54. if [ "x${use_sudo}" = "xy" -o "x${use_sudo}" = "xY" ]; then
  55. export DOCKER_COMMAND="sudo ${DOCKER}"
  56. fi
  57. echo -ne "Title of new issue?: "
  58. read -r issue_title
  59. echo ""
  60. issue_url=$(format_issue_url "${issue_title}" "$(template)")
  61. if which xdg-open 2>/dev/null >/dev/null ; then
  62. echo -ne "Would like to launch this report in your browser? [Y|n]: "
  63. read -r -n 1 launch_now
  64. echo ""
  65. if [ "${launch_now}" != "n" -a "${launch_now}" != "N" ]; then
  66. xdg-open "${issue_url}"
  67. fi
  68. fi
  69. echo "If you would like to manually open the url, you can open this link if your browser: ${issue_url}"