Created
May 18, 2019 09:39
-
-
Save hiiamyes/28b5b4beef8818338697d53792910a47 to your computer and use it in GitHub Desktop.
Shell Script and Github API: Get Latest Tag on a Branch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
token="my_personal_access_token" | |
base_url="https://api.github.com" | |
list_branches_url="/repos/hiiamyes/github-api-test/branches" | |
list_commites_url="/repos/hiiamyes/github-api-test/commits" | |
list_tags_url="/repos/emq-inc/emq-adminsite/tags" | |
headers="Authorization: token $token" | |
commit_sha=$( | |
curl \ | |
--silent $base_url$list_branches_url/sprint \ | |
-H "$headers" | | |
jq --raw-output '.commit.sha' | |
) | |
tags=$( | |
curl \ | |
--silent $base_url$list_tags_url \ | |
-H "$headers" | |
) | |
while [ "$tag_name" = "" ]; do | |
tag_name=$( | |
echo $tags | | |
jq \ | |
--raw-output \ | |
--arg commit_sha $commit_sha \ | |
'.[] | select(.commit.sha == $commit_sha) | .name' | |
) | |
commit_sha=$( | |
curl \ | |
--silent $base_url$list_commites_url/$commit_sha \ | |
-H "$heaers" | | |
jq -r '.parents[0].sha' | |
) | |
done | |
echo $tag_name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment