From d20c943e0ac6bae7e96bc1e23162ead39e9ea321 Mon Sep 17 00:00:00 2001 From: Josh Hagins Date: Wed, 19 Oct 2016 10:49:22 -0400 Subject: [PATCH] Remove {find,fix,merge}_outdated_appcasts scripts (#25936) Refs https://github.com/caskroom/homebrew-cask/issues/25926 --- developer/bin/find_outdated_appcasts | 121 -------------------------- developer/bin/fix_outdated_appcasts | 78 ----------------- developer/bin/merge_outdated_appcasts | 99 --------------------- 3 files changed, 298 deletions(-) delete mode 100755 developer/bin/find_outdated_appcasts delete mode 100755 developer/bin/fix_outdated_appcasts delete mode 100755 developer/bin/merge_outdated_appcasts diff --git a/developer/bin/find_outdated_appcasts b/developer/bin/find_outdated_appcasts deleted file mode 100755 index 1ec6e77d9f..0000000000 --- a/developer/bin/find_outdated_appcasts +++ /dev/null @@ -1,121 +0,0 @@ -#!/bin/bash - -readonly caskroom_online='https://github.com/caskroom' -readonly caskroom_repos_dir='/tmp/caskroom_repos' -readonly caskroom_repos=(homebrew-cask homebrew-versions homebrew-fonts homebrew-eid) -readonly curl_flags=(--silent --location --header 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36') -inaccessible_appcasts=() - -if [[ ! $(which 'ghi') ]] || ! security find-internet-password -s github.com -l 'ghi token' &> /dev/null; then - echo -e "$(tput setaf 1) - This script requires 'ghi' installed and configured. - If you have [Homebrew](http://brew.sh), you can install it with 'brew install ghi'. - To configure it, run 'ghi config --auth '. Your Github password will be required, but is never stored. - $(tput sgr0)" | sed -E 's/ {4}//' >&2 - exit 1 -fi - -function message { - echo "${1}" -} - -function go_to_repos_dir { - [[ ! -d "${caskroom_repos_dir}" ]] && mkdir -p "${caskroom_repos_dir}" - cd "${caskroom_repos_dir}" || exit 1 -} - -function go_to_repo_and_update { - local repo_name repo_dir casks_dir - - repo_name="${1}" - repo_dir="${caskroom_repos_dir}/${repo_name}" - casks_dir="${repo_dir}/Casks" - - if [[ ! -d "${repo_dir}" ]]; then - go_to_repos_dir - - message "Cloning ${repo_name}…" - git clone "${caskroom_online}/${repo_name}.git" --quiet - - cd "${casks_dir}" || exit 1 - else - cd "${casks_dir}" || exit 1 - - message "Updating ${repo_name}…" - git pull --rebase origin master --quiet - fi -} - -function open_issue { - local repo_name cask_name cask_url version appcast_url issue_number - - repo_name="${1}" - cask_name="${2}" - cask_url="${caskroom_online}/${repo_name}/blob/master/Casks/${cask_name}.rb" - version="${3}" - appcast_url="${4}" - - message="$(echo "Outdated cask: ${cask_name} - - Outdated cask: [\`${cask_name}\`](${cask_url}). - - Info: - + version: \`${version}\`. - + appcast url: ${appcast_url}. - " | sed -E 's/^ {4}//')" - - issue_number=$(ghi open --label 'outdated appcast' --message "${message}" | head -1 | perl -pe 's/^#(\d+): .*/\1/') - message "Opened issue: ${caskroom_online}/${repo_name}/issues/${issue_number}." -} - -function is_appcast_available { - local appcast_url - - appcast_url="${1}" - - http_status="$(curl "${curl_flags[@]}" --head --write-out '%{http_code}' "${appcast_url}" -o '/dev/null')" - - [[ "${http_status}" == 200 ]] -} - -function report_outdated_appcasts { - local repo_name cask_name appcast_url current_checkpoint new_checkpoint version - - repo_name="${1}" - - for cask_file in ./*; do - appcast_url="$(brew cask _stanza appcast "${cask_file}")" - [[ -z "${appcast_url}" ]] && continue # skip early if there is no appcast - - cask_name="$(basename "${cask_file%.*}")" - - message "Verifying appcast checkpoint for ${cask_name}…" - - if is_appcast_available "${appcast_url}"; then - current_checkpoint="$(brew cask _stanza --yaml appcast "${cask_file}" | grep '^- :checkpoint' | awk '{print $3}')" - new_checkpoint="$(curl "${curl_flags[@]}" --compressed "${appcast_url}" | sed 's|[^<]*||g' | shasum --algorithm 256 | awk '{ print $1 }')" - else - message "There was an error checking the appcast for ${cask_name}." - inaccessible_appcasts+=("${repo_name}/${cask_name}") - continue - fi - - if [[ "${current_checkpoint}" != "${new_checkpoint}" ]]; then - version="$(brew cask _stanza version "${cask_file}")" - - message "${cask_name} is outdated. Opening issue in ${repo_name}…" - open_issue "${repo_name}" "${cask_name}" "${version}" "${appcast_url}" - fi - done -} - -for repo in "${caskroom_repos[@]}"; do - go_to_repo_and_update "${repo}" - report_outdated_appcasts "${repo}" -done - -if [[ ${#inaccessible_appcasts[@]} -gt 0 ]];then - echo # empty line - message 'Some casks have appcasts that errored out, and may need to be rechecked:' - printf '%s\n' "${inaccessible_appcasts[@]}" -fi diff --git a/developer/bin/fix_outdated_appcasts b/developer/bin/fix_outdated_appcasts deleted file mode 100755 index 9915b5339b..0000000000 --- a/developer/bin/fix_outdated_appcasts +++ /dev/null @@ -1,78 +0,0 @@ -#!/bin/bash - -IFS=$'\n' - -readonly caskroom_repos_dir='/tmp/caskroom_repos' -readonly caskroom_repos=(homebrew-cask homebrew-versions homebrew-fonts homebrew-eid) - -if [[ ! $(which 'ghi') ]] || ! security find-internet-password -s github.com -l 'ghi token' &> /dev/null; then - echo -e "$(tput setaf 1) - This script requires 'ghi' installed and configured. - If you have [Homebrew](http://brew.sh), you can install it with 'brew install ghi'. - To configure it, run 'ghi config --auth '. Your Github password will be required, but is never stored. - $(tput sgr0)" | sed -E 's/ {4}//' >&2 - exit 1 -fi - -if [[ ! $(which 'cask-repair') ]]; then - echo -e "$(tput setaf 1) - This script requires 'cask-repair'. - If you have [Homebrew](http://brew.sh), you can install it with 'brew install vitorgalvao/tiny-scripts/cask-repair'. - $(tput sgr0)" | sed -E 's/ {4}//' >&2 - exit 1 -fi - -function message { - echo "${1}" -} - -function go_to_repos_dir { - [[ ! -d "${caskroom_repos_dir}" ]] && mkdir -p "${caskroom_repos_dir}" - cd "${caskroom_repos_dir}" || exit 1 -} - -function go_to_repo_and_update { - local repo_name repo_dir casks_dir - - repo_name="${1}" - repo_dir="${caskroom_repos_dir}/${repo_name}" - casks_dir="${repo_dir}/Casks" - - if [[ ! -d "${repo_dir}" ]]; then - go_to_repos_dir - - message "Cloning ${repo_name}…" - git clone "https://github.com/caskroom/${repo_name}.git" --quiet - - cd "${casks_dir}" || exit 1 - else - cd "${casks_dir}" || exit 1 - - message "Updating ${repo_name}…" - git pull --rebase origin master --quiet - fi -} - -function fix_outdated_appcasts { - local issue_number cask_name pr_number - - for line in $(ghi list --state open --no-pulls --label 'outdated appcast' --reverse | tail +2); do - [[ "${line}" == 'None.' ]] && break # exit early if there are no relevant issues in repo - - issue_number="$(awk '{print $1}' <<< "${line}")" - cask_name="$(awk '{print $4}' <<< "${line}")" - - cask-repair --pull origin --push origin --open-appcast --closes-issue "${issue_number}" --blind-submit "${cask_name}" - - if [[ "$?" -eq 0 ]]; then - pr_number="$(ghi list --pulls --creator | sed -n 2p | awk '{print $1}')" - ghi edit --label 'outdated appcast' "${pr_number}" &>/dev/null - ghi comment --close --message "Closing in favour of #${pr_number}." "${issue_number}" &>/dev/null - fi - done -} - -for repo in "${caskroom_repos[@]}"; do - go_to_repo_and_update "${repo}" - fix_outdated_appcasts -done diff --git a/developer/bin/merge_outdated_appcasts b/developer/bin/merge_outdated_appcasts deleted file mode 100755 index ae5f808db7..0000000000 --- a/developer/bin/merge_outdated_appcasts +++ /dev/null @@ -1,99 +0,0 @@ -#!/bin/bash - -IFS=$'\n' - -readonly caskroom_online='https://github.com/caskroom' -readonly caskroom_repos_dir='/tmp/caskroom_repos' -readonly caskroom_repos=(homebrew-cask homebrew-versions homebrew-fonts homebrew-eid) - -if [[ ! $(which 'ghi') ]] || ! security find-internet-password -s github.com -l 'ghi token' &> /dev/null; then - echo -e "$(tput setaf 1) - This script requires 'ghi' installed and configured. - If you have [Homebrew](http://brew.sh), you can install it with 'brew install ghi'. - To configure it, run 'ghi config --auth '. Your Github password will be required, but is never stored. - $(tput sgr0)" | sed -E 's/ {4}//' >&2 - exit 1 -fi - -if [[ ! $(which 'fastmerge') ]]; then - echo -e "$(tput setaf 1) - This script requires 'fastmerge'. - If you have [Homebrew](http://brew.sh), you can install it with 'brew install vitorgalvao/tiny-scripts/fastmerge'. - $(tput sgr0)" | sed -E 's/ {4}//' >&2 - exit 1 -fi - -function message { - echo "${1}" -} - -function go_to_repos_dir { - [[ ! -d "${caskroom_repos_dir}" ]] && mkdir -p "${caskroom_repos_dir}" - cd "${caskroom_repos_dir}" || exit 1 -} - -function go_to_repo_and_update { - local repo_name repo_dir casks_dir - - repo_name="${1}" - repo_dir="${caskroom_repos_dir}/${repo_name}" - casks_dir="${repo_dir}/Casks" - - if [[ ! -d "${repo_dir}" ]]; then - go_to_repos_dir - - message "Cloning ${repo_name}…" - git clone "${caskroom_online}/${repo_name}.git" --quiet - - cd "${casks_dir}" || exit 1 - else - cd "${casks_dir}" || exit 1 - - message "Updating ${repo_name}…" - git pull --rebase origin master --quiet - fi -} - -function delete_current_branch { - local current_branch - - current_branch="$(git rev-parse --abbrev-ref HEAD)" - git checkout master --quiet - git branch -D "${current_branch}" --quiet -} - -function delete_cask_repair_branches { - [[ $(ghi list --state open --pulls --label 'outdated appcast' | tail -1) == 'None.' ]] && cask-repair --push origin --delete-branches -} - -function merge_outdated_appcasts { - local repo_name pr_number cask_name pr_url last_commit - - repo_name="${1}" - - for line in $(ghi list --state open --pulls --label 'outdated appcast' --reverse | tail +2); do - [[ "${line}" == 'None.' ]] && break # exit early if there are no relevant issues in repo - - pr_number="$(awk '{print $1}' <<< "${line}")" - cask_name="$(awk '{print $3}' <<< "${line}")" - pr_url="${caskroom_online}/${repo_name}/pull/${pr_number}" - - hub checkout "${pr_url}" &>/dev/null - last_commit="$(git log -n 1 --pretty=format:'%H')" - delete_current_branch - - if [[ "$(hub ci-status "${last_commit}")" == 'success' ]]; then - message "Merging pull request for ${cask_name}…" - fastmerge --maintainer --remote origin "${pr_url}" - else - continue - fi - done -} - -for repo in "${caskroom_repos[@]}"; do - go_to_repo_and_update "${repo}" - merge_outdated_appcasts "${repo}" - delete_cask_repair_branches - git gc -done