2
// This program is free software; you can redistribute it and/or modify
3
// it under the terms of the GNU General Public License as published by
4
// the Free Software Foundation; either version 3 of the License, or
5
// (at your option) any later version.
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License for more details.
12
// You should have received a copy of the GNU General Public License
13
// along with this program; if not, write to the Free Software
14
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
using System.Net.Security;
22
using System.Collections.Generic;
28
/// Class which makes queries to JIRA via the RSS interface
34
/// ie. http://issues.apache.org/jira
38
private string _username;
39
private string _password;
42
/// Maximum results we can retrieve in a query
44
private int _maxResults= 10000;
47
public JIRARssClient( string url )
52
public string Username
54
set { _username= value; }
57
public string Password
59
set { _password= value; }
63
/// Get a list of all issues, open or closed
65
public IList<RemoteIssue> GetAllIssues( IList<long> projectIds )
67
return DoQuery( GetBaseQueryUrl( projectIds ) );
71
/// Get a list of all issues that have the given status ids
73
public IList<RemoteIssue> GetAllIssuesWithStatus( IList<long> projectIds, IList<int> statusIds )
75
StringBuilder sb= new StringBuilder();
76
sb.Append( GetBaseQueryUrl( projectIds ) );
78
foreach( int statusId in statusIds )
80
sb.Append( "&status=" );
81
sb.Append( statusId );
83
return DoQuery( sb.ToString() );
87
/// Get a list of all issues (open and closed), that have been updated in the last hour
89
public IList<RemoteIssue> GetRecentlyUpdatedIssues( IList<long> projectIds )
91
return DoQuery( GetBaseQueryUrl( projectIds )+"&updated%3Aprevious=-1h" );
95
/// Do the actual query by converting the rss into a list of issue items
97
private IList<RemoteIssue> DoQuery( String queryUrl )
99
List<RemoteIssue> result= new List<RemoteIssue>();
102
HttpWebRequest request= WebRequest.Create( queryUrl ) as HttpWebRequest;
104
// Handle credentials
105
if( _username!=null && _password!=null )
107
CredentialCache creds= new CredentialCache();
108
creds.Add( new Uri( queryUrl ), "Basic", new NetworkCredential( _username, _password ) );
110
request.Credentials= creds;
113
// Console.WriteLine( "Query: "+queryUrl );
115
HttpWebResponse response= request.GetResponse() as HttpWebResponse;
117
// Parse the xml from the get all open issues query
118
XmlDocument doc= new XmlDocument();
119
doc.Load( response.GetResponseStream() );
121
foreach( XmlNode itemNode in doc.SelectNodes( "//rss/channel/item" ) )
123
RemoteIssue issue= new RemoteIssue();
124
issue.key= itemNode.SelectSingleNode( "key" ).InnerText;
125
issue.summary= itemNode.SelectSingleNode( "title" ).InnerText;
126
issue.status= itemNode.SelectSingleNode( "status" ).Attributes[ "id" ].InnerText;
135
/// Use the RSS End-point to find issues that are resolved/closed for the given project ids
137
private string GetBaseQueryUrl( IList<long> projectIds )
139
StringBuilder sb= new StringBuilder();
141
sb.Append( "/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?" );
143
// Append the request to authenticate
144
if( _username!=null && _password!=null )
146
sb.Append( "os_authType=basic" );
149
// Add each of the project ids to the query
150
foreach( long projectId in projectIds )
152
sb.Append( "&pid=" );
153
sb.Append( projectId );
156
// Descending sort by issue id
157
sb.Append( "&sorter/field=issuekey" );
158
sb.Append( "&sorter/order=DESC" );
160
// Cap on the max results...
161
sb.Append( "&tempMax=" );
162
sb.Append( _maxResults );
164
return sb.ToString();