Skip to content

Instantly share code, notes, and snippets.

@liangzai-cool
Created April 9, 2019 08:59
Show Gist options
  • Save liangzai-cool/1a2db7d48e8356e8e947e477dc744cc9 to your computer and use it in GitHub Desktop.
Save liangzai-cool/1a2db7d48e8356e8e947e477dc744cc9 to your computer and use it in GitHub Desktop.
利用coding.net批量更新本地所有仓库
source_code_dir="/Users/username/sourcecode/dev.tencent.com/"
token="your_coding_net_token"
current_dir=$(pwd)
response=$(curl -X GET "https://coding.net/api/user/projects?type=all&sort=&page=1&pageSize=100" -H "Authorization: token ${token}")
project_count=$(echo $response | jq '.data.list | length')
echo $project_count
for(( i = 0; i < $project_count; i = i + 1 ))
do
operation="clone"
item=$(echo $response | jq -r ".data.list[$i]")
name=$(echo $item | jq -r ".name")
owner_user_name=$(echo $item | jq -r ".owner_user_name")
ssh_url=$(echo $item | jq -r ".ssh_url")
if [ -d "$source_code_dir$owner_user_name/$name/.git" ]; then
echo "$source_code_dir$owner_user_name/$name/.git 存在"
operation="pull"
else
echo "$source_code_dir$owner_user_name/$name/.git 不存在"
fi
echo "正在 $operation 项目:$ssh_url"
if [ $operation = "clone" ]; then
git clone $ssh_url "$source_code_dir$owner_user_name/$name"
else
cd "$source_code_dir$owner_user_name/$name"
git pull
cd $current_dir
fi
echo -e "完成 $operation 项目:$ssh_url\n"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment