Skip to content

Commit 3f03d19

Browse files
committed
fix: improve latest commit detection via timestamp sorting in Phase 2 bot
Signed-off-by: Akshat Kumar <akshat230405@gmail.com>
1 parent 2261c14 commit 3f03d19

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

.github/scripts/dry_run_inactivity_unassign_phase2.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,14 @@ for ISSUE in $ISSUES; do
9393
continue
9494
fi
9595

96-
LAST_COMMIT_DATE=$(gh api "repos/$REPO/pulls/$PR_NUM/commits" \
97-
--jq '.[-1].commit.committer.date // .[-1].commit.author.date' 2>/dev/null || echo "")
96+
# Use the same "max by timestamp" logic as the real bot
97+
COMMITS_JSON=$(gh api "repos/$REPO/pulls/$PR_NUM/commits" 2>/dev/null || echo "")
9898

99-
if [ -z "$LAST_COMMIT_DATE" ]; then
99+
LAST_COMMIT_DATE=$(echo "$COMMITS_JSON" \
100+
| jq -r 'max_by(.commit.committer.date // .commit.author.date)
101+
| (.commit.committer.date // .commit.author.date)' 2>/dev/null || echo "")
102+
103+
if [ -z "$LAST_COMMIT_DATE" ] || [ "$LAST_COMMIT_DATE" = "null" ]; then
100104
echo " [WARN] Could not determine last commit date for PR #$PR_NUM, skipping."
101105
continue
102106
fi

.github/scripts/inactivity_unassign_phase2.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,17 @@ for ISSUE in $ISSUES; do
9494
continue
9595
fi
9696

97-
# Last commit date on the PR
98-
LAST_COMMIT_DATE=$(gh api "repos/$REPO/pulls/$PR_NUM/commits" \
99-
--jq '.[-1].commit.committer.date // .[-1].commit.author.date' 2>/dev/null || echo "")
97+
# Last commit date on the PR: pick the truly latest by timestamp
98+
COMMITS_JSON=$(gh api "repos/$REPO/pulls/$PR_NUM/commits" --paginate 2>/dev/null || echo "[]")
10099

101-
if [ -z "$LAST_COMMIT_DATE" ]; then
100+
LAST_COMMIT_DATE=$(echo "$COMMITS_JSON" \
101+
| jq -r '
102+
select(length > 0)
103+
| max_by(.commit.committer.date // .commit.author.date)
104+
| (.commit.committer.date // .commit.author.date)
105+
')
106+
107+
if [ -z "$LAST_COMMIT_DATE" ] || [ "$LAST_COMMIT_DATE" = "null" ]; then
102108
echo " [WARN] Could not determine last commit date for PR #$PR_NUM, skipping."
103109
continue
104110
fi

0 commit comments

Comments
 (0)