Skip to content

Instantly share code, notes, and snippets.

@dholdren
Created July 21, 2014 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dholdren/9503fc48d2f524688344 to your computer and use it in GitHub Desktop.
Save dholdren/9503fc48d2f524688344 to your computer and use it in GitHub Desktop.
Pull current commands for your semaphore project (hacky)
function pull_commands() {
#get all projects
project_name_hash_id_map=$(curl -sS -X GET "https://semaphoreapp.com/api/v1/projects?auth_token=${SEMAPHORE_API_TOKEN}" | jq '[.[] | {(.name): .hash_id}] | add')
if [ -z "$project_name_hash_id_map" ]
then
echo "projects call failed"
exit 1
fi
#for each project, get the hash_id of each project
for project_hash_id in $(echo $project_name_hash_id_map | jq -r .[])
do
if [[ -n $project_hash_id ]]
then
#get all the branch_ids of the project
branch_name_id_map=$(curl -sS -X GET "https://semaphoreapp.com/api/v1/projects/${project_hash_id}/branches?auth_token=${SEMAPHORE_API_TOKEN}" | jq '[.[] | {(.name): .id}] | add')
#get the dev branch id
dev_branch_id=$(echo $branch_name_id_map | jq -r ".[\"dev\"]")
if [[ -n $dev_branch_id ]]
then
#get the latest build number of the branch
dev_branch_status=$(curl -sS -X GET "https://semaphoreapp.com/api/v1/projects/${project_hash_id}/${dev_branch_id}/status?auth_token=${SEMAPHORE_API_TOKEN}")
project_name=$(echo $dev_branch_status | jq .project_name)
echo "######## Project: ${project_name} #########"
declare -i last_build_number
declare -i current_build_number
current_build_number=$(echo $dev_branch_status | jq .build_number)
last_build_number=current_build_number-1 #in case it's currently building
curl -sS -X GET "https://semaphoreapp.com/api/v1/projects/${project_hash_id}/${dev_branch_id}/builds/${last_build_number}/log?auth_token=${SEMAPHORE_API_TOKEN}" | jq -r '.threads[0].commands[].name'
fi
fi
done
}
pull_commands
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment