forked from travist/pivotalphp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.php
220 lines (186 loc) · 5.95 KB
/
run.php
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/usr/bin/php
<?php
require_once('cliphp/cli.php');
require_once('includes/pivotaltracker_rest.php');
require_once('includes/tcpdf/config/lang/eng.php');
require_once('includes/tcpdf/tcpdf.php');
require_once('includes/devStatus.php');
// To keep stupid warnings from showing up...
date_default_timezone_set('America/Chicago');
// Create the new CLI object.
$cli = new CLIPHP();
// Get all of the files in the scripts folder.
$dir = dirname(__FILE__) . "/scripts";
$files = array();
if (is_dir($dir)) {
if ($contents = opendir($dir)) {
while (($node = readdir($contents)) !== false) {
if ($node != "." && $node != "..") {
$path = $dir . DIRECTORY_SEPARATOR . $node;
$ext = strtolower(substr($node, strrpos($node, '.') + 1));
if ($ext == 'php' && !is_dir($path)) {
$files[$node] = $path;
}
}
}
}
}
/**
* Get's which script to run.
*
* @return <type>
*/
function getScript() {
global $cli, $files;
$i = 1;
$output = "Select an output script:\n";
$check = false;
foreach ($files as $file => $path) {
$output .= ' ' . $i . ') ' . $file . "\n";
$i++;
}
$input = $cli->get("script", $output);
if (is_numeric($input) && $input <= count($files)) {
$keys = array_keys($files);
return $keys[($input - 1)];
}
else {
echo "Invalid Numerical input. Please try again.\n";
return 0;
}
}
/**
* Get's your pivotal tracker token.
*
* @return array
*/
function getToken() {
global $cli;
if (isset($cli->args['token'])) {
return $cli->args['token'];
}
else {
$username = $cli->get("username", "Enter your Pivotal Tracker user name. ( You will only need to do this once ):");
$password = $cli->get("password", "Enter you Pivotal Tracker password. ( You will only need to do this once ):");
$output = shell_exec('curl -u ' . $username . ':' . $password . ' -X GET https://www.pivotaltracker.com/services/v3/tokens/active');
$matches = array();
preg_match('/\<guid\>([0-9a-zA-Z]+)\<\/guid\>/', $output, $matches);
return $matches[1];
}
}
/**
* Get's the PDF object.
*
* @param <type> $config
* @return TCPDF
*/
function getPDF($args) {
// create new PDF document
global $cli;
//landscape for bullet_list
if ($cli->args['script'] == "bullet_list.php") {
$pdf = new TCPDF("L", PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
}
else {
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
}
// set document information
$pdf->SetCreator($args['name']);
$pdf->SetAuthor($args['name']);
$pdf->SetTitle($args['title']);
$pdf->SetSubject($args['title']);
// remove default header/footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
$pdf->SetMargins(5, 5, 5);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, 5);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
return $pdf;
}
/**
* Get's the privotal tracker stories based on a filter.
*
* @param <type> $config
* @param <type> $filter
* @return <type>
*/
function getStories($args) {
// Now create a new PivotalTracker object.
$pivotal = new PivotalTracker($args['token']);
$args['filter'] = isset($args['filter']) ? 'label:"' . $args['filter'] . '"' : '';
$args['filter'] .= 'includedone:true';
return $pivotal->stories_get_by_filter($args['project'], $args['filter']);
}
$cli->get("name", "Enter your full name. ( You will only need to do this once ):", TRUE);
$cli->set("token", getToken(), TRUE);
$cli->get("project", "Enter you Pivotal Tracker project ID. ( You will only need to do this once ):", TRUE);
$cli->get("title", "Title: ");
$cli->get("filter", "Filter: ");
$cli->set("script", getScript());
// Make sure we have everything.
if ($cli->args['token'] && $cli->args['project'] && $cli->args['title'] && $cli->args['script']) {
// Get the PDF.
$pdf = getPDF($cli->args);
// Get the stories.
$stories = getStories($cli->args);
if ($stories) {
// Include the script.
require_once($files[$cli->args['script']]);
// counts for stories
//var_dump($stories);
//exit();
//counts for stories
$type_cnt = array('bug'=>0,'feature'=>0,'release'=>0);
$est_type_cnt = array('bug'=>0,'feature'=>0,'release'=>0);
$est_accept_type_cnt = array('bug'=>0,'feature'=>0,'release'=>0);
$state_type_cnt = array();
$est_cnt = 0;
foreach ($stories as $story) {
if ($story['story_type']) {
$type_cnt[$story['story_type']]++;
if ($story['estimate'] > 0) {
$est_cnt = $est_cnt + $story['estimate'];
if ($story['current_state'] == 'accepted') {
$est_accept_type_cnt[$story['story_type']] += $story['estimate'];
$est_accept_cnt += $story['estimate'];
}
$est_type_cnt[$story['story_type']] += $story['estimate'];
}
$state_type_cnt[$story['story_type']][$story['current_state']]++;
}
}
// var_dump($est_type_cnt);
// var_dump($state_type_cnt);
//var_dump($type_cnt);
$msg = "---------------\nTOTALS:\n";
foreach ($type_cnt as $type => $type_count) {
$msg .= sprintf (" %-15.15s : %4d\n",$type."(s)",$type_count);
}
$msg .= "---------------\n";
$msg .= "estimate total:$est_cnt\n";
$msg .= "---------------\n";
print $msg;
//test writing script to give list of stories, their dev, and the status of those stories
devStatusList($stories, $cli->args);
// Get the output from our script.
pdf_contents($pdf, $cli->args, $stories);
//Close and output PDF document
$pdf_output = $pdf->Output('doc.pdf', 'S');
// Now write the contents to a file.
$filename = $cli->args['title'] . '.pdf';
file_put_contents( dirname(__FILE__) . '/' . $filename, $pdf_output);
echo "Successfully created " . $filename . "!\n";
}
else {
echo "No stories found.\n";
}
}
else {
echo "Invalid Input: Please try again.\n";
}
?>