-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdatetracker.php
More file actions
executable file
·171 lines (147 loc) · 5.59 KB
/
updatetracker.php
File metadata and controls
executable file
·171 lines (147 loc) · 5.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
/**
* Created with pain sweat, and tears.
* User: chris
* Date: 8/29/13
* Updated: 9/7/13 - Chris Shea "Adding comments"
*
* DISCLAIMER:
* Don't blame me. Don't complain, contribute! If you feel like any of this could be better please fork, and submit
* a pull request.
*
*
* CONTENTS:
* This file takes a command line user through the process of:
* 1. Establishing a connection with Pivotal Tracker
* 2. Determining the project we are contributing too
* 3. Deciding which story or add a new one
* 4. Walk the user through adding all of the needed details to create a story.
* 5. If they are adding a bug allow them to upload all of the log files that are found.
*
*
* NEXT STEPS:
* Feature Requests:
* 1. Create a function for logify
* 2. Add ability to attach files
* 3. Add ability to add tasks
*
* Bugs:
*
*/
?>
<?php
// Load the classes
// Loads the basic class to communicate with Pivotal Tracker
require ('pivotaltracker.php');
// Loads some tasks that fall outside of specifically communicating with Tracker
require ('helpers.php');
$pivotaltracker = new pivotaltracker;
$helpers = new pivotalTrackerHelpers;
/**
*
* WELCOME
*
*/
// Let's set the stage, and hope that the user is paying attention to the output on the screen.
echo "\nUPDATING PIVOTAL TRACKER\n"
. " Please read and understand all output\n"
. " www.pivotaltracker.com\n";
/**
*
* ENSURE WE HAVE A TOKEN
*
*/
// Does our .pivotaltoken file exist?
if (!file_exists($helpers->tokenFile()))
{
$pivotaltracker->token = $pivotaltracker->getToken();
}
$token = file_get_contents($helpers->tokenFile());
echo ($helpers->displayToken($token));
/**
*
* WHAT PROJECT ARE WE USING
*
*/
// First we establish the location of the .git directory.
// Once we locate git we check for the prepare-commit-msg hook which would contain the Tracker Project ID
// See Dependencies in the README
exec('git rev-parse --show-toplevel 2> /dev/null', $output);
$pRoot = $output[0];
echo ("\nPROJECT:\n"
. " Project directory: " .$pRoot . "\n");
// If the prepare-commit-msg does not exist let's run the hooks command
if (!file_exists($helpers->hookFile($pRoot)))
{
echo " Please choose project id:\n"
." ----------------------------------------\n\n";
echo $pivotaltracker->getMyRecentProjects($token) . "\n"
." ----------------------------------------\n";
exec('hooks.sh');
}
$pId = $helpers->getFileContents($helpers->hookFile($pRoot), 'project');
$pName = $pivotaltracker->getProject($token,$pId,'name');
echo " Project Name/Id: " . $pName . " - " . $pId . "\n";
/**
*
* STORY TIME
*
*/
// Let's go ahead and show them their stories which are not accepted
echo "\nSTORIES:\n";
echo $cStories = $pivotaltracker->getStories($token,$pId);
fwrite(STDOUT, "\n Story id [story_id/new]: ");
$sOption = (trim(fgets(STDIN)));
// If they choose to create a new story we'll get the required information
// Establishing these variables before the if
if ($sOption == 'new')
{
fwrite(STDOUT, "\n Story type [feature/bug/chore/release]: ");
$sType = (trim(fgets(STDIN)));
fwrite(STDOUT, "\n Story Name: ");
$sName = (trim(fgets(STDIN)));
fwrite(STDOUT, "\n Story Desc: ");
$sDesc = (trim(fgets(STDIN)));
// We have collectetd the information now create a new story.
$sInfo = $pivotaltracker->addStory("$token", "$pId", "$sType", "$sName", "$sDesc");
$sId = $sInfo['sId'];
$sUrl = $sInfo['sUrl'];
echo "\n Created story: " . $sId
."\n At: " . $sUrl . "\n";
// If they want to create a bug we will ask them if they would like to include all of the log files
if ($sType == 'bug')
{
fwrite(STDOUT, "\n Attach logs [yes/no]: ");
$sLogify = (trim(fgets(STDIN)));
// If they want to include all of the logs this step will upload them to the project for processing later
if ($sLogify == 'yes')
{
$sLogs = glob("$pRoot/var/{log,report}/*", GLOB_BRACE);
$sLogs[] = "/var/log/apache2/error.log";
$pUploads = $pivotaltracker->addUploads($token,$pId,$sLogs);
$sComm = "Attaching magento and server logs";
// Convert Uploads to a String and attach with comment
$pUploadsString = implode(",",$pUploads);
$cResult = $pivotaltracker->addAttachments($token,$pId,$sId,$sComm,$pUploadsString);
echo "\n Comment: " . $cResult . "\n";
}
}
}
// Ok they have chosen to contribute to an existing story.
else
{
$sId = $sOption;
// Collect a comment for the story
fwrite(STDOUT, "\n Story Comment: ");
$sComm = (trim(fgets(STDIN)));
$cResult = $pivotaltracker->addComment($token,$pId,$sId,$sComm);
echo " Updated storyId: " . $sId . "\n"
." With comment: " . $cResult . "\n";
}
// Add Tasks
//fwrite(STDOUT, "\n Story Comment: ");
//$sTask = (trim(fgets(STDIN)));
// Add an attachment?
//fwrite(STDOUT, "\n Story Comment: ");
//$sAttachment = (trim(fgets(STDIN)));
?>