Skip to content

Commit cff9753

Browse files
authored
Merge pull request #551 from gm3dmo/forcepush
forcepush
2 parents 8f208e4 + f41cbaa commit cff9753

4 files changed

Lines changed: 119 additions & 1 deletion

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
normal=$(tput sgr0)
2+
highlight=$(tput setaf 2)
3+
4+
printf "$highlight"
5+
6+
cat << EOF
7+
8+
________ ____
9+
/_ __/ /_ ___ / __ \____ _ _____ _____
10+
/ / / __ \/ _ \ / /_/ / __ \ | /| / / _ \/ ___/
11+
/ / / / / / __/ / ____/ /_/ / |/ |/ / __/ /
12+
/_/ /_/ /_/\___/ /_/ \____/|__/|__/\___/_/
13+
14+
EOF
15+
16+
printf "${normal}"
17+
18+
printf "${highlight} - Creating repo: ${normal}"
19+
./create-repo-testrepo.sh | jq -r '.name'
20+
21+
printf "${highlight} - Adding team to repo (team_slug must be set in your .gh-api-examples.conf file)${normal}\n"
22+
./add-team-to-repo.sh
23+
24+
printf "${highlight} - Creating webhook: ${normal}"
25+
./create-webhook.sh | jq -r '.id'
26+
27+
printf "${highlight} - Creating docs/README.md: ${normal}"
28+
./create-commit-readme.sh | jq -r ".content.html_url"
29+
30+
printf "${highlight} - Creating workflow file: ${normal}"
31+
./create-commit-workflow-pwr.sh | jq -r ".content.html_url"
32+
33+
printf "${highlight} - Creating CODEOWNERS: ${normal}"
34+
./create-commit-codeowners.sh| jq -r ".content.html_url"
35+
36+
printf "${highlight} - Creating requirements.txt: ${normal}"
37+
./create-commit-python-pip.sh| jq -r ".content.html_url"
38+
sleep 2
39+
40+
printf "${highlight} - Creating new branch: ${normal}"
41+
./create-branch-newbranch.sh | jq -r '.url'
42+
43+
printf "${highlight} - Creating a commit on the new branch: ${normal}"
44+
./create-commit-on-new-branch.sh | jq -r ".content.html_url"
45+
46+
printf "${highlight} - Creating an update commit to docs/README.md: ${normal}"
47+
./create-commit-update-readme.sh | jq -r ".content.html_url"
48+
49+
50+
printf "${highlight} - Creating an issue: ${normal}"
51+
./create-repo-issue.sh | jq -r '.html_url'
52+
53+
printf "${highlight} - Creating a pull request: ${normal}"
54+
./create-pull-request.sh | jq -r '.html_url'
55+
56+
printf "${highlight} - Setting branch protection rules on default branch: ${normal}"
57+
./set-branch-protection.sh | jq -r '.url'
58+
59+
printf "${highlight} - Creating a release: ${normal}"
60+
./create-release.sh | jq -r '.html_url'
61+
62+
printf "${highlight} - Adding a .gitattributes file to new branch: ${normal}"
63+
./create-commit-gitattributes.sh | jq -r ".content.html_url"
64+
65+
printf "${highlight} - Force-updating ${branch_name} to parent (destroying README update commit): ${normal}"
66+
./force-update-branch-to-parent.sh | jq -r '.object.sha'
67+
echo
68+
69+
70+
# If you have the appropriate token set in `pr_approver_token`
71+
# then you can provide an approving review:
72+
# ./create-approving-review-for-a-pull-request.sh

configure.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ def main(args):
184184
185185
### [Commits](https://docs.github.com/en/rest/commits/commits)
186186
default_committer="${default_committer}"
187+
force_update_reference=false
187188
188189
189190
### [Checks](https://docs.github.com/en/rest/guides/getting-started-with-the-checks-api)

force-update-branch-to-parent.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
. ./.gh-api-examples.conf
2+
3+
# https://docs.github.com/en/rest/git/refs?apiVersion=2022-11-28#update-a-reference
4+
# PATCH /repos/{owner}/{repo}/git/refs/{ref}
5+
#
6+
# Force-updates a branch to its parent commit, destroying the latest commit.
7+
# This demonstrates a destructive force-push that rewrites branch history.
8+
9+
if [ -z "$1" ]
10+
then
11+
branch=${branch_name}
12+
else
13+
branch=$1
14+
fi
15+
16+
# Get the current tip commit SHA of the branch
17+
tip_sha=$(curl ${curl_custom_flags} --silent \
18+
-H "Accept: application/vnd.github.v3+json" \
19+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
20+
"${GITHUB_API_BASE_URL}/repos/${org}/${repo}/branches/${branch}" | jq -r '.commit.sha')
21+
22+
# Get the parent commit SHA (one commit back)
23+
parent_sha=$(curl ${curl_custom_flags} --silent \
24+
-H "Accept: application/vnd.github.v3+json" \
25+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
26+
"${GITHUB_API_BASE_URL}/repos/${org}/${repo}/git/commits/${tip_sha}" | jq -r '.parents[0].sha')
27+
28+
json_file=tmp/force-update-branch-to-parent.json
29+
30+
jq -n \
31+
--arg sha "${parent_sha}" \
32+
'{ sha: $sha,
33+
force: true
34+
}' > ${json_file}
35+
36+
curl ${curl_custom_flags} \
37+
-X PATCH \
38+
-H "Accept: application/vnd.github.v3+json" \
39+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
40+
"${GITHUB_API_BASE_URL}/repos/${org}/${repo}/git/refs/heads/${branch}" --data @${json_file}

update-a-reference.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ fi
1212

1313

1414
json_file=tmp/update-a-reference.json
15+
1516
jq -n \
1617
--arg sha "${sha}" \
17-
'{ sha: $sha }' > ${json_file}
18+
--arg force "$force_update_reference" \
19+
'{ sha: $sha,
20+
force: $force | test ("true")
21+
}' > ${json_file}
1822

1923

2024
curl ${curl_custom_flags} \
@@ -23,3 +27,4 @@ curl ${curl_custom_flags} \
2327
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
2428
"${GITHUB_API_BASE_URL}/repos/${org}/${repo}/git/refs/heads/${base_branch}" --data @${json_file}
2529

30+

0 commit comments

Comments
 (0)