<commit_before>#!/usr/bin/env bash
#
# This script is meant to run on every new commit to main in CircleCI. If the commit comes from a PR, it will
# check the PR associated with the commit for labels. If the label matches `docs*` it will be cherry-picked
# to stable-website. If the label matches `backport/*`, it will be cherry-picked to the appropriate `release/*`
# branch.

# Requires $CIRCLE_PROJECT_USERNAME, $CIRCLE_PROJECT_REPONAME, and $CIRCLE_SHA1 from CircleCI

set -o pipefail

# colorized status prompt
function status {
    tput setaf 4
    echo "$@"
    tput sgr0
}

# Returns the latest GitHub "backport/*" label
function get_latest_backport_label {
    local resp
    local ret
    local latest_backport_label

    resp=$(curl -f -s -H "Authorization: token ${GITHUB_TOKEN}" "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/labels")
    ret="$?"
    if [[ "$ret" -ne 0 ]]; then
        status "The GitHub API returned $ret which means it was probably rate limited."
        exit $ret
    fi

    latest_backport_label=$(echo "$resp" | jq -r '.[] | select(.name | startswith("backport/")) | .name' | sort -rV | head -n1)
    echo "$latest_backport_label"
    return 0
}

# This function will do the cherry-picking of a commit on a branch
# Exit 1 if cherry-picking fails
function cherry_pick_with_slack_notification {
    # Arguments:
    #   $1 - branch to cherry-pick to
    #   $2 - commit to cherry-pick
    #   $3 - url to PR of commit<commit_msg>ci: query for max number of possible labels<commit_after>#!/usr/bin/env bash
#
# This script is meant to run on every new commit to main in CircleCI. If the commit comes from a PR, it will
# check the PR associated with the commit for labels. If the label matches `docs*` it will be cherry-picked
# to stable-website. If the label matches `backport/*`, it will be cherry-picked to the appropriate `release/*`
# branch.

# Requires $CIRCLE_PROJECT_USERNAME, $CIRCLE_PROJECT_REPONAME, and $CIRCLE_SHA1 from CircleCI

set -o pipefail

# colorized status prompt
function status {
    tput setaf 4
    echo "$@"
    tput sgr0
}

# Returns the latest GitHub "backport/*" label
function get_latest_backport_label {
    local resp
    local ret
    local latest_backport_label

    resp=$(curl -f -s -H "Authorization: token ${GITHUB_TOKEN}" "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/labels?per_page=100")
    ret="$?"
    if [[ "$ret" -ne 0 ]]; then
        status "The GitHub API returned $ret which means it was probably rate limited."
        exit $ret
    fi

    latest_backport_label=$(echo "$resp" | jq -r '.[] | select(.name | startswith("backport/")) | .name' | sort -rV | head -n1)
    echo "$latest_backport_label"
    return 0
}

# This function will do the cherry-picking of a commit on a branch
# Exit 1 if cherry-picking fails
function cherry_pick_with_slack_notification {
    # Arguments:
    #   $1 - branch to cherry-pick to
    #   $2 - commit to cherry-pick
    #   $3 - url to PR of commit
{'fraction_non_alphanumeric': 0.1020006559527714, 'fraction_numerical': 0.00754345687110528, 'mean_word_length': 3.394812680115274, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, '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': '3378178', 'n_tokens_mistral': 1019, 'n_tokens_neox': 978, 'n_words': 354}