Created
August 24, 2012 18:52
-
-
Save kdwolski/3454250 to your computer and use it in GitHub Desktop.
Add issues in Jira RSS feed to todo.txt file
This file contains 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
#!/usr/bin/php -q | |
<?php | |
/** | |
* A simple PHP Cli script to append items from a | |
* Jira RSS feed to a todo.txt file. | |
* | |
* I use this to access my work Jira issue list and update | |
* my todo.txt which syncs via Dropbox to todo.txt Android app. | |
* | |
* @author Kevin D. Wolski | |
* | |
*/ | |
$url = ""; // Jira (or other protected) Feed URL | |
$username = ""; // Username | |
$password = ""; // Password | |
$todoPath = ""; // Local path to todo.txt file (e.g. Dropbox) | |
$project = "+"; // Add + before project string | |
$updateCount = 0; | |
echo "1. Attempting to access feed. \n"; | |
$ch = curl_init(); | |
curl_setopt( $ch, CURLOPT_URL, $url ); | |
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); | |
curl_setopt( $ch, CURLOPT_USERPWD, "$username:$password" ); | |
curl_setopt( $ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ); | |
$output = curl_exec( $ch ); | |
$info = curl_getinfo( $ch ); | |
curl_close( $ch ); | |
if ( $output ) { | |
echo "2. Found feed. Looking for new items... \n"; | |
$rss = simplexml_load_string( $output ); | |
$file = file_get_contents( $todoPath ); | |
if ( $rss ) { | |
$items = $rss->channel->item; | |
//Open todo.txt and append new items. | |
foreach ( $items as $item ) { | |
// Replace URL prefix to Jira GUID node (Add your URL path in the first "") | |
$id = str_replace( "", "", $item->link ); | |
$title = $item->title; | |
if ( !strpos( $file, $id ) ) { | |
$fh = fopen( $todoPath, 'a' ) or die( "\n *** CAN'T OPEN FILE ***" ); | |
$stringData = $title . " " . $project; | |
fwrite( $fh, "\n" . $stringData ); | |
fclose( $fh ); | |
$updateCount++; | |
echo "\t" . $updateCount . ". Added: " . $stringData . " \n"; | |
} | |
} | |
if ( $updateCount == 0 ) { | |
echo "3. No new items to add. \n"; | |
} | |
} else { | |
echo "*** ERROR PARSING FEED! *** \n"; | |
} | |
} else { | |
echo "*** ERROR ACCESSING FEED! *** \n"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment