Skip to content

Commit ab326c8

Browse files
committed
deepscan update
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
1 parent 7fe42ac commit ab326c8

1 file changed

Lines changed: 78 additions & 36 deletions

File tree

ci/scripts/depscan.sh

Lines changed: 78 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if ! gh auth status &> /dev/null; then
1919
exit 1
2020
fi
2121

22-
# Determine 3 years ago in seconds (handles both Linux/GNU and BSD/macOS date versions)
22+
# Determine 3 years ago in seconds
2323
if date --version &>/dev/null; then
2424
THRESHOLD=$(date -d "3 years ago" +%s)
2525
IS_GNU_DATE=true
@@ -28,8 +28,47 @@ else
2828
IS_GNU_DATE=false
2929
fi
3030

31+
# Reusable function to check a GitHub repo's status
32+
# Returns a string in the format "status|pushed_at"
33+
function get_repo_status() {
34+
local REPO=$1
35+
local RESPONSE=$(gh api "repos/$REPO" 2>/dev/null)
36+
37+
if [ $? -ne 0 ]; then
38+
echo "unknown|"
39+
return
40+
fi
41+
42+
local ARCHIVED=$(echo "$RESPONSE" | jq -r '.archived')
43+
local PUSHED_AT=$(echo "$RESPONSE" | jq -r '.pushed_at')
44+
45+
if [ "$PUSHED_AT" = "null" ] || [ -z "$PUSHED_AT" ]; then
46+
echo "unknown|"
47+
return
48+
fi
49+
50+
local LAST_COMMIT_SEC
51+
if $IS_GNU_DATE; then
52+
LAST_COMMIT_SEC=$(date -d "$PUSHED_AT" +%s)
53+
else
54+
LAST_COMMIT_SEC=$(date -j -f "%Y-%m-%dT%H:%M:%SZ" "$PUSHED_AT" +%s)
55+
fi
56+
57+
local STATUS="fine"
58+
if [ "$ARCHIVED" = "true" ]; then
59+
STATUS="archived"
60+
elif [ "$LAST_COMMIT_SEC" -lt "$THRESHOLD" ]; then
61+
STATUS="stale"
62+
fi
63+
64+
echo "$STATUS|$PUSHED_AT"
65+
}
66+
3167
echo "Fetching all direct and indirect dependencies..."
3268

69+
# Get the main module name to identify direct dependencies
70+
MAIN_MODULE=$(go list -m)
71+
3372
# Extract unique GitHub modules exactly as they are known to Go
3473
MODULES=$(go list -m all | awk '{print $1}' | grep '^github\.com/' | sort -u)
3574

@@ -45,56 +84,59 @@ for MODULE in $MODULES; do
4584
continue
4685
fi
4786

48-
# 2. Extract the base GitHub repo (owner/name) from the module path
87+
# 2. Extract the base GitHub repo (owner/name) and check its status
4988
REPO=$(echo "$MODULE" | sed -E 's|^github\.com/([^/]+)/([^/]+).*|\1/\2|')
89+
RESULT=$(get_repo_status "$REPO")
5090

51-
# 3. Fetch repository metadata using gh api
52-
RESPONSE=$(gh api "repos/$REPO" 2>/dev/null)
53-
54-
if [ $? -ne 0 ]; then
55-
continue
56-
fi
91+
STATUS="${RESULT%%|*}"
92+
PUSHED_AT="${RESULT##*|}"
5793

58-
# 4. Extract archived status and last push date
59-
ARCHIVED=$(echo "$RESPONSE" | jq -r '.archived')
60-
PUSHED_AT=$(echo "$RESPONSE" | jq -r '.pushed_at')
61-
62-
if [ "$PUSHED_AT" = "null" ] || [ -z "$PUSHED_AT" ]; then
63-
continue
64-
fi
65-
66-
# 5. Convert pushed_at string to seconds
67-
if $IS_GNU_DATE; then
68-
LAST_COMMIT_SEC=$(date -d "$PUSHED_AT" +%s)
69-
else
70-
LAST_COMMIT_SEC=$(date -j -f "%Y-%m-%dT%H:%M:%SZ" "$PUSHED_AT" +%s)
71-
fi
72-
73-
# 6. Evaluate if the repository is stale
74-
IS_STALE=false
75-
if [ "$LAST_COMMIT_SEC" -lt "$THRESHOLD" ]; then
76-
IS_STALE=true
77-
fi
78-
79-
# 7. Print the report if it matches the criteria
80-
if [ "$ARCHIVED" = "true" ] || [ "$IS_STALE" = "true" ]; then
94+
# 3. Process if the repository is stale or archived
95+
if [ "$STATUS" = "archived" ] || [ "$STATUS" = "stale" ]; then
8196
FORMATTED_DATE=$(echo "$PUSHED_AT" | cut -d'T' -f1)
8297

8398
REASONS=()
84-
if [ "$ARCHIVED" = "true" ]; then
99+
if [ "$STATUS" = "archived" ]; then
85100
REASONS+=("Archived")
86101
fi
87-
if [ "$IS_STALE" = "true" ]; then
102+
if [ "$STATUS" = "stale" ]; then
88103
REASONS+=("Inactive > 3 years")
89104
fi
90-
91105
REASON_STR=$(IFS=", "; echo "${REASONS[*]}")
106+
107+
# 4. Check the immediate parent module in the dependency chain
108+
# Strip comments/empty lines, get the second to last line (the parent)
109+
PARENT_MOD=$(echo "$WHY_OUTPUT" | grep -v '^#' | sed '/^$/d' | tail -n 2 | head -n 1)
110+
PARENT_MSG=""
111+
112+
if [ -n "$PARENT_MOD" ] && [ "$PARENT_MOD" != "$MODULE" ]; then
113+
if [ "$PARENT_MOD" = "$MAIN_MODULE" ]; then
114+
PARENT_MSG="Notice: This is a direct dependency. You may want to replace it."
115+
elif [[ "$PARENT_MOD" == github.com/* ]]; then
116+
# Get the parent's base repository
117+
PARENT_REPO=$(echo "$PARENT_MOD" | sed -E 's|^github\.com/([^/]+)/([^/]+).*|\1/\2|')
118+
119+
# Check the parent's status
120+
PARENT_RESULT=$(get_repo_status "$PARENT_REPO")
121+
PARENT_STATUS="${PARENT_RESULT%%|*}"
122+
123+
if [ "$PARENT_STATUS" = "fine" ]; then
124+
PARENT_MSG="Notice: Brought in by '$PARENT_MOD' which is active. This dependency is still fine."
125+
fi
126+
fi
127+
fi
128+
129+
# 5. Print the formatted report
92130
echo "[!] $MODULE"
93131
echo " Status: $REASON_STR"
94132
echo " Last updated: $FORMATTED_DATE"
95-
echo " Dependency chain (go mod why):"
96133

97-
# Reuse the previously captured WHY_OUTPUT and indent it
134+
# Output the parent notice if it exists
135+
if [ -n "$PARENT_MSG" ]; then
136+
echo " $PARENT_MSG"
137+
fi
138+
139+
echo " Dependency chain (go mod why):"
98140
echo "$WHY_OUTPUT" | sed 's/^/ /'
99141
echo ""
100142
fi

0 commit comments

Comments
 (0)