[git-tool] do not use GITHUB_TOKEN (#11730)

This commit stops using GITHUB_TOKEN in git-tool for better security.
This commit is contained in:
Yakun Xu
2025-07-16 07:11:17 -07:00
committed by GitHub
parent 6e1a6ff190
commit 2f1183f387
7 changed files with 14 additions and 41 deletions
+3 -30
View File
@@ -47,41 +47,14 @@ apply_dependencies()
depends_on_pr="$(echo "${dependency}" | tr -d '\r\n' | cut -d# -f2)"
echo "pr: #${depends_on_pr}"
git pull --no-edit --no-rebase origin "pull/${depends_on_pr}/merge"
done < <(grep -E "^Depends-On: *${project_name}" || true)
}
get_pr_body()
{
local pr
if [[ -z ${PR_BODY+x} ]]; then
echo 'PR_BODY is not set' >&2
else
echo 'PR_BODY is set' >&2
echo "${PR_BODY}"
return 0
fi
[[ ${GITHUB_ACTIONS+x} && ${GITHUB_REF-} =~ ^refs/pull/[0-9]+/merge ]] || {
echo 'Not a pull request.' >&2
return 0
}
pr="$(echo "${GITHUB_REF}" | cut -d/ -f3)"
# do not print GITHUB_TOKEN
set +x
curl -H "authorization: Bearer ${GITHUB_TOKEN}" -H 'content-type: application/json' \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls/${pr}" \
| jq -r .body
set -x
done < <(grep -E "^Depends-On: *${project_name}" <<<"${PR_BODY:-}" || true)
}
try_update()
{
cd "$1"
get_pr_body | apply_dependencies
apply_dependencies
}
try_clone()
@@ -95,7 +68,7 @@ try_clone()
dest_dir="$(git clone "$@" 2>&1 | tee | cut -d\' -f2)"
cd "${dest_dir}"
get_pr_body | apply_dependencies
apply_dependencies
fi
}