Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 44 additions & 7 deletions scripts/tooling/hapi-pr-session-emoji.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,26 +124,57 @@ trim_ws() {
printf '%s' "$s"
}

strip_leading_emojis() {
local s="$1"
while true; do
case "$s" in
โœ…*) s="${s#โœ…}" ;;
๐Ÿ”*) s="${s#๐Ÿ”}" ;;
โš ๏ธ*) s="${s#โš ๏ธ}" ;;
๐Ÿ“*) s="${s#๐Ÿ“}" ;;
๐Ÿ”ง*) s="${s#๐Ÿ”ง}" ;;
*) break ;;
esac
s="$(trim_ws "$s")"
done
printf '%s' "$s"
}

normalize_title_base() {
local s="$1"
s="$(trim_ws "$s")"
while [[ "$s" == *" "* ]]; do
s="${s// / }"
done
printf '%s' "$s"
}

title_base_from() {
local name="$1" pr="$2" base marker
for marker in "PR #${pr}:" "pr#${pr}:" "PR #${pr} " "pr#${pr} " "Peer #${pr}:" "peer #${pr}:"; do
name="$(strip_leading_emojis "$name")"
for marker in "PR #${pr}:" "pr#${pr}:" "PR #${pr} " "pr#${pr} " \
"PR: ${pr}:" "PR: ${pr} " "PR:${pr}:" "PR:${pr} " \

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Strip hashed PR: titles before rebuilding

For malformed titles that include the hash, such as PR: #944: import picker, the new parser branch extracts 944, but this marker list only strips PR: 944/PR:944 without the #. Since those titles are selected by the sweep via the #[0-9] filter, they get renamed to โ€ฆPR #944: PR: #944: import picker instead of being repaired; include the hashed PR: #${pr} variants here.

Useful? React with ๐Ÿ‘ย / ๐Ÿ‘Ž.

"Peer #${pr}:" "peer #${pr}:"; do
if [[ "$name" == *"$marker"* ]]; then
base="${name##*"$marker"}"
base="$(trim_ws "$base")"
[[ "$base" == [Pp]eer[[:space:]#]*#"${pr}"*:* ]] && base="${base#*:}" && base="$(trim_ws "$base")"
base="$(normalize_title_base "$(trim_ws "$base")")"
[[ "$base" == [Pp]eer[[:space:]#]*#"${pr}"*:* ]] && base="${base#*:}" && base="$(normalize_title_base "$(trim_ws "$base")")"
printf '%s' "$base"
return
fi
done
trim_ws "$name"
normalize_title_base "$(trim_ws "$name")"
}

title_base_multi_from() {
local name="$1" p1="$2" p2="$3" base marker
for marker in "PR #${p1}/#${p2}:" "pr#${p1}/${p2}:" "PR #${p1}/#${p2} " "pr#${p1}/${p2} "; do
name="$(strip_leading_emojis "$name")"
for marker in "PR #${p1}/#${p2}:" "pr#${p1}/${p2}:" "PR #${p1}/#${p2} " "pr#${p1}/${p2} " \
"PR #${p1} #${p2}:" "pr#${p1} #${p2}:" \
"PR #${p1}: #${p2}:" "pr#${p1}: #${p2}:"; do
Comment on lines +172 to +174

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Strip both PRs from space-separated titles

For newly parsed space-separated titles like PR #944 945: import picker, extract_pr_numbers returns both numbers, but this marker list only removes variants where the second number has a #. The multi-PR rename therefore becomes โ€ฆPR #944/#945: 945: import picker, leaving a stray second PR in the base and continuing to corrupt the session title on sweep; add the no-# variant here to match the parser.

Useful? React with ๐Ÿ‘ย / ๐Ÿ‘Ž.

if [[ "$name" == *"$marker"* ]]; then
base="${name##*"$marker"}"
trim_ws "$base"
normalize_title_base "$(trim_ws "$base")"
return
fi
done
Expand All @@ -153,14 +184,20 @@ title_base_multi_from() {
extract_pr_numbers() {
local name="$1"
local re_multi re_peer
re_multi='[Pp][Rr][#: ]*#?([0-9]{3,4})/([0-9]{3,4})'
re_multi='[Pp][Rr][[:space:]]*#([0-9]{3,4})/#([0-9]{3,4})'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep slash parsing for PR #N/N titles

For existing session titles using the previously supported slash form PR #944/945: ..., this regex no longer matches because it now requires a # before the second PR. The sweep then falls through to the single-PR grep and classifies only #944, so the rename/ping state drops #945 from tracking; this regresses titles the old [#: ]*#?N/N pattern parsed.

Useful? React with ๐Ÿ‘ย / ๐Ÿ‘Ž.

re_peer='[Pp]eer[[:space:]#:]*#?([0-9]{3,4})'
if [[ "$name" =~ [Pp][Rr][[:space:]]*#?([0-9]{3,4}):[[:space:]]*#?([0-9]{3,4}) ]]; then
echo "${BASH_REMATCH[1]}"; echo "${BASH_REMATCH[2]}"; return
fi
if [[ "$name" =~ [Pp][Rr][[:space:]]*#?([0-9]{3,4})[[:space:]]+#?([0-9]{3,4}): ]]; then
echo "${BASH_REMATCH[1]}"; echo "${BASH_REMATCH[2]}"; return
fi
if [[ "$name" =~ $re_multi ]]; then
echo "${BASH_REMATCH[1]}"; echo "${BASH_REMATCH[2]}"; return
fi
if [[ "$name" =~ [Pp][Rr]:[[:space:]]*#?([0-9]{3,4}) ]]; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include PR: N titles in sweep selection

For malformed no-hash titles like PR: 944: foo, this new parser branch is never reached in the normal --sweep path because the session list is pre-filtered by test("Peer #[0-9]|PR #|pr#|#[0-9]{3,4}"), which does not match PR: 944. As a result the advertised PR: N recovery only works outside the sweep flow; add the PR: form to the jq selector so these sessions are actually processed.

Useful? React with ๐Ÿ‘ย / ๐Ÿ‘Ž.

echo "${BASH_REMATCH[1]}"; return
fi
local first
first="$(printf '%s' "$name" | grep -oiE '[Pp][Rr][[:space:]]*#?[0-9]{3,4}' | head -1 | grep -oE '[0-9]{3,4}' || true)"
[[ -n "$first" ]] && { echo "$first"; return; }
Expand Down
Loading