Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 74 additions & 23 deletions build-testcase-with-commit-status
Original file line number Diff line number Diff line change
Expand Up @@ -49,40 +49,91 @@ sleep 2
./create-commit-gitattributes.sh | jq -r ".content.html_url"

printf "${highlight} - Creating commit status for an optional check: ${normal}"
./create-commit-status.sh pending ci-test/this-check-is-optional | jq -r '.url'
./create-commit-status.sh pending ci/commit-status-optional | jq -r '.url'
printf "${highlight} - Creating commit status for an required check: ${normal}"
./create-commit-status.sh pending ci-test/this-check-is-required | jq -r '.url'
./create-commit-status.sh pending ci/commit-status-required | jq -r '.url'
printf "${highlight} - Updating branch protection with required check: ${normal}"
./update-branch-protection-with-required-check.sh | jq -r '.url'

# To update the checks to success run the two lines below:
# ./create-commit-status.sh success ci-test/this-check-is-required
# ./create-commit-status.sh success ci-test/this-check-is-optional
#
sleep 3

. .gh-api-examples.conf

clear
echo -------------------------------------------
echo Run this to make create the approval review by a codeowner:
echo You will need to have set the pr_approver_token in the
echo .gh-api-examples.conf file. The value should be a PAT of
echo a user with permissions to approve the pull request.
if [ ${pr_approver_token} != "replace_with_a_PAT" ]; then
echo "Do you want to create an approving review by a codeowner using token ${pr_approver_token}:"
x=n
read x
if [ "$x" != "y" ]; then
echo "Skip creating approval review by codeowner"
elif [ "$x" == "y" ]; then
printf "${highlight} - Creating an approving review for a pull request: ${normal}"
./create-approving-review-for-a-pull-request.sh | jq -r '.html_url'
fi
fi

read x
printf "${highlight} - Creating an approving review for a pull request: ${normal}"
./create-approving-review-for-a-pull-request.sh | jq -r '.html_url'
echo -------------------------------------------

echo Run these two to make the checks update their status:
# Ask the user if they want to run these two commands to update the check statuses

clear
echo -------------------------------------------
echo
echo "Press y to update the optional commit status to success"
echo "Press any other key to skip this step"
echo
x=n
read x
printf "${highlight} - Updating status for optional check to success: ${normal}"
./create-commit-status.sh success ci-test/this-check-is-optional | jq -r '.id'
if [ "$x" != "y" ]; then
echo "Skipping updating the optional commit status"
elif [ "$x" == "y" ]; then
printf "${highlight} - Updating status for optional commit-status-opitonal to success: ${normal}"
./create-commit-status.sh success ci/commit-status-optional | jq -r '.id'
fi

clear
x=n
echo
echo "Press y to update the required commit status to success"
echo "Press any other key to skip this step"
echo
read x
printf "${highlight} - Updating status for required check to success: ${normal}"
./create-commit-status.sh success ci-test/this-check-is-required | jq -r '.id'
if [ "$x" != "y" ]; then
echo "Skipping updating ci/commit-status-required"
elif [ "$x" == "y" ]; then
printf "${highlight} - Updating status for required check to success: ${normal}"
./create-commit-status.sh success ci/commit-status-required | jq -r '.id'
fi

echo -------------------------------------------

echo If the tiny app is configured and has appropriate permissions
echo check runs can be created with the Checks API:
clear
x=n
echo
echo "Press y to create a check run"
echo "Press any other key to skip this step"
echo
read x
if [ "$x" != "y" ]; then
echo "Skip creating check run"
elif [ "$x" == "y" ]; then
printf "${highlight} - Creating check run with annotation: ${normal}"
check_run_id=$(./tiny-create-check-run-with-annotation.sh | jq -r '.id')
printf "${highlight} - Created check run id: ${check_run_id} ${normal}"
fi

clear
x=n
echo
echo "Press y to update check run id ${check_run_id}"
echo "Press any other key to skip this step"
echo
read x
if [ "$x" != "y" ]; then
echo "Skip updating check run"
elif [ "$x" == "y" ]; then
printf "${highlight} - Updating check run id: $check_run_id ${normal}"
./tiny-update-a-check-run.sh ${check_run_id}
fi

printf "${highlight} - Creating check-run with annotation: ${normal}"
./tiny-create-check-run-with-annotation.sh | jq -r '.id'

2 changes: 1 addition & 1 deletion configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def main(args):
branch_name="new_branch"
protected_branch_name="${base_branch}"
required_approving_reviewers=1
required_status_check_name="ci-test/this-check-is-required"
required_status_check_name="ci/commit-status-required"
enforce_admins="false"
base_branch=${base_branch}
delete_branch_on_merge=${delete_branch_on_merge}
Expand Down
4 changes: 2 additions & 2 deletions create-commit-status.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/enterprise-cloud@latest/rest/commits/statuses?apiVersion=2022-11-28#create-a-commit-status
# POST POST /repos/{owner}/{repo}/statuses/{sha}
# POST /repos/{owner}/{repo}/statuses/{sha}

# The state of the status.
# Can be one of: error, failure, pending, success
Expand All @@ -16,7 +16,7 @@ fi

if [ -z "$2" ]
then
status_context="ci-test/this-check-is-required"
status_context="ci/pwr-commit-status-required"
else
status_context=$2
fi
Expand Down
2 changes: 1 addition & 1 deletion tiny-app-create-check-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fi

if [ -z "$2" ]
then
status_context="ci-test/this-check-is-required"
status_context="ci/commit-status-required"
else
status_context=$2
fi
Expand Down
5 changes: 1 addition & 4 deletions update-branch-protection-with-required-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ fi
json_file=tmp/branch-protection.json
source_json=test-data/api-doc-set-branch-protection.json


# | .required_status_checks.checks = [ $required_status_check_name ]

cat ${source_json}| jq --arg team_slug "$team_slug" \
--arg team_admin "$team_admin" \
--argjson enforce_admins $enforce_admins \
--argjson required_approving_reviewers ${required_approving_reviewers} \
--arg required_status_check_name ${required_status_check_name} \
'.restrictions.users = [ $team_admin] | .restrictions.teams = [$team_slug]
| .required_status_checks.checks = [ { context: $required_status_check_name, app_id: null } ]
| .required_status_checks.checks = [ { context: $required_status_check_name, app_id: null },{ context: "ci/commit-status-required", app_id: null } ]
| .required_pull_request_reviews.dismissal_restrictions.users = [ $team_admin ]
| .required_pull_request_reviews.dismissal_restrictions.teams = [ $team_slug ]
| .required_pull_request_reviews.required_approving_review_count = $required_approving_reviewers
Expand Down