YETUS-896 Use emoji as vote result on github (#68)

Signed-off-by: Sean Busbey <busbey@apache.org>
Signed-off-by: Guanghao Zhang <zhangguanghao1@xiaomi.com>
diff --git a/Jenkinsfile b/Jenkinsfile
index 4addf22..58fed66 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -134,6 +134,9 @@
                 YETUS_ARGS+=(--github-password="${GITHUB_PASSWORD}")
                 YETUS_ARGS+=(--github-user=${GITHUB_USER})
 
+                # use emoji as vote result on GitHub
+                YETUS_ARGS+=(--github-use-emoji-vote)
+
                 # enable writing back to ASF JIRA
                 YETUS_ARGS+=(--jira-issue-re='^YETUS-[0-9]*$')
                 YETUS_ARGS+=(--jira-password="${JIRA_PASSWORD}")
diff --git a/precommit/src/main/shell/test-patch.d/github.sh b/precommit/src/main/shell/test-patch.d/github.sh
index 5ccb5ae..e350270 100755
--- a/precommit/src/main/shell/test-patch.d/github.sh
+++ b/precommit/src/main/shell/test-patch.d/github.sh
@@ -36,6 +36,7 @@
 GITHUB_PASSWD=""
 GITHUB_USER=""
 GITHUB_ISSUE=""
+GITHUB_USE_EMOJI_VOTE=false
 
 # private globals...
 GITHUB_BRIDGED=false
@@ -58,6 +59,7 @@
   yetus_add_option "--github-password=<pw>" "Github password (or OAuth token)"
   yetus_add_option "--github-repo=<repo>" "github repo to use (default:'${GITHUB_REPO}')"
   yetus_add_option "--github-user=<user>" "Github user [default: ${GITHUB_USER}]"
+  yetus_add_option "--github-use-emoji-vote" "Whether to use emoji to represent the vote result on github [default: ${GITHUB_USE_EMOJI_VOTE}]"
 }
 
 function github_parse_args
@@ -88,6 +90,10 @@
         delete_parameter "${i}"
         GITHUB_USER=${i#*=}
       ;;
+      --github-use-emoji-vote)
+        delete_parameter "${i}"
+        GITHUB_USE_EMOJI_VOTE=true
+      ;;
     esac
   done
 }
@@ -607,12 +613,48 @@
   until [[ ${i} -eq ${#TP_VOTE_TABLE[@]} ]]; do
     ourstring=$(echo "${TP_VOTE_TABLE[${i}]}" | tr -s ' ')
     vote=$(echo "${ourstring}" | cut -f2 -d\| | tr -d ' ')
+    subs=$(echo "${ourstring}"  | cut -f3 -d\|)
+    ela=$(echo "${ourstring}" | cut -f4 -d\|)
+    calctime=$(clock_display "${ela}")
     comment=$(echo "${ourstring}"  | cut -f5 -d\|)
 
+
     if [[ "${vote}" = "H" ]]; then
       echo "||| _${comment}_ |" >> "${commentfile}"
     else
-      echo "${TP_VOTE_TABLE[${i}]}" >> "${commentfile}"
+      if [[ ${GITHUB_USE_EMOJI_VOTE} == true ]]; then
+        emoji=""
+        case ${vote} in
+          1|"+1")
+            emoji=":green_heart:"
+          ;;
+          -1)
+            emoji=":broken_heart:"
+          ;;
+          0)
+            emoji=":blue_heart:"
+          ;;
+          -0)
+            emoji=":yellow_heart:"
+          ;;
+          H)
+            # this never gets called (see above) but this is here so others know the color is taken
+            emoji=""
+          ;;
+          *)
+            # usually this should not happen but let's keep the old vote result if it happens
+            emoji=${vote}
+          ;;
+        esac
+        printf '| %s | %s | %s | %s |\n' \
+        "${emoji}" \
+        "${subs}" \
+        "${calctime}" \
+        "${comment}" \
+        >> "${commentfile}"
+      else
+        echo "${TP_VOTE_TABLE[${i}]}" >> "${commentfile}"
+      fi
     fi
     ((i=i+1))
   done