-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_lib.sh
More file actions
executable file
·28 lines (27 loc) · 951 Bytes
/
Copy path_lib.sh
File metadata and controls
executable file
·28 lines (27 loc) · 951 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env bash
# SPDX-License-Identifier: PMPL-1.0-or-later
# _lib.sh — Shared helpers for classify-*.sh scripts.
#
# Sourced by every classifier. Not directly executable.
#
# Provides: normalize_input <file>
#
# Emits one TSV row per workflow file: "<repo>\t<path>\t<sha>".
# Accepts two input shapes auto-detected from the first line:
#
# 1. JSONL from `gh api /search/code` (legacy):
# {"repo":"foo","sha":"abc123"}
# Emitted path is empty (no nested-copy info available).
#
# 2. TSV from `list-workflow-paths.sh` (preferred — handles nested):
# foo<TAB><path><TAB>abc123<TAB>top-level|nested
# Emitted path is the original `<path>` value; the scope column
# is dropped.
normalize_input() {
local file="$1"
if [[ "$(head -c1 "$file")" == "{" ]]; then
jq -r '[.repo, (.path // ""), .sha] | @tsv' "$file"
else
awk -F'\t' 'NF >= 3 { print $1 "\t" $2 "\t" $3 }' "$file"
fi
}