Last active
March 21, 2022 09:30
-
-
Save andreas-kkday/081e2ce73aa70066ea0650f58129132c to your computer and use it in GitHub Desktop.
check PR branch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1. 裝 github cli | |
| https://cli.github.com/ | |
| 然後登入, auth ... | |
| 2. 把兩個 script 放在 ~/bin/, 設定 PATH=$PATH:/Users/kkday/bin/ | |
| 3. .zshrc 設定 alias | |
| ``` | |
| alias checkPr="pr-branch-fix.sh || check-pr.py" | |
| alias checkAllPr="pr-branch-fix.sh || check-pr.py all" | |
| ``` | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import subprocess | |
| import json | |
| import sys | |
| class bcolors: | |
| HEADER = '\033[95m' | |
| OKBLUE = '\033[94m' | |
| OKCYAN = '\033[96m' | |
| OKGREEN = '\033[92m' | |
| WARNING = '\033[93m' | |
| FAIL = '\033[91m' | |
| ENDC = '\033[0m' | |
| BOLD = '\033[1m' | |
| UNDERLINE = '\033[4m' | |
| def checkPr(prNumber): | |
| # gh pr view $PRID --json number,title,baseRefName,labels | |
| proc = subprocess.run( | |
| ['gh', 'pr', 'view', prNumber, "--json", "author,number,title,baseRefName,labels,state,reviewDecision"], | |
| stdout=subprocess.PIPE) | |
| # print(proc.stdout.decode('utf-8')) | |
| jsonObj = json.loads(proc.stdout.decode('utf-8')) | |
| checkWarn(jsonObj) | |
| def checkWarn(jsonObj): | |
| baseRef = jsonObj["baseRefName"] | |
| revDecision = jsonObj["reviewDecision"] | |
| title = jsonObj["title"] | |
| number = jsonObj["number"] | |
| colorWarn = bcolors.FAIL | |
| colorCyan = bcolors.OKCYAN | |
| colorBlue = bcolors.OKBLUE | |
| colorEnd = bcolors.ENDC | |
| colorOk = bcolors.OKGREEN | |
| author = jsonObj["author"] | |
| #如果是 merge 到 develop 又已經被 approved 了, 就要小心 | |
| if baseRef == "develop" and revDecision == "APPROVED": | |
| labels = ",".join(map(lambda l: l["name"], jsonObj["labels"])) | |
| print(f"{colorWarn} {author} {number} {colorEnd} {title} is {revDecision} but to be merge to {baseRef}, label {colorCyan}{labels} {colorEnd}") | |
| else: | |
| labels = ",".join(map(lambda l: l["name"], jsonObj["labels"])) | |
| #print(f"{colorOk} {number} {colorBlue}{title}{colorOk} is {revDecision}, merge to {colorBlue}{baseRef}{colorOk}, label {colorCyan}{labels} {colorEnd}") | |
| def checkAll(proc): | |
| for l in proc.stdout.decode('utf-8').splitlines(): | |
| checkPr(l.split()[0]) | |
| #一個一個撈 PR 的 detail | |
| def main(): | |
| if len(sys.argv) < 2: | |
| proc = subprocess.run(['gh', 'pr', 'list', '--author', '"@me"'], stdout=subprocess.PIPE) | |
| #列出所有我的 PR | |
| else: | |
| proc = subprocess.run(['gh', 'pr', 'list', '--search', 'review:approved'], stdout=subprocess.PIPE) | |
| #列出所有 approved 的 PR | |
| checkAll(proc) | |
| if __name__ == '__main__': | |
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/zsh | |
| git fetch | |
| echo -n "Latest release branch " | |
| release=`git branch -a|grep remotes/origin/release|wc -l` | |
| if [ $release -eq 0 ]; | |
| then | |
| echo "" | |
| echo "No release branch" | |
| exit 0 | |
| fi | |
| branch=`git branch -a|grep remotes/origin/release |sort -V|awk -F "/" '{print $4}'|tail -n 1` | |
| echo $branch | |
| #如果 release branch 已經 merge 了, 就不用檢查 | |
| git branch --merged develop|grep $branch | |
| if [ $? -eq 0 ]; | |
| then | |
| echo $branch "already merged to develop" | |
| exit 0 | |
| fi | |
| exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment