Skip to content

Instantly share code, notes, and snippets.

@ClobberXD
Created June 11, 2020 14:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ClobberXD/09be48da5001195ebcb1c2b7b39e828e to your computer and use it in GitHub Desktop.
Save ClobberXD/09be48da5001195ebcb1c2b7b39e828e to your computer and use it in GitHub Desktop.
PR creator script for Minetest CTF maps

This script allows you to very easily create PRs for MT-CTF/maps.

Before first run

There are a couple of hard-coded variables in the script, which need to be set before the first run. I didn't bother to make these configurable via command-line args because these variables usually need to be set only once.

  • MAPSREPO (L7): This should contain the path to the local maps repository. This needs to be an absolute path. e.g. /home/test_user/new_super_duper_awesome_map_that_will_get_rejected_immediately/
  • USERNAME (L8): This should contain your GitHub username. You'll need to authenticate, as the PR will be made in your name.

Also, don't forget to mark the script as executable.

Usage

Syntax:

maps_pr.sh <MAPDIR>

MAPDIR is the path to the new map's directory containing the map's files. Relative paths are allowed.

Examples:

maps_pr.sh ~/new_map/    # From anywhere

cd ~/
maps_pr.sh new_map/      # From parent directory

cd new_map/
maps_pr.sh .             # From within the map directory
#!/bin/bash
#
# Configuration variables
#
MAPSREPO="<Path/to/your/local/maps/repo>"
USERNAME="<Your_GitHub_Username_Here>"
BASE="MT-CTF"
LABELS="New map,Review required"
################################################################################
#
# Sanity checks
#
if [[ ${#} -eq 0 ]]; then
echo "[ERROR] Missing maps directory. Aborting!"
exit -1
fi
if [[ ! -d ${1} ]]; then
echo "[ERROR] Invalid maps directory. Aborting!"
exit -1
fi
if [[ ! -d ${MAPSREPO} ]]; then
echo "[ERROR] Invalid maps repository path. Aborting!"
exit -1
fi
################################################################################
#
# Main
#
echo "*** Initialising..."
echo " MAPSREPO=${MAPSREPO}"
# Hacky workaround to retrieve absolute path of map directory
MAPDIR="${1}"
cd "${MAPDIR}"
MAPDIR="${PWD}"
echo " MAPDIR=${MAPDIR}"
MAPNAME="$(basename ${MAPDIR})"
echo " MAPNAME=${MAPNAME}"
#while read line; do
# if [ "$line" -eq "mapauthor = *" ]
#done < "$MAPDIR/map.conf"
cd "${MAPSREPO}" > /dev/null
echo "*** Creating new branch ${MAPNAME}..."
git checkout -b "${MAPNAME}" master > /dev/null 2>&1
echo "*** Adding new map to repository and committing changes..."
cp -r "${MAPDIR}" . > /dev/null
git add "${MAPNAME}/*" > /dev/null 2>&1
git commit -m "Add \"${MAPNAME}\"" > /dev/null 2>&1
echo "*** Pushing to remote..."
# Create a separate remote to not need to depend on the existing remote's name being "origin"
git remote add maps_pr_remote https://github.com/${USERNAME}/maps > /dev/null 2>&1
git push -u "maps_pr_remote" "${MAPNAME}" > /dev/null 2>&1
echo "*** Creating pull request..."
hub pull-request -b "${BASE}:master" -h "${USERNAME}:${MAPNAME}" -l "${LABELS}" -o -m "Add \"${MAPNAME}\"
(This pull request was generated by a script)" > /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment