sh 从Bash创建Gtihub标签

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 从Bash创建Gtihub标签相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env bash

# Colours picked from https://robinpowered.com/blog/best-practice-system-for-organizing-and-tagging-github-issues/

###
# Label definitions
###
declare -A LABELS

# Platform
LABELS["ruby"]="BFD4F2"
LABELS["rails"]="BFD4F2"

# Problems
LABELS["bug"]="EE3F46"
LABELS["security"]="EE3F46"
LABELS["production"]="F45D43"

# Mindless
LABELS["chore"]="FEF2C0"
LABELS["legal"]="FFF2C1"

# Experience
LABELS["copy"]="FFC274"
LABELS["design"]="FFC274"
LABELS["ux"]="FFC274"

# Environment
LABELS["staging"]="FAD8C7"
LABELS["test"]="FAD8C7"

# Feedback
LABELS["discussion"]="CC317C"
LABELS["rfc"]="CC317C"
LABELS["question"]="CC317C"

# Improvements
LABELS["enhancement"]="5EBEFF"
LABELS["optimizaiton"]="5EBEFF"

# Additions
LABELS["feature"]="91CA55"

# Pending
LABELS["in progress"]="FBCA04"
LABELS["watchlist"]="FBCA04"

# Inactive
LABELS["invalid"]="D2DAE1"
LABELS["wontfix"]="D2DAE1"
LABELS["duplicate"]="D2DAE1"
LABELS["on hold"]="D2DAE1"

###
# Get a token from Github
###
if [ ! -f ".token" ]; then
  read -p "Please enter your Github username: " user
  read -p "Please enter your 6 digit two-factor-authentication code: " otp_code

  curl -u "$user" -H "X-Github-OTP: $otp_code" -d '{"scopes":["repo", "public_repo"], "note":"Creating Labels"}' "https://api.github.com/authorizations" | jq -r '.token' > .token
fi

TOKEN=$(cat .token)

read -p "Who owns the repo you want labels on?: " owner
read -p "What repo do you want labels on?: " repo

for K in "${!LABELS[@]}"; do
  CURL_OUTPUT=$(curl -s -H "Authorization: token $TOKEN" -X POST "https://api.github.com/repos/$owner/$repo/labels" -d "{\"name\":\"$K\", \"color\":\"${LABELS[$K]}\"}")
  HAS_ERROR=$(echo "$CURL_OUTPUT" | jq -r '.errors')

  if [ ! -z "$HAS_ERROR" ]; then
    ERROR=$(echo "$CURL_OUTPUT" | jq -r '.errors[0].code')

    if [ "$ERROR" == "already_exists" ]; then
      # We update
      echo "'$K' already exists. Updating..."
      CURL_OUTPUT=$(curl -s -H "Authorization: token $TOKEN" -X PATCH "https://api.github.com/repos/$owner/$repo/labels/${K/ /%20}" -d "{\"name\":\"$K\", \"color\":\"${LABELS[$K]}\"}")
    else
      echo "Unknown error: $ERROR"
      echo "Output from curl: "
      echo "$CURL_OUTPUT"
      echo "Exiting..."
      exit;
    fi
  else
    echo "Created '$K'."
  fi
done

以上是关于sh 从Bash创建Gtihub标签的主要内容,如果未能解决你的问题,请参考以下文章

从脚本创建 bash 文件 [重复]

意外收获Gtihub上这套“Andorid从底层基础到架构成长笔记”,果然高手与菜鸟之间差距不止一点点!

sh 通过bash脚本创建MySQL

sh Bash脚本:创建MySQL数据库和用户

sh bash,linux从文件中读取

sh 从bash返回值