# Transforms a branch name in the form of "pr/<NUMBER>" or
# "mr/<NUMBER>" into a proper ref for GitHub or GitLab.
+
+# Transform a branch name to a ref.
+#
+# For GitHub the following formats are allowed:
+# - pr/123
+# - pull/123
+# - https://github.com/OISF/libhtp/pull/123
+# - OISF/libhtp#123
+#
+# For GibLab only the format "mr/123" is supported.
transform_branch() {
- pr=$(echo "${1}" | sed -n 's/^pr\/\([[:digit:]]\+\)$/\1/p')
+ pr=$(echo "${1}" | sed -n \
+ -e 's/^https:\/\/github.com\/OISF\/.*\/pull\/\([0-9]*\)$/\1/p' \
+ -e 's/^OISF\/.*#\([0-9]*\)$/\1/p' \
+ -e 's/^pull\/\([0-9]*\)$/\1/p' \
+ -e 's/^pr\/\([0-9]*\)$/\1/p')
if [ "${pr}" ]; then
- echo "refs/pull/${pr}/head"
- return
+ echo "refs/pull/${pr}/head"
+ return
fi
-
+
mr=$(echo "${1}" | sed -n 's/^mr\/\([[:digit:]]\+\)$/\1/p')
if [ "${mr}" ]; then
echo "refs/merge-requests/${mr}/head"