Skip to content

Instantly share code, notes, and snippets.

@LSTANCZYK
Forked from kdwolski/jira_todo.php
Last active August 29, 2015 14:06
Show Gist options
  • Save LSTANCZYK/b5c59ea7564c8b9ed200 to your computer and use it in GitHub Desktop.
Save LSTANCZYK/b5c59ea7564c8b9ed200 to your computer and use it in GitHub Desktop.
#!/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