root/trunk/MTFogger/MTFogger.pl

Revision 394, 4.9 kB (checked in by djchall, 9 months ago)

First release of MTFogger, MT plugin that provides template tags for printing lists of Fogbugz cases in MT templates.

Line 
1 # MTFogger - A plugin for Movable Type.
2 # Copyright (c) 2007 Six Apart.
3
4 package MT::Plugin::MTFogger;
5
6 use strict;
7 use base qw( MT::Plugin );
8
9 use WebService::FogBugz;
10 use Data::Dumper;
11 use XML::Liberal;
12 use XML::LibXML;
13 use XML::Simple;
14
15 our $VERSION = '0.1';
16 our $SCHEMA_VERSION = '1.000';
17
18
19 my $plugin = MT::Plugin::MTFogger->new({
20     key             => 'mtfogger',
21     id              => 'mtfogger',
22         name            => "MTFogger",
23         version         => $VERSION,
24         schema_version  => $SCHEMA_VERSION,
25         description     => "<MT_TRANS phrase=\"Display Fogbugz releases and cases from within Movable Type\">",
26         author_name     => "Chris Ernest Hall",
27         author_link     => "http://djchall.vox.com/",
28         plugin_link     => "http://djchall.com/plugins/",
29         doc_link        => "",
30         system_config_template => 'fogger_config.tmpl',
31         settings => new MT::PluginSettings([
32             ['FbzLogin', { Default => '' }],
33                         ['FbzPassword', { Default => '' }],
34                         ['FbzBaseurl', { Default => '' }]
35         ])
36 });
37
38 MT->add_plugin($plugin);
39
40 sub init_registry {
41   my $plugin = shift;
42  
43       $plugin->registry({
44         tags => {
45                     function => {
46                              'FbzCaseNumber' => \&_hdlr_GetCaseNumber,
47                                  'FbzCaseCategory' => \&_hdlr_GetCaseCategory,
48                                  'FbzCaseTitle' => \&_hdlr_GetCaseTitle,
49                                  'FbzCaseStatus' => \&_hdlr_GetCaseStatus,
50                                  'FbzCasePriority' => \&_hdlr_GetCasePriority,
51                     },
52             block => {
53                 'FbzCases' => \&_hdlr_ListCases,
54             },
55         },
56     });
57  
58 }
59
60
61 sub init_app {
62     my $plugin = shift;
63     $plugin->SUPER::init_app(@_);
64     my ($app) = @_;
65
66     return unless $app->isa('MT::App::CMS');
67 }
68
69 sub instance { $plugin }
70
71 sub _hdlr_ListCases {
72     #for now, just get the active cases in a hard-coded branch
73     my ($ctx, $args, $cond) = @_;
74     my $out = "";
75     my $builder = $ctx->stash('builder');
76     my $tokens = $ctx->stash('tokens');
77        
78         my $project = $args->{project};
79         my $fixfor = $args->{fixfor};
80         my $status = $args->{status};
81         my $orderby = $args->{orderby};
82         my $max = $args->{max};
83        
84         #get list of active cases
85     my $Cases = getCases($project, $fixfor, $status, $orderby, $max);
86        
87         if (ref($Cases) eq 'ARRAY') {
88        
89         #loop through cases, and populate stash with them, I think
90         foreach my $case (@$Cases) {
91       my @case_numbers = @{ $case->{ixBug} };
92       my $case_number = $case_numbers[0];
93       my $category = $case->{'sCategory'};
94       my $title = $case->{'sTitle'};
95       my $status = $case->{'sStatus'};
96           my $priority = $case->{'sPriority'};
97          
98       $ctx->stash("current_case_number",$case_number);
99           $ctx->stash("current_case_category",$category);
100           $ctx->stash("current_case_title",$title);
101           $ctx->stash("current_case_status",$status);
102           $ctx->stash("current_case_priority",$priority);
103                
104       $out .= $builder->build($ctx,$tokens,$cond);       
105     }
106        
107         } else {
108           $out = "";
109         }
110        
111     return $out;
112 }
113
114 sub _hdlr_GetCaseNumber {
115     my ($ctx, $args, $cond) = @_;
116     my $CaseNumber = $ctx->stash('current_case_number');
117    
118         return $CaseNumber;
119 }
120
121 sub _hdlr_GetCaseCategory {
122     my ($ctx, $args, $cond) = @_;
123     my $CaseCategory = $ctx->stash('current_case_category');
124    
125         return $CaseCategory;
126 }
127
128 sub _hdlr_GetCaseTitle {
129     my ($ctx, $args, $cond) = @_;
130     my $CaseTitle = $ctx->stash('current_case_title');
131    
132         return $CaseTitle;
133 }
134
135 sub _hdlr_GetCaseStatus {
136     my ($ctx, $args, $cond) = @_;
137     my $CaseStatus = $ctx->stash('current_case_status');
138    
139         return $CaseStatus;
140 }
141
142
143 sub _hdlr_GetCasePriority {
144     my ($ctx, $args, $cond) = @_;
145     my $CasePriority = $ctx->stash('current_case_priority');
146    
147         return $CasePriority;
148 }
149
150 sub getCases() {
151   my $project = shift;
152   my $fixfor = shift;
153   my $status = shift;
154   my $orderby = shift;
155   my $max = shift;
156  
157   $max = int($max);
158  
159   if (!$status) {
160     $status = "Active";
161   }
162  
163   if (!$orderby) {
164     $orderby = "Case";
165   }
166  
167   my $fogbugz = logonFogbugz();
168
169   my %Cases = $fogbugz->request_method('search', {
170     q => "project:\"$project\" fixfor:\"$fixfor\" status:\"$status\" orderby:\"$orderby\" ",
171     cols => 'ixBug,sCategory,sTitle,sStatus,sPriority',
172         max => $max,
173   });
174
175   my ($content)  = %Cases;
176
177   #let's try parsing it
178   my $parsed_content = XMLin($content);
179
180   my $Cases = $parsed_content->{cases}->{case};
181  
182   return $Cases;
183 }
184
185 sub getFixfors() {
186   #to do -- function that gets all releases from fbz for a given project
187
188
189 }
190
191 sub logonFogbugz() {
192   my $plugin = MT::Plugin::MTFogger->instance;
193
194   my $config = $plugin->get_config_hash();
195  
196   #get parameters from settings
197   my $FbzLogin = $config->{FbzLogin};
198   my $FbzPassword = $config->{FbzPassword};
199   my $FbzBaseurl = $config->{FbzBaseurl};
200  
201   my $fogbugz = WebService::FogBugz->new({
202     email => $FbzLogin,
203     password => $FbzPassword,
204     base_url => $FbzBaseurl
205   });
206
207   my $result = $fogbugz->logon;
208  
209   return $fogbugz;
210 }
Note: See TracBrowser for help on using the browser.