3 Star 0 Fork 0

mirrors_sass/clone-linked-repo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
find-ref.sh 2.11 KB
一键复制 编辑 原始数据 按行查看 历史
なつき 提交于 2023-05-22 16:18 . Address deprecation warnings (#8)
#!/bin/bash -e
# Copyright 2021 Google Inc. Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.
if [ -z "$PR_BRANCH" ]; then
# Remove the "refs/heads/" prefix
current_branch="${CURRENT_REF/refs\/heads\//}"
else
current_branch="$PR_BRANCH"
fi
if [[ "$current_branch" == feature.* ]]; then
default="$current_branch"
else
default="$DEFAULT_REF"
fi
if [[ -z "$default" ]]; then
skip="true"
else
skip="false"
fi
# We don't have a PR_BRANCH so we are not in a pull request, so there's no
# linked PR to find.
if [ -z "$PR_BRANCH" ]; then
if [[ -z "$default" ]]; then
echo "Not a pull request, skipping checkout"
else
echo "Not a pull request, using default ref $default"
fi
echo "skip=$skip" >> "$GITHUB_OUTPUT"
echo "ref=$default" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "::group::Pull request body"
echo "$PR_BODY"
echo "::endgroup::"
# Echoes the sass/sass Git ref that should be checked out for the current GitHub
# Actions run. If we're running specs for a pull request which refers to a
# sass/sass pull request, we'll run against the latter rather than sass/sass
# main.
echo "::group::Finding pull request reference"
for link in "$(echo "$PR_BODY" | grep -Eo "${REPO}(#|/pull/)[0-9]+")"; do
if [[ "$link" = *#* ]]; then
number="${link#*#}"
else
number="${link#*/pull/}"
fi
json="$(
curl --fail --silent \
--header "Authorization: token $TOKEN" \
--header "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/$REPO/pulls/${number}"
)"
if [[ "$?" == 0 && "$(echo "$json" | jq .state -r)" == "open" ]]; then
echo "Linked to pull request $number"
echo "skip=false" >> "$GITHUB_OUTPUT"
echo "ref=refs/pull/$number/head" >> "$GITHUB_OUTPUT"
exit 0
else
echo "$link isn't a pull request."
fi
done
if [[ -z "$default" ]]; then
echo "No linked pull request, skipping checkout"
else
echo "No linked pull request, using default ref $default"
fi
echo "skip=$skip" >> "$GITHUB_OUTPUT"
echo "ref=$default" >> "$GITHUB_OUTPUT"
echo "::endgroup::"
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_sass/clone-linked-repo.git
[email protected]:mirrors_sass/clone-linked-repo.git
mirrors_sass
clone-linked-repo
clone-linked-repo
main

搜索帮助