diff --git a/contrib/source-control-tools/land-patch.sh b/contrib/source-control-tools/land-patch.sh --- a/contrib/source-control-tools/land-patch.sh +++ b/contrib/source-control-tools/land-patch.sh @@ -98,6 +98,39 @@ fi fi +# Temporarily stop verbose logging to prevent leaking CONDUIT_TOKEN +set +x +# Fetch user name and email +WHOAMI_RESULT=$(curl "https://reviews.bitcoinabc.org/api/user.whoami" \ + -d "api.token=${CONDUIT_TOKEN}") || { + echo "Error: Failed to fetch user info of committer." + echo "curl output:" + echo "${WHOAMI_RESULT}" + exit 30 +} +set -x + +ERROR_INFO=$(echo "${WHOAMI_RESULT}" | jq '.error_info') +if [ "${ERROR_INFO}" != "null" ]; then + echo "Conduit error while fetching 'whoami' of committer: ${ERROR_INFO}" + exit 31 +fi + +# Set git username and email so that committer information is preserved. +GIT_COMMITTER_NAME=$(echo "${WHOAMI_RESULT}" | jq '.result.realName') || { + echo "Error: Failed to fetch committer name" + echo "The 'realName' field may be missing or malformed." + exit 32 +} +export GIT_COMMITTER_NAME + +GIT_COMMITTER_EMAIL=$(echo "${WHOAMI_RESULT}" | jq '.result.primaryEmail') || { + echo "Error: Failed to fetch committer name" + echo "The 'primaryEmail' field may be missing or malformed." + exit 32 +} +export GIT_COMMITTER_EMAIL + # IMPORTANT NOTE: The patch is trusted past this point. It was either reviewed # and accepted or it was auto-generated. @@ -118,7 +151,7 @@ else # TODO: This will primarily be for scheduled, automated commits. echo "Error: Landing unreviewed patches is not supported yet." - exit 30 + exit 80 fi # TODO: Autogen (such as manpages, updating timings.json, copyright header, etc.) @@ -136,7 +169,7 @@ else # TODO: Push a git commit directly. This will primarily be for scheduled, automated commits. echo "Error: Pushing unreviewed patches is not supported yet." - exit 31 + exit 81 fi # This MUST be the last line to ensure no changes to this script on-disk can affect the execution