squash-only 1.0.4 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # squash-only
2
2
 
3
- A bash script to automatically configure all your GitHub repositories to use squash-only merge strategy.
3
+ A hybrid Node.js/bash script to automatically configure all your GitHub repositories to use squash-only merge strategy.
4
4
 
5
5
  ## Quick start
6
6
 
@@ -19,13 +19,15 @@ It automatically skips repositories you don't own and provides a summary of the
19
19
 
20
20
  ## Requirements
21
21
 
22
- - `bash` (version 4+)
22
+ - `bash` (version 3+; 4+ recommended)
23
23
  - `curl`
24
24
  - `jq`
25
25
  - GitHub authentication (see below)
26
26
 
27
27
  **Note:** If using the Node.js binary wrapper, you'll also need Node.js installed.
28
28
 
29
+ **macOS note:** Some macOS installations default to bash 3.2. The script should still work, but if you hit shell-related issues, try running with bash 4+.
30
+
29
31
  ## Authentication
30
32
 
31
33
  The script supports three methods for GitHub authentication (in order of preference):
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "squash-only",
3
- "version": "1.0.4",
3
+ "version": "2.0.0",
4
4
  "description": "Scripts for making all your repos on GitHub Squash Only!",
5
5
  "bin": {
6
6
  "squash-only": "./bin/squash-only.js"
@@ -17,14 +17,33 @@ trap cleanup EXIT
17
17
 
18
18
  # Handle termination signals
19
19
  handle_exit() {
20
+ if [ "$SHOULD_EXIT" -eq 1 ]; then
21
+ # Second Ctrl-C: bail immediately.
22
+ exit 130
23
+ fi
24
+
20
25
  SHOULD_EXIT=1
21
26
  echo ""
22
- echo "⚠️ Interrupted. Cleaning up..."
23
- cleanup
24
- exit 130
27
+ echo "⚠️ Interrupted. Finishing current step then stopping..."
25
28
  }
26
29
  trap handle_exit INT TERM
27
30
 
31
+ require_cmd() {
32
+ local cmd=$1
33
+ if ! command -v "$cmd" &> /dev/null; then
34
+ echo "❌ Error: Required command not found: $cmd"
35
+ return 1
36
+ fi
37
+ }
38
+
39
+ warn_if_old_bash() {
40
+ # Some platforms (notably older macOS installs) default to bash 3.2.
41
+ # This script should still work on bash 3+, but warn to reduce surprises.
42
+ if [ "${BASH_VERSINFO[0]:-0}" -lt 4 ]; then
43
+ echo "⚠️ Warning: detected bash < 4 (${BASH_VERSION:-unknown}). If you hit issues, run with bash 4+."
44
+ fi
45
+ }
46
+
28
47
  get_github_token() {
29
48
  # Check if GITHUB_TOKEN is already in environment
30
49
  if [ -n "${GITHUB_TOKEN:-}" ]; then
@@ -106,7 +125,7 @@ process_repo() {
106
125
  -X PATCH \
107
126
  -H "Authorization: token $GITHUB_TOKEN" \
108
127
  -H "Accept: application/vnd.github+json" \
109
- https://api.github.com/repos/$repo \
128
+ "https://api.github.com/repos/$repo" \
110
129
  -d '{
111
130
  "allow_merge_commit": false,
112
131
  "allow_rebase_merge": false,
@@ -153,10 +172,12 @@ fetch_all_repos() {
153
172
  break
154
173
  fi
155
174
 
156
- echo "$body" | jq -r '.[] | "\(.full_name)|\(.owner.login)"' | while IFS='|' read -r repo owner; do
175
+ # NOTE: Avoid a pipeline into `while` here; that runs the loop in a subshell and
176
+ # breaks exit/interrupt handling and control flow.
177
+ while IFS='|' read -r repo owner; do
157
178
  [ "$SHOULD_EXIT" -eq 1 ] && break
158
179
  process_repo "$repo" "$owner" || break
159
- done
180
+ done < <(echo "$body" | jq -r '.[] | "\(.full_name)|\(.owner.login)"')
160
181
 
161
182
  [ "$SHOULD_EXIT" -eq 1 ] && break
162
183
 
@@ -201,6 +222,10 @@ parse_args() {
201
222
  }
202
223
 
203
224
  main() {
225
+ warn_if_old_bash
226
+ require_cmd curl || exit 1
227
+ require_cmd jq || exit 1
228
+
204
229
  parse_args "$@"
205
230
 
206
231
  # Initialize counters
@@ -256,6 +281,10 @@ main() {
256
281
  else
257
282
  echo " ⏱️ Elapsed time: ${ELAPSED}s"
258
283
  fi
284
+
285
+ if [ "$SHOULD_EXIT" -eq 1 ]; then
286
+ exit 130
287
+ fi
259
288
  }
260
289
 
261
290
  main "$@"