Skip to content

Commit f0f58ea

Browse files
committed
2
1 parent d8e1e5a commit f0f58ea

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

.github/workflows/codestate-pr-report.yml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ jobs:
4747
run: |
4848
set -e
4949
SHORT_SHA=$(git rev-parse --short "$GITHUB_SHA")
50+
COMMIT_TIME=$(git show -s --format=%cI "$GITHUB_SHA" || date -u +%Y-%m-%dT%H:%M:%SZ)
51+
COMMIT_MSG=$(git show -s --format=%s "$GITHUB_SHA" || echo "")
52+
# Truncate commit message for display (80 chars max)
53+
COMMIT_MSG_SHORT=$(printf '%s' "$COMMIT_MSG" | head -c 80)
54+
if [ ${#COMMIT_MSG} -gt 80 ]; then COMMIT_MSG_SHORT="$COMMIT_MSG_SHORT…"; fi
5055
OUTDIR="site"
5156
mkdir -p "$OUTDIR"
5257
# Bring over existing reports so we can publish with keep_files=false safely
@@ -71,6 +76,11 @@ jobs:
7176
if [ -f codestate_pr_report.json ]; then
7277
cp codestate_pr_report.json "$OUTDIR/$SUBPATH/codestate_pr_report.json"
7378
fi
79+
# Write metadata for this run
80+
COMMIT_MSG_ESC=$(printf '%s' "$COMMIT_MSG" | sed 's/"/\\"/g')
81+
cat > "$OUTDIR/$SUBPATH/metadata.json" << META
82+
{"pr_number":"$PR_NUMBER","short_sha":"$SHORT_SHA","sha":"$GITHUB_SHA","time":"$COMMIT_TIME","message":"$COMMIT_MSG_ESC"}
83+
META
7484
# Build history list from existing content in OUTDIR (copied + current)
7585
HISTORY_FILE_MD="$OUTDIR/history.md"
7686
echo "# CodeState Report History" > "$HISTORY_FILE_MD"
@@ -92,11 +102,29 @@ jobs:
92102
else
93103
label="Manual ($base)"
94104
fi
95-
echo "- [$label]($dir/)" >> "$HISTORY_FILE_MD"
105+
# Try to read metadata for time and full sha
106+
TIME=""; FULL_SHA=""; MSG="";
107+
if [ -f "$OUTDIR/$dir/metadata.json" ]; then
108+
TIME=$(sed -n 's/.*"time"[[:space:]]*:[[:space:]]*"\(.*\)".*/\1/p' "$OUTDIR/$dir/metadata.json" | head -n1)
109+
FULL_SHA=$(sed -n 's/.*"sha"[[:space:]]*:[[:space:]]*"\(.*\)".*/\1/p' "$OUTDIR/$dir/metadata.json" | head -n1)
110+
MSG=$(sed -n 's/.*"message"[[:space:]]*:[[:space:]]*"\(.*\)".*/\1/p' "$OUTDIR/$dir/metadata.json" | head -n1)
111+
fi
112+
short=${base#sha-}
113+
cmd="git checkout ${FULL_SHA:-$short}"
114+
# Truncate message for display
115+
MSG_SHORT=$(printf '%s' "$MSG" | head -c 80)
116+
if [ ${#MSG} -gt 80 ]; then MSG_SHORT="$MSG_SHORT…"; fi
117+
if [ -n "$TIME" ] && [ -n "$MSG_SHORT" ]; then
118+
echo "- [$label]($dir/) — $TIME — \`$cmd\` — $MSG_SHORT" >> "$HISTORY_FILE_MD"
119+
elif [ -n "$TIME" ]; then
120+
echo "- [$label]($dir/) — $TIME — \`$cmd\`" >> "$HISTORY_FILE_MD"
121+
else
122+
echo "- [$label]($dir/) — \`$cmd\`" >> "$HISTORY_FILE_MD"
123+
fi
96124
done <<< "$EXISTING_INDEXES"
97125
fi
98126
# Add current run at the top
99-
echo "- [Current Run]($SUBPATH/)" | cat - "$HISTORY_FILE_MD" > "$HISTORY_FILE_MD.tmp" && mv "$HISTORY_FILE_MD.tmp" "$HISTORY_FILE_MD"
127+
echo "- [Current Run]($SUBPATH/) — $COMMIT_TIME — \`git checkout $GITHUB_SHA\` — $COMMIT_MSG_SHORT" | cat - "$HISTORY_FILE_MD" > "$HISTORY_FILE_MD.tmp" && mv "$HISTORY_FILE_MD.tmp" "$HISTORY_FILE_MD"
100128

101129
# Build index.md from root README plus quick links
102130
INDEX_MD="$OUTDIR/index.md"

0 commit comments

Comments
 (0)