{"id":841,"date":"2026-02-12T03:25:02","date_gmt":"2026-02-12T03:25:02","guid":{"rendered":"https:\/\/opshub.com.cn\/?p=841"},"modified":"2026-03-09T09:31:53","modified_gmt":"2026-03-09T09:31:53","slug":"%e4%bb%8e-gitlab-%e8%bf%9c%e7%a8%8b%e8%8e%b7%e5%8f%96%e6%89%80%e6%9c%89%e4%bb%93%e5%ba%93%e7%9a%84-url%e3%80%81%e6%9c%80%e5%90%8e%e6%8f%90%e4%ba%a4%e4%ba%ba%e4%bb%a5%e5%8f%8a%e6%9c%80%e5%90%8e","status":"publish","type":"post","link":"https:\/\/opshub.com.cn\/?p=841","title":{"rendered":"\u4ece GitLab \u8fdc\u7a0b\u83b7\u53d6\u6240\u6709\u4ed3\u5e93\u7684 URL\u3001\u6700\u540e\u63d0\u4ea4\u4eba\u4ee5\u53ca\u6700\u540e\u63d0\u4ea4\u65e5\u671f"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n\n# ===================== \u914d\u7f6e\u9879\uff08\u5fc5\u987b\u4fee\u6539\uff09=====================\nGITLAB_URL=\"http:\/\/210.14.75.1:20220\/\" # \u4f60\u7684GitLab\u5730\u5740\uff08\u5982https:\/\/gitlab.com\uff09\nPRIVATE_TOKEN=\"WutLt-wTtGLExy-6QDGY\"     # \u7b2c\u4e00\u6b65\u751f\u6210\u7684\u8bbf\u95ee\u4ee4\u724c\nGROUP_ID=\"\"                              # \u53ef\u9009\uff1a\u6307\u5b9a\u5206\u7ec4ID\uff08\u7559\u7a7a\u5219\u83b7\u53d6\u5f53\u524d\u7528\u6237\u6240\u6709\u4ed3\u5e93\uff09\n# ============================================================\n\n# 1. \u83b7\u53d6\u4ed3\u5e93\u5217\u8868\uff08\u5206\u9875\u5904\u7406\uff0c\u907f\u514d\u6f0f\u53d6\uff09\npage=1\nper_page=100\ntotal_pages=1\n\necho \"===== GitLab \u6240\u6709\u4ed3\u5e93\u4fe1\u606f\u6c47\u603b =====\"\necho \"GitLab\u5730\u5740: $GITLAB_URL\"\necho \"====================================$(echo -e '\\n')\"\n\nwhile &#91; $page -le $total_pages ]; do\n\t# \u6784\u5efaAPI\u8bf7\u6c42URL\uff08\u6309\u5206\u7ec4\/\u5168\u91cf\u83b7\u53d6\uff09\n\tif &#91; -n \"$GROUP_ID\" ]; then\n\t\trepos_api=\"$GITLAB_URL\/api\/v4\/groups\/$GROUP_ID\/projects?page=$page&amp;per_page=$per_page&amp;include_subgroups=true\"\n\telse\n\t\trepos_api=\"$GITLAB_URL\/api\/v4\/projects?page=$page&amp;per_page=$per_page&amp;owned=true\"\n\tfi\n\n\t# \u83b7\u53d6\u5f53\u524d\u9875\u4ed3\u5e93\u6570\u636e\n\trepos_data=$(curl -s --header \"Private-Token: $PRIVATE_TOKEN\" \"$repos_api\")\n\t# \u83b7\u53d6\u603b\u9875\u6570\uff08\u4ece\u54cd\u5e94\u5934\u63d0\u53d6\uff09\n\ttotal_pages=$(curl -s -I --header \"Private-Token: $PRIVATE_TOKEN\" \"$repos_api\" | grep -i 'x-total-pages' | awk '{print $2}' | tr -d '\\r')\n\n\t# 2. \u904d\u5386\u6bcf\u4e2a\u4ed3\u5e93\uff0c\u63d0\u53d6URL\u548c\u6700\u540e\u63d0\u4ea4\u4fe1\u606f\n\techo \"$repos_data\" | jq -r '.&#91;] | {id: .id, description: .description, name: .name, http_url_to_repo: .http_url_to_repo, last_commit: .last_activity_at}' | awk '{if($0==\"}\"){printf\"%s\\n\",$0}else{printf\"%s \",$0}}' | while read -r line; do\n\t\t# \u89e3\u6790\u4ed3\u5e93\u57fa\u672c\u4fe1\u606f\n\t\trepo_description=$(echo \"$line\" | jq -r '.description')\n\t\trepo_name=$(echo \"$line\" | jq -r '.name')\n\t\trepo_url=$(echo \"$line\" | jq -r '.http_url_to_repo')\n\t\trepo_id=$(echo \"$line\" | jq -r '.id')\n\t\t#echo \"\u4ed3\u5e93\u63cf\u8ff0: $repo_description\"\n\t\t#echo \"\u4ed3\u5e93\u540d\u79f0: $repo_name\"\n\t\t#echo \"\u4ed3\u5e93URL: $repo_url\"\n\n\t\t# 3. \u83b7\u53d6\u4ed3\u5e93\u6700\u540e\u63d0\u4ea4\u7684\u8be6\u7ec6\u4fe1\u606f\uff08\u901a\u8fc7API\uff09\n\t\tcommit_api=\"$GITLAB_URL\/api\/v4\/projects\/$repo_id\/repository\/commits?per_page=1\"\n\t\tcommit_data=$(curl -s --header \"Private-Token: $PRIVATE_TOKEN\" \"$commit_api\")\n\n\t\tif &#91; \"$commit_data\" != \"&#91;]\" ] &amp;&amp; &#91; \"$commit_data\" != \"\" ]; then\n\t\t\t# \u89e3\u6790\u63d0\u4ea4\u4eba\u3001\u63d0\u4ea4\u65e5\u671f\n\t\t\tcommit_author=$(echo \"$commit_data\" | jq -r '.&#91;0].author_name')\n\t\t\tcommit_date=$(echo \"$commit_data\" | jq -r '.&#91;0].created_at' | cut -c1-19) # \u683c\u5f0f\u5316\u65e5\u671f\n\t\t\t#echo \"\u6700\u540e\u63d0\u4ea4\u4eba: $commit_author\"\n\t\t\t#echo \"\u6700\u540e\u63d0\u4ea4\u65e5\u671f: $commit_date\"\n\t\telse\n            :\n\t\t\t#echo \"\u6700\u540e\u63d0\u4ea4\u4eba: \u65e0\u63d0\u4ea4\u8bb0\u5f55\"\n\t\t\t#echo \"\u6700\u540e\u63d0\u4ea4\u65e5\u671f: \u65e0\u63d0\u4ea4\u8bb0\u5f55\"\n\t\tfi\n\t\techo -e \"${repo_description:-}\\t-\\t-\\t${repo_url:-}\\t${commit_author:-}${commit_date}\\t-\"\n\t\t#echo \"------------------------------------$(echo -e '\\n')\"\n\tdone\n\n\tpage=$((page + 1))\ndone\n\necho \"===== \u4fe1\u606f\u83b7\u53d6\u5b8c\u6210 =====\"\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-841","post","type-post","status-publish","format-standard","hentry","category-9"],"_links":{"self":[{"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/841","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=841"}],"version-history":[{"count":1,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/841\/revisions"}],"predecessor-version":[{"id":843,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/841\/revisions\/843"}],"wp:attachment":[{"href":"https:\/\/opshub.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=841"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=841"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=841"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}