sh merge-dependabot-pr.sh

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh merge-dependabot-pr.sh相关的知识,希望对你有一定的参考价值。

#!/bin/bash

# This script creates a consolidate Pull Request for all outstanding dependabot 
# Pull Requests.
# 
# Motivation: Sometimes, dependabot opens a large number of PRs that all need to 
# be merged. Each time one merges, it causes the rest to be out of date, making 
# it a slow, manual process of clicking upate, waiting for ci, then clicking 
# merge for each subsequent PR. 
# 
# Usage: 
#
# ```bash
# cd MY_GIT_REPO
# merge-dependabot-prs.sh
# ```
# 
# TODO: Only merge PRs with a successful CI status
# 
# Maintainer: [Ian Remmel](https://github.com/ianwremmel)
#
# Contribution: This gist will be updated based on feedback in the comments, as 
# appropriate
#
# License: MIT
# 
# Copyright: Ian Remmel © 2018 until at least now
#

set -euo pipefail

if ! command -v hub >/dev/null 2>&1; then
  echo 
  echo "This script requires hub"
  echo "https://hub.github.com/"
  echo 
  exit 1
fi

if ! command -v http >/dev/null 2>&1; then
  echo 
  echo "This script requires httpie"
  echo "https://httpie.org/"
  echo 
  exit 1
fi

if ! command -v jq >/dev/null 2>&1; then
  echo 
  echo "This script requires jq"
  echo "https://stedolan.github.io/jq/"
  echo 
  exit 1
fi

echo "Making sure master is update to date with origin/master"
git checkout master
git pull --rebase

echo "Checking out new branch"
git checkout -b "merges-$(date +%s)"

echo "Retrieving dependabot branches from GitHub and merging into current branch"
http "$(git remote -v | awk -F"[ :/.]" '/origin.*fetch/{print "https://api.github.com/repos/" $3 "/" $4 "/issues"}')" labels==dependencies | jq .[].html_url | xargs -n 1 hub merge 

echo "Pushing current branch to origin"
git push -u origin "$(git branch | awk '/\* /{print $2}')"

echo "Opening Pull Request"
hub pull-request -m 'Consolidated dependabot merges' 

以上是关于sh merge-dependabot-pr.sh的主要内容,如果未能解决你的问题,请参考以下文章

如何使我的命令行在具有扩展名(.sh)和名称如“weird.sh.sh.sh”的文件上工作

sh sh_template.sh

sh sh.sh

Linux下面如何运行 SH文件

配置告警系统主脚本main.sh mon.sh load.sh 502.sh disk.sh

shell 脚本各种执行方式(source ./*.sh, . ./*.sh, ./*.sh)的区别