# Greetings # # 首次贡献者的 PR 欢迎评论. # 纯 shell + 平台 API 实现, 不依赖第三方 action (无需从 GitHub 拉取任何内容). # # 要求: # - 平台启用 Gitea Actions 并注册 ubuntu runner # - 若 Gitea 版本不支持 pull_request_target, 请改为 pull_request name: Greetings on: pull_request_target: types: [opened] jobs: greeting: runs-on: ubuntu-latest steps: - name: Install jq run: | command -v jq && exit 0 sudo apt-get install -y --no-install-recommends jq \ || (sudo apt-get update && sudo apt-get install -y --no-install-recommends jq) - name: Welcome first-time contributor env: TOKEN: ${{ secrets.GITHUB_TOKEN }} API: ${{ gitea.server_url || 'https://git.xhmcl.com' }}/api/v1 REPO: ${{ github.repository }} ACTOR: ${{ github.actor }} PR_NUM: ${{ github.event.pull_request.number }} run: | set -euo pipefail OWNER="${REPO%%/*}" NAME="${REPO#*/}" api() { curl -fsS -H "Authorization: token ${TOKEN}" -H "Content-Type: application/json" "$@" } # 统计该用户提交过的 PR 总数 (分页遍历) total=0 page=1 while :; do resp=$(api "$API/repos/$OWNER/$NAME/pulls?state=all&poster=$ACTOR&limit=50&page=$page") n=$(echo "$resp" | jq 'if type=="array" then length else 0 end') total=$((total + n)) [ "$n" -lt 50 ] && break page=$((page + 1)) done if [ "$total" -le 1 ]; then body=$(jq -n --arg u "@$ACTOR" \ '{"body": ("你好 " + $u + ",感谢提交PR!\nHi " + $u + ", thanks for opening the Pull Request!\n我们会尽早审核回应😊\nWe will respond to it as soon as possible😊")}') api -X POST -d "$body" "$API/repos/$OWNER/$NAME/issues/$PR_NUM/comments" echo "Welcome comment posted for first PR of $ACTOR." else echo "Not the first PR of $ACTOR ($total PRs), skip." fi