Created
May 23, 2026 22:35
-
-
Save GamerGirlandCo/cb28717861782aa126b41aadf0cf1c28 to your computer and use it in GitHub Desktop.
gitea pull request checkout script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| OPTS=$(getopt -o h::s:p:t:w:c:b:a: --long help::,src:,src-dir:,pr:,pull:,tags:,custom:,work-path:,work:,conf:,branch:,auto-run: -n 'gitea-pr-clone.sh' -- "$@") | |
| if [ $? -ne 0 ]; then | |
| echo "Failed to parse options" >&2 | |
| exit 1 | |
| fi | |
| eval set -- "$OPTS" | |
| SRC_DIR="$(realpath ./gitea)" | |
| PR=37630 | |
| BRANCH_NAME="" | |
| TAGS="bindata sqlite sqlite_unlock_notify" | |
| WORK_PATH="/opt/gitea-secondary" | |
| CUSTOM_PATH="custom" | |
| CONF_FILE="app.ini" | |
| AUTO_RUN=false | |
| dir_exists() { | |
| if [ -d "$1" ]; then | |
| return 0; | |
| else | |
| return 1; | |
| fi | |
| } | |
| is_absolute_path() { | |
| if [[ $1 == "/*" ]]; then | |
| return 0; | |
| else | |
| return 1; | |
| fi | |
| } | |
| compute_variables() { | |
| if ! is_absolute_path $CUSTOM_PATH; then | |
| CUSTOM_PATH=$WORK_PATH/$CUSTOM_PATH | |
| fi | |
| if ! is_absolute_path $CONF_FILE; then | |
| CONF_FILE=$CUSTOM_PATH/$CONF_FILE | |
| fi | |
| if [ -z BRANCH_NAME ]; then | |
| BRANCH_NAME="pull-$PR" | |
| fi | |
| } | |
| clone() { | |
| if ! dir_exists $SRC_DIR; then | |
| echo "cloning gitea..." | |
| git clone https://github.com/go-gitea/gitea.git $SRC_DIR | |
| fi; | |
| cd $SRC_DIR | |
| git fetch origin pull/$PR/head:$BRANCH_NAME | |
| git checkout $BRANCH_NAME | |
| } | |
| build() { | |
| TAGS="$TAGS" LDFLAGS="-X \"code.gitea.io/gitea/modules/setting.CustomPath=$CUSTOM_PATH\" -X \"code.gitea.io/gitea/modules/setting.AppWorkPath=$WORK_PATH\" -X \"code.gitea.io/gitea/modules/setting.CustomConf=$CONF_FILE\"" make | |
| return $? | |
| } | |
| main() { | |
| compute_variables | |
| clone | |
| if build; then | |
| echo "gitea has been built at ${SRC_DIR}/gitea !" | |
| if [ $AUTO_RUN = "true" ]; then | |
| echo "starting gitea..." | |
| ${SRC_DIR}/gitea web | |
| fi | |
| fi | |
| } | |
| print_help() { | |
| cat <<-'EOF' | |
| OPTIONS: | |
| -h, --help | |
| print this help text | |
| -s, --src, --src-dir <directory> | |
| the source directory to clone the gitea repo into (defaults to "$(pwd)/gitea") | |
| -p, --pr, --pull <NUMBER> | |
| the pull request number to fetch and checkout (defaults to 37630) | |
| -b, --branch <name> | |
| the name of the branch to use when checking out the pull request (defaults to "pull-<number>") | |
| -t, --tags "tag1 tag2" | |
| custom tags to include when building. defaults to "bindata sqlite sqlite_unlock_notify" | |
| -w, --work, --work-path <directory> | |
| custom work path that gitea will use when built. defaults to "/opt/gitea-secondary" | |
| --custom <directory> | |
| where gitea will search for files like custom stylesheets, assets, templates, etc. if non-absolute, will be computed relative to the `work-path` parameter (see above). defaults to "/opt/gitea-secondary/custom" | |
| -c, --conf <conf-file> | |
| custom config file name. if non-absolute, is computed relative to the `custom` parameter (see above). defaults to "app.ini" | |
| -a, --auto-run | |
| whether or not to automatically start gitea after building. defaults to `false` | |
| EOF | |
| } | |
| while true; do | |
| case "$1" in | |
| -h | --help) | |
| print_help | |
| exit 0 | |
| ;; | |
| -s | --src | --src-dir) | |
| SRC_DIR=$2 | |
| shift 2 | |
| ;; | |
| -p | --pr | --pull) | |
| PR=$2 | |
| shift 2 | |
| ;; | |
| -b | --branch) | |
| BRANCH_NAME=$2 | |
| shift 2 | |
| ;; | |
| -t | --tags) | |
| TAGS=$2 | |
| shift 2 | |
| ;; | |
| -w | --work-path | --work) | |
| WORK_PATH=$2 | |
| shift 2 | |
| ;; | |
| -c | --conf) | |
| CONF_FILE=$2 | |
| shift 2 | |
| ;; | |
| --custom) | |
| CUSTOM_PATH=$2 | |
| shift 2 | |
| ;; | |
| --) | |
| shift | |
| break | |
| ;; | |
| *) | |
| print_help | |
| exit 1 | |
| ;; | |
| esac | |
| done | |
| main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment