Mark Jansen 76c58ac22a
Add support for deploying with the 'deploy-pr' label,
instead of adding all users to the trusted list
2022-03-08 21:15:39 +01:00

67 lines
1.6 KiB
Plaintext

# ReactOS Web-Playground BuildBot Build Scripts
# functions - Shared functions between all scripts
# Returns 0 (true) if the given GitHub username belongs to the given GitHub Team ID, otherwise returns 1 (false).
check_team_membership() {
local member=$1
local team_id=$2
local status=`curl -H "Authorization: token ${personal_access_token}" -i -s https://api.github.com/teams/${team_id}/memberships/${member} | head -n 1 | cut -d$' ' -f2`
if [[ "${status}" == "200" ]]; then
return 0
else
return 1
fi
}
check_pr_label() {
local labels="$1"
local search_label="$2"
if echo "$labels" | grep -qFx "$search_label"; then
return 0
else
return 1
fi
}
# Get the GitHub username for the person that submitted a web-content Pull Request
get_pr_username() {
local pr_data="$1"
echo "$pr_data" | jq -r '.user.login'
}
get_pr_labels() {
local pr_data="$1"
echo "$pr_data" | jq -r '.labels[].name'
}
get_pr_data() {
local pr_number=$1
curl -s https://api.github.com/repos/reactos/web-content/pulls/${pr_number}
}
# Outputs the *.web-content.reactos.org subdomain for deployment, or "invalid" if this branch is not deployed.
get_subdomain() {
local branch=$1
if [[ "${branch}" == "master" ]]; then
echo "master"
elif [[ "${branch}" =~ ^refs/pull/([0-9]+)/ ]]; then
echo "pr${BASH_REMATCH[1]}"
else
echo "invalid"
fi
}
# Posts a message from "reactos-buildbot" to a web-content Pull Request discussion.
post_to_pr() {
local pr_number=$1
local message=$2
curl -d '{"body": "'"$message"'"}' -H "Authorization: token ${personal_access_token}" -s -X POST https://api.github.com/repos/reactos/web-content/issues/${pr_number}/comments > /dev/null
}