Skip to content

Commit

Permalink
perf: add to a note a terminal when fail to request github
Browse files Browse the repository at this point in the history
2. update .talismanrc
  • Loading branch information
woaihuangfan authored and bsdfzzzy committed Mar 16, 2022
1 parent 116968e commit 1052a59
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ fileignoreconfig:
allowed_patterns:
- address
version: "1.0"
version: "1.0"
fileignoreconfig:
- filename: V1.4__create_tbl_healthy_verification.sql
checksum: 7255c380b5ed2bc12a709e518521918d105f2ba0ff91a2e0ebe9d3c56e8d4
Expand Down Expand Up @@ -605,3 +604,4 @@ version: "1.0"
fileignoreconfig:
- filename: .github/workflows/main.yml
checksum: 5df444c7bfb65ec6d492e518052930b09bff0162f78ec8cf92b6d685909f4353
version: "1.0"
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ task installLocalGitHook() {
if (GITHUB_TOKEN) {
exec {
workingDir root
commandLine "bash", "./scripts/install-talisman.sh", "pre-commit", GITHUB_TOKEN
commandLine "bash", "scripts/install-talisman.sh", "pre-commit", GITHUB_TOKEN
}
} else {
exec {
workingDir root
commandLine "bash", "./scripts/install-talisman.sh", "pre-commit"
commandLine "bash", "scripts/install-talisman.sh", "pre-commit"
}
}
}
Expand Down
22 changes: 19 additions & 3 deletions scripts/install-talisman.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,28 @@ run() {

GITHUB_URL="https://github.com/thoughtworks/talisman"
VERSION_URL="https://api.github.com/repos/thoughtworks/talisman/releases/latest"
VERSION=0
RESPONSE=null
if [[ $GITHUB_TOKEN == "" ]]; then
VERSION=$(curl --silent "$VERSION_URL" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
RESPONSE=$(curl --silent -w '"http_code": "%{http_code}"' "$VERSION_URL")
else
VERSION=$(curl --silent --header "authorization: Bearer $GITHUB_TOKEN" "$VERSION_URL" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
RESPONSE=$(curl --silent -w '"http_code": "%{http_code}"' --header "authorization: Bearer $GITHUB_TOKEN" "$VERSION_URL")
fi
HTTP_CODE=$(echo $RESPONSE | grep '"http_code":' | sed -E 's/.*"([^"]+)".*/\1/')
if [[ $HTTP_CODE != 200 ]]; then
echo "Fail to install talisman pre-commit hook!"
if [[ $RESPONSE =~ "API rate limit exceeded" ]]; then
echo ""
echo $RESPONSE
echo "You can add a github token and then run './gradlew --no-daemon -Penv=dev -PGITHUB_TOKEN=<YOUR_GITHUB_TOKEN> }} clean build -x test' "
echo "About github token,please refer to https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token"
else
echo "problems occured while request github"
echo "you can run the following command to see what happened:"
echo "'curl $VERSION_URL'"
fi
exit 1
fi
VERSION=$(echo "$RESPONSE" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')

BINARY_BASE_URL="$GITHUB_URL/releases/download/$VERSION"
REPO_HOOK_BIN_DIR=".git/hooks/bin"
Expand Down

0 comments on commit 1052a59

Please sign in to comment.