Last active
August 29, 2015 13:56
-
-
Save nacin/9211945 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# In order for this to work, you needed to have committed to | |
# https://plugins.svn.wordpress.org and have this in your Mac OS X keychain. | |
# In lieu of a ticket number, it also accepts the format "12345.3.diff" | |
# which will replace a previous diff of that name. | |
# Edit this | |
SVN_USER='nacin' | |
# Stop editing | |
# Thanks Mike Adams. | |
if [[ -p /dev/stdin || ! -t 0 ]] | |
then # We're in a pipe or a redirect, store stdin | |
TICKET_ATTACHMENT=`mktemp -t trac.att.XXXXXXXXXX` | |
if [[ ! $TICKET_ATTACHMENT ]] | |
then | |
echo "Could not create temp file" >&2 | |
exit 1 | |
fi | |
TICKET_ATTACHMENT=$(cat | base64) | |
elif # no attachment | |
TICKET_ATTACHMENT=$(/usr/bin/env svn diff | base64) | |
fi | |
TICKET_ID=${1?Usage: $0 TICKET_ID [DESCRIPTION] [TRAC_SUBDOMAIN]} | |
if [[ $TICKET_ID == *".diff" ]] | |
then | |
ATTACHMENT_NAME=$TICKET_ID | |
TICKET_ID=$( echo "$TICKET_ID" | cut -d'.' -f 1 ) | |
OVERRIDE=1 | |
else | |
ATTACHMENT_NAME="$TICKET_ID.diff" | |
OVERRIDE=0 | |
fi | |
TRAC_SUBDOMAIN=${3:-core} | |
if [ "$TRAC_SUBDOMAIN" != "core" ]; then | |
ATTACHMENT_NAME="$TRAC_SUBDOMAIN.$ATTACHMENT_NAME" | |
fi | |
DESCRIPTION=${2:-} | |
SVN_PASS=$(security find-generic-password -g -l "<https://plugins.svn.wordpress.org:443> Use your WordPress.org login" 2>&1 | grep password: | sed -e 's/password: "//' -e 's/"$//') | |
TMP_FILE=$(mktemp -t trac.att.XXXXXXXXXX) | |
echo "<?xml version=\"1.0\"?> | |
<methodCall> | |
<methodName>ticket.putAttachment</methodName> | |
<params> | |
<param><int>${TICKET_ID}</int></param> | |
<param><string>${ATTACHMENT_NAME}</string></param> | |
<param><string>${DESCRIPTION}</string></param> | |
<param><base64>${TICKET_ATTACHMENT}</base64></param> | |
<param><boolean>${OVERRIDE}</boolean></param> | |
</params> | |
</methodCall>" > "$TMP_FILE" | |
RESULT=$(curl -u "${SVN_USER}:${SVN_PASS}" -s -H "Content-Type: application/xml" --data "@${TMP_FILE}" "https://${TRAC_SUBDOMAIN}.trac.wordpress.org/login/xmlrpc") | |
ATTACHED=$(echo "$RESULT" | grep "${TICKET_ID}" | sed -e 's/<value><string>//' -e 's/<\/string><\/value>//') | |
if [[ $ATTACHED ]] | |
then | |
echo "http://${TRAC_SUBDOMAIN}.trac.wordpress.org/attachment/ticket/${TICKET_ID}/${ATTACHED}" | |
else | |
echo $RESULT >&2 | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment