github.com/noironetworks/cilium-net@v1.6.12/contrib/backporting/submit-backport (about)

     1  #!/bin/bash
     2  #
     3  # Copyright 2020 Authors of Cilium
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #     http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  
    17  DIR=$(dirname $(readlink -ne $BASH_SOURCE))
    18  source $DIR/../release/lib/common.sh
    19  source $DIR/common.sh
    20  
    21  BRANCH="${1:-}"
    22  if [ "$BRANCH" = "" ]; then
    23      BRANCH=$(git symbolic-ref --short HEAD | sed 's/.*\(v[0-9]\.[0-9]\).*/\1/')
    24  fi
    25  BRANCH=$(echo "$BRANCH" | sed 's/^v//')
    26  
    27  SUMMARY=${2:-}
    28  if [ "$SUMMARY" = "" ]; then
    29      SUMMARY="v$BRANCH-backport-$(date --rfc-3339=date).txt"
    30  fi
    31  
    32  if ! git branch -a | grep -q "origin/v$BRANCH$" || [ ! -e $SUMMARY ]; then
    33      echo "usage: $0 [branch version] [pr-summary]" 1>&2
    34      echo 1>&2
    35      echo "Ensure 'branch version' is available in 'origin' and the summary file exists" 1>&2
    36      exit 1
    37  fi
    38  
    39  if ! hub help | grep -q "pull-request"; then
    40      echo "This tool relies on 'hub' from https://github.com/github/hub." 1>&2
    41      echo "Please install this tool first." 1>&2
    42      exit 1
    43  fi
    44  
    45  echo -e "Sending PR for branch v$BRANCH:\n" 1>&2
    46  cat $SUMMARY 1>&2
    47  echo -e "\nSending pull request..." 2>&1
    48  PR_BRANCH=$(git rev-parse --abbrev-ref HEAD)
    49  git push origin "$PR_BRANCH"
    50  hub pull-request -b "v$BRANCH" -l kind/backports,backport/$BRANCH -F $SUMMARY
    51  
    52  prs=$(grep "contrib/backporting/set-labels.py" $SUMMARY | sed -e 's/^.*for pr in \([0-9 ]\+\);.*$/\1/g')
    53  echo -e "\nUpdating labels for PRs $prs\n" 2>&1
    54  echo -n "Set labels for all PRs above? [y/N] "
    55  read set_all_labels
    56  if [ "$set_all_labels" = "y" ]; then
    57      for pr in $prs; do
    58          $DIR/set-labels.py $pr pending $BRANCH;
    59      done
    60  fi