|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Script to show commits in develop that are not in master |
| 4 | +# with their associated PR info and commit hashes |
| 5 | +# |
| 6 | +# Usage: |
| 7 | +# ./show-unmerged-prs.sh # Show all unmerged commits |
| 8 | +# ./show-unmerged-prs.sh --bugfix # Show only bugfix-labeled PRs |
| 9 | + |
| 10 | +set -e |
| 11 | + |
| 12 | +REPO="firmware" |
| 13 | +OWNER="meshtastic" |
| 14 | +BASE_BRANCH="master" |
| 15 | +HEAD_BRANCH="develop" |
| 16 | +LIMIT=100 |
| 17 | +FILTER_LABEL="" |
| 18 | + |
| 19 | +# Parse arguments |
| 20 | +for arg in "$@"; do |
| 21 | + case $arg in |
| 22 | + --bugfix) |
| 23 | + FILTER_LABEL="bugfix" |
| 24 | + shift |
| 25 | + ;; |
| 26 | + --feature) |
| 27 | + FILTER_LABEL="feature" |
| 28 | + shift |
| 29 | + ;; |
| 30 | + --help) |
| 31 | + echo "Usage: $0 [OPTIONS]" |
| 32 | + echo "Options:" |
| 33 | + echo " --bugfix Show only PRs labeled with 'bugfix'" |
| 34 | + echo " --feature Show only PRs labeled with 'feature'" |
| 35 | + echo " --help Show this help message" |
| 36 | + exit 0 |
| 37 | + ;; |
| 38 | + esac |
| 39 | +done |
| 40 | + |
| 41 | +if [ -n "$FILTER_LABEL" ]; then |
| 42 | + echo "Fetching commits in $HEAD_BRANCH that are not in $BASE_BRANCH (filtered by label: $FILTER_LABEL)..." |
| 43 | +else |
| 44 | + echo "Fetching commits in $HEAD_BRANCH that are not in $BASE_BRANCH..." |
| 45 | +fi |
| 46 | +echo "" |
| 47 | + |
| 48 | +# Check if gh CLI is available |
| 49 | +if ! command -v gh &> /dev/null; then |
| 50 | + echo "ERROR: GitHub CLI (gh) not found. Please install it first." |
| 51 | + echo "Visit: https://cli.github.com/" |
| 52 | + exit 1 |
| 53 | +fi |
| 54 | + |
| 55 | +# Get commits in develop that are not in master |
| 56 | +# For each commit, try to find associated PR |
| 57 | +git fetch origin develop master 2>/dev/null || true |
| 58 | + |
| 59 | +# Use git to get the list of commits |
| 60 | +commits=$(git log --pretty=format:"%H|%s" origin/master..origin/develop | head -n $LIMIT) |
| 61 | + |
| 62 | +count=0 |
| 63 | +displayed=0 |
| 64 | +echo "Commits in $HEAD_BRANCH not in $BASE_BRANCH:" |
| 65 | +echo "==============================================" |
| 66 | +echo "" |
| 67 | + |
| 68 | +while IFS='|' read -r hash subject; do |
| 69 | + ((count++)) |
| 70 | + |
| 71 | + # Try to find the PR for this commit |
| 72 | + # Extract PR number, title, description, and labels |
| 73 | + pr_response=$(gh api -X GET "/repos/$OWNER/$REPO/commits/$hash/pulls" \ |
| 74 | + -H "Accept: application/vnd.github.v3+json" 2>/dev/null | \ |
| 75 | + jq -r '.[0] | "\(.number)|\(.title)|\(.body // "No description")|\(.labels | map(.name) | join(","))"' 2>/dev/null || echo "||||") |
| 76 | + |
| 77 | + if [ -z "$pr_response" ] || [ "$pr_response" = "||||" ]; then |
| 78 | + # If no PR found, skip if filter is active, otherwise show the commit |
| 79 | + if [ -z "$FILTER_LABEL" ]; then |
| 80 | + ((displayed++)) |
| 81 | + echo "[$displayed] Commit: $hash" |
| 82 | + echo " Subject: $subject" |
| 83 | + echo " PR: Not found in GitHub" |
| 84 | + echo "" |
| 85 | + fi |
| 86 | + else |
| 87 | + IFS='|' read -r pr_num pr_title pr_desc pr_labels <<< "$pr_response" |
| 88 | + |
| 89 | + # Check if filter matches |
| 90 | + if [ -n "$FILTER_LABEL" ]; then |
| 91 | + # Only show if the label is in the labels list |
| 92 | + if ! echo "$pr_labels" | grep -q "$FILTER_LABEL"; then |
| 93 | + continue |
| 94 | + fi |
| 95 | + fi |
| 96 | + |
| 97 | + ((displayed++)) |
| 98 | + echo "[$displayed] PR #$pr_num - $pr_title" |
| 99 | + echo " Commit: $hash" |
| 100 | + if [ -n "$pr_desc" ] && [ "$pr_desc" != "No description" ]; then |
| 101 | + # Truncate description to 200 chars |
| 102 | + desc_short="${pr_desc:0:200}" |
| 103 | + [ ${#pr_desc} -gt 200 ] && desc_short+="..." |
| 104 | + echo " Description: $desc_short" |
| 105 | + fi |
| 106 | + if [ -n "$pr_labels" ] && [ "$pr_labels" != "" ]; then |
| 107 | + echo " Labels: $pr_labels" |
| 108 | + fi |
| 109 | + echo "" |
| 110 | + fi |
| 111 | +done <<< "$commits" |
| 112 | + |
| 113 | +echo "" |
| 114 | +if [ -n "$FILTER_LABEL" ]; then |
| 115 | + echo "Done. Showing $displayed PRs with label '$FILTER_LABEL' from $displayed commits checked." |
| 116 | +else |
| 117 | + echo "Done. Showing $displayed commits from $HEAD_BRANCH not in $BASE_BRANCH." |
| 118 | +fi |
0 commit comments