<commit_before>#! /usr/bin/env sh

API_STATUS=https://www.thebluealliance.com/api/v3/status
SET_BUILD_STATUS=https://www.thebluealliance.com/api/v3/_/build
fetch_apiv3_status() {
    curl -s --header "X-TBA-Auth-Key: $APIv3_KEY" $API_STATUS
}

update_build_info() {
    current_commit=$TRAVIS_COMMIT
    commit_time="$(git show -s --format=%ci HEAD)"
    deploy_time="$(date)"
    travis_job="$TRAVIS_BUILD_ID"

    http $SET_BUILD_STATUS X-TBA-Auth-Key:$APIv3_KEY current_commit="$current_commit" commit_time="$commit_time" deploy_time="$deploy_time" travis_job="$travis_job"
}

check_killswitch() {
    enabled=$(fetch_apiv3_status | jq '.contbuild_enabled')
    if [ "$enabled" != "true" ]; then
        echo "Continuous Deployment disabled via killswitch..."
        exit 0
    fi
}

check_commit_tag() {
    # The most recent commit message
    msg=$(git log -1 --pretty=%B)
    case "$msg" in
        *\[nodeploy\]*) echo "Skipping due to [nodeploy] tag"; exit 0 ;;
    esac
}

check_clowntown_tag() {
    # Don't allow for non-pull requests
    if test "$TRAVIS_PULL_REQUEST" != "false" ; then
        return
    fi

    # The most recent commit message
    msg=$(git log -1 --pretty=%B)
    case "$msg" in
        *\[clowntown\]*) echo "Skipping due to [clowntown] tag. You better know what you're doing..."; exit 0 ;;
    esac
}

should_deploy() {
    check_commit_tag
    check_killswitch
}<commit_msg>Prevent overwriting older commit on deploy<commit_after>#! /usr/bin/env sh

API_STATUS=https://www.thebluealliance.com/api/v3/status
SET_BUILD_STATUS=https://www.thebluealliance.com/api/v3/_/build
fetch_apiv3_status() {
    curl -s --header "X-TBA-Auth-Key: $APIv3_KEY" $API_STATUS
}

update_build_info() {
    current_commit=$TRAVIS_COMMIT
    commit_time="$(git show -s --format=%ci HEAD)"
    deploy_time="$(date)"
    travis_job="$TRAVIS_BUILD_ID"

    http $SET_BUILD_STATUS X-TBA-Auth-Key:$APIv3_KEY current_commit="$current_commit" commit_time="$commit_time" deploy_time="$deploy_time" travis_job="$travis_job"
}

check_killswitch() {
    enabled=$(fetch_apiv3_status | jq '.contbuild_enabled')
    if [ "$enabled" != "true" ]; then
        echo "Continuous Deployment disabled via killswitch..."
        exit 0
    fi
}

check_overwrite_old() {
    echo "Pulling currently deployed commit..."
    web_status=$(fetch_apiv3_status | jq '.web')
    commit=$(echo $web_status | jq '.current_commit')
    prod_time_str=$(echo $web_status | jq '.commit_time')
    local_time_str=$(git show -s --format=%ci HEAD)

    echo "Prod is currently running $commit, committed at $prod_time_str"
    echo "Current commit was committed at $local_time_str"

    # Convert time strings to UNIX time
    prod_time=$(echo $prod_time_str | date +%s)
    local_time=$(echo $local_time_str | date +%s)
    msg=$(git log -1 --pretty=%B)
    if [ "$local_time" -lt "$prod_time" ]; then
        case "$msg" in
            *\[clowntown\]*) echo "Commit is older, but [clowntown] found. Be careful..." ;;
	    *) echo "Not overwriting prod with an older commit, exiting..."; exit 0 ;;
	esac
    fi
}

check_commit_tag() {
    # The most recent commit message
    msg=$(git log -1 --pretty=%B)
    case "$msg" in
        *\[nodeploy\]*) echo "Skipping due to [nodeploy] tag"; exit 0 ;;
    esac
}

check_clowntown_tag() {
    # Don't allow for non-pull requests
    if test "$TRAVIS_PULL_REQUEST" != "false" ; then
        return
    fi

    # The most recent commit message
    msg=$(git log -1 --pretty=%B)
    case "$msg" in
        *\[clowntown\]*) echo "Skipping due to [clowntown] tag. You better know what you're doing..."; exit 0 ;;
    esac
}

should_deploy() {
    check_commit_tag
    check_killswitch
    check_overwrite_old
}
{'fraction_non_alphanumeric': 0.13944757307589167, 'fraction_numerical': 0.006704210244033253, 'mean_word_length': 3.3779342723004695, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1654502', 'n_tokens_mistral': 1324, 'n_tokens_neox': 1279, 'n_words': 317}