Skip to content

Instantly share code, notes, and snippets.

@thecode
Forked from bdraco/core_integration_pr
Created January 27, 2025 13:43
Show Gist options
  • Select an option

  • Save thecode/2f725a121fb71840d8a245381fab9a4f to your computer and use it in GitHub Desktop.

Select an option

Save thecode/2f725a121fb71840d8a245381fab9a4f to your computer and use it in GitHub Desktop.

Revisions

  1. @bdraco bdraco revised this gist May 6, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion core_integration_pr
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    #!/bin/bash
    # curl -o- -L https://gist.githubusercontent.com/ludeeus/d5d7a96823ca8cd03833c3129114b0f4/raw/core_integration_pr | bash /dev/stdin -d domain -p 12345
    # curl -o- -L https://gist.githubusercontent.com/bdraco/43f8043cb04b9838383fd71353e99b18/raw/core_integration_pr | bash /dev/stdin -d domain -p 12345

    while getopts d:p: flag
    do
  2. @bdraco bdraco revised this gist May 6, 2023. No changes.
  3. @bdraco bdraco revised this gist May 6, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion core_integration_pr
    Original file line number Diff line number Diff line change
    @@ -57,7 +57,7 @@ cd "${tmp_git_dir}"

    info "Checking out PR#${pull_request}"
    git fetch origin --depth 1 "pull/${pull_request}/head"
    git checkout -b origin/`git ls-remote origin pull/${pull_request}/head | awk '{print $1}'`
    git checkout `git ls-remote origin pull/${pull_request}/head | awk '{print $1}'`

    if [[ ! -d "${tmp_git_dir}/homeassistant/components/${domain}" ]]; then
    error "Integration with ${domain} does not exist in PR#${pull_request}"
  4. @bdraco bdraco revised this gist May 6, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion core_integration_pr
    Original file line number Diff line number Diff line change
    @@ -57,7 +57,7 @@ cd "${tmp_git_dir}"

    info "Checking out PR#${pull_request}"
    git fetch origin --depth 1 "pull/${pull_request}/head"
    git checkout -b "pull/${pull_request}/head"
    git checkout -b origin/`git ls-remote origin pull/${pull_request}/head | awk '{print $1}'`

    if [[ ! -d "${tmp_git_dir}/homeassistant/components/${domain}" ]]; then
    error "Integration with ${domain} does not exist in PR#${pull_request}"
  5. @ludeeus ludeeus revised this gist Apr 18, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion core_integration_pr
    Original file line number Diff line number Diff line change
    @@ -67,7 +67,7 @@ info "Removing current folder ${current_dir}/custom_components/${domain}"
    rm -rf "${current_dir}/custom_components/${domain}"

    info "Copying integration files"
    mkdir -p "${current_dir}/custom_components/${domain}"
    mkdir -p "${current_dir}/custom_components"
    mv "${tmp_git_dir}/homeassistant/components/${domain}" "${current_dir}/custom_components/"

    if [[ -f "${current_dir}/custom_components/${domain}/strings.json" ]]; then
  6. @ludeeus ludeeus revised this gist Apr 18, 2023. 1 changed file with 2 additions and 4 deletions.
    6 changes: 2 additions & 4 deletions core_integration_pr
    Original file line number Diff line number Diff line change
    @@ -63,10 +63,8 @@ if [[ ! -d "${tmp_git_dir}/homeassistant/components/${domain}" ]]; then
    error "Integration with ${domain} does not exist in PR#${pull_request}"
    fi

    if [[ -d "${current_dir}/custom_components/${domain}" ]]; then
    info "Removing current folder ${current_dir}/custom_components/${domain}"
    rm -rf "${current_dir}/custom_components/${domain}"
    fi
    info "Removing current folder ${current_dir}/custom_components/${domain}"
    rm -rf "${current_dir}/custom_components/${domain}"

    info "Copying integration files"
    mkdir -p "${current_dir}/custom_components/${domain}"
  7. @ludeeus ludeeus revised this gist Apr 18, 2023. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions core_integration_pr
    Original file line number Diff line number Diff line change
    @@ -51,10 +51,14 @@ if [[ ! -f ".HA_VERSION" ]]; then
    fi


    info "Checking out home-assistant/core#${pull_request}"
    git clone --depth 1 --branch "pull/${pull_request}/head" https://github.com/home-assistant/core.git "${tmp_git_dir}"
    info "Cloning core to "
    git clone --depth 1 https://github.com/home-assistant/core.git "${tmp_git_dir}"
    cd "${tmp_git_dir}"

    info "Checking out PR#${pull_request}"
    git fetch origin --depth 1 "pull/${pull_request}/head"
    git checkout -b "pull/${pull_request}/head"

    if [[ ! -d "${tmp_git_dir}/homeassistant/components/${domain}" ]]; then
    error "Integration with ${domain} does not exist in PR#${pull_request}"
    fi
  8. @ludeeus ludeeus revised this gist Apr 18, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion core_integration_pr
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    #!/bin/bash
    # curl -o- -L https://gist.githubusercontent.com/ludeeus/d5d7a96823ca8cd03833c3129114b0f4/core_integration_pr | bash /dev/stdin -d domain -p 12345
    # curl -o- -L https://gist.githubusercontent.com/ludeeus/d5d7a96823ca8cd03833c3129114b0f4/raw/core_integration_pr | bash /dev/stdin -d domain -p 12345

    while getopts d:p: flag
    do
  9. @ludeeus ludeeus revised this gist Apr 18, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion core_integration_pr
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    #!/bin/bash
    # wget -O - https://gist.githubusercontent.com/ludeeus/d5d7a96823ca8cd03833c3129114b0f4/raw/core_integration_pr | bash - -d domain_name -p pr_number
    # curl -o- -L https://gist.githubusercontent.com/ludeeus/d5d7a96823ca8cd03833c3129114b0f4/core_integration_pr | bash /dev/stdin -d domain -p 12345

    while getopts d:p: flag
    do
  10. @ludeeus ludeeus revised this gist Apr 18, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion core_integration_pr
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    #!/bin/bash
    # wget -O - https://gist.githubusercontent.com/ludeeus/d5d7a96823ca8cd03833c3129114b0f4/raw/give_me_pr | bash - -d domain_name -p pr_number
    # wget -O - https://gist.githubusercontent.com/ludeeus/d5d7a96823ca8cd03833c3129114b0f4/raw/core_integration_pr | bash - -d domain_name -p pr_number

    while getopts d:p: flag
    do
  11. @ludeeus ludeeus renamed this gist Apr 18, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion give_me_pr → core_integration_pr
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    #!/bin/bash
    # wget -O - https://some_url | bash - -d domain_name -p pr_number
    # wget -O - https://gist.githubusercontent.com/ludeeus/d5d7a96823ca8cd03833c3129114b0f4/raw/give_me_pr | bash - -d domain_name -p pr_number

    while getopts d:p: flag
    do
  12. @ludeeus ludeeus revised this gist Apr 18, 2023. 1 changed file with 3 additions and 8 deletions.
    11 changes: 3 additions & 8 deletions give_me_pr
    Original file line number Diff line number Diff line change
    @@ -47,19 +47,14 @@ if [[ -z "${pull_request}" ]]; then
    fi

    if [[ ! -f ".HA_VERSION" ]]; then
    info "Not a Home Assistant folder!"
    # exit 1
    error "Not a Home Assistant folder!"
    fi


    info "Cloning core to "
    git clone --depth 1 https://github.com/home-assistant/core.git "${tmp_git_dir}"
    info "Checking out home-assistant/core#${pull_request}"
    git clone --depth 1 --branch "pull/${pull_request}/head" https://github.com/home-assistant/core.git "${tmp_git_dir}"
    cd "${tmp_git_dir}"

    info "Checking out PR#${pull_request}"
    git fetch origin "pull/${pull_request}/head"
    git checkout -b "pull/${pull_request}/head"

    if [[ ! -d "${tmp_git_dir}/homeassistant/components/${domain}" ]]; then
    error "Integration with ${domain} does not exist in PR#${pull_request}"
    fi
  13. @ludeeus ludeeus revised this gist Apr 18, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion give_me_pr
    Original file line number Diff line number Diff line change
    @@ -78,7 +78,7 @@ if [[ -f "${current_dir}/custom_components/${domain}/strings.json" ]]; then
    mv "${current_dir}/custom_components/${domain}/strings.json" "${current_dir}/custom_components/${domain}/translations/en.json"
    fi

    jq '.version = "${pull_request}"' "${current_dir}/custom_components/${domain}/manifest.json" > tmp && mv -f tmp "${current_dir}/custom_components/${domain}/manifest.json"
    jq --arg pull_request "${pull_request}" '.version = $pull_request' "${current_dir}/custom_components/${domain}/manifest.json" > tmp && mv -f tmp "${current_dir}/custom_components/${domain}/manifest.json"

    info "DONE!"
    info "You now need to restart Home Assistant"
  14. @ludeeus ludeeus created this gist Apr 18, 2023.
    86 changes: 86 additions & 0 deletions give_me_pr
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,86 @@
    #!/bin/bash
    # wget -O - https://some_url | bash - -d domain_name -p pr_number

    while getopts d:p: flag
    do
    case "${flag}" in
    d) domain="${OPTARG}";;
    p) pull_request="${OPTARG}";;
    esac
    done


    function info () { echo -e "${GREEN_COLOR}INFO: $1${NO_COLOR}";}
    function error () { echo -e "${RED_COLOR}ERROR: $1${NO_COLOR}"; if [ "$2" != "false" ]; then exit 1;fi; }

    current_dir="${PWD}"
    tmp_git_dir=/tmp/core_git

    set -e
    clean_up () {
    ARG=$?
    info "Cleaning up"
    cd "$current_dir"
    rm -rf "${tmp_git_dir}"
    exit $ARG
    }
    trap clean_up EXIT


    if [ -z "$(command -v "git")" ]; then
    error "'git' is not installed"
    fi

    if [ -z "$(command -v "jq")" ]; then
    error "'jq' is not installed"
    fi


    info "Current dir is ${current_dir}"

    if [[ -z "${domain}" ]]; then
    error "Missing domain (-d) argument";
    fi

    if [[ -z "${pull_request}" ]]; then
    error "Missing pull request (-p) argument";
    fi

    if [[ ! -f ".HA_VERSION" ]]; then
    info "Not a Home Assistant folder!"
    # exit 1
    fi


    info "Cloning core to "
    git clone --depth 1 https://github.com/home-assistant/core.git "${tmp_git_dir}"
    cd "${tmp_git_dir}"

    info "Checking out PR#${pull_request}"
    git fetch origin "pull/${pull_request}/head"
    git checkout -b "pull/${pull_request}/head"

    if [[ ! -d "${tmp_git_dir}/homeassistant/components/${domain}" ]]; then
    error "Integration with ${domain} does not exist in PR#${pull_request}"
    fi

    if [[ -d "${current_dir}/custom_components/${domain}" ]]; then
    info "Removing current folder ${current_dir}/custom_components/${domain}"
    rm -rf "${current_dir}/custom_components/${domain}"
    fi

    info "Copying integration files"
    mkdir -p "${current_dir}/custom_components/${domain}"
    mv "${tmp_git_dir}/homeassistant/components/${domain}" "${current_dir}/custom_components/"

    if [[ -f "${current_dir}/custom_components/${domain}/strings.json" ]]; then
    mkdir -p "${current_dir}/custom_components/${domain}/translations"
    mv "${current_dir}/custom_components/${domain}/strings.json" "${current_dir}/custom_components/${domain}/translations/en.json"
    fi

    jq '.version = "${pull_request}"' "${current_dir}/custom_components/${domain}/manifest.json" > tmp && mv -f tmp "${current_dir}/custom_components/${domain}/manifest.json"

    info "DONE!"
    info "You now need to restart Home Assistant"
    info "NOTE: If the PR changed anything outside of it´s own folder this method will not work."
    info "If you want to remove this, you need to delete the ${current_dir}/custom_components/${domain} folder"