meta_project 0.4.9 → 0.4.10

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,5 +1,13 @@
1
1
  = MetaProject Changelog
2
2
 
3
+ == Version 0.4.10
4
+
5
+ This version fixes some bugs in the JIRA and SourceForge APIs.
6
+
7
+ * Made error reporting better for JIRA exceptions.
8
+ * Avoid exception rippling through when login credentials are not specified.
9
+ * Made SourceForge tracker API more robust.
10
+
3
11
  == Version 0.4.9
4
12
 
5
13
  This release makes the validation of Browser objects more robust.
data/README CHANGED
@@ -1,4 +1,4 @@
1
- = MetaProject 0.4.9
1
+ = MetaProject 0.4.10
2
2
 
3
3
  MetaProject (formerly XForge) is a library that allows interaction with various project hosting servers, issue trackers, SCMs and SCM browsers through a common API.
4
4
 
data/Rakefile CHANGED
@@ -24,7 +24,7 @@ require 'rake/rdoctask'
24
24
  #
25
25
  # REMEMBER TO KEEP PKG_VERSION IN SYNC WITH THE CHANGES FILE!
26
26
  PKG_NAME = "meta_project"
27
- PKG_VERSION = "0.4.9"
27
+ PKG_VERSION = "0.4.10"
28
28
  PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
29
29
  PKG_FILES = FileList[
30
30
  '[A-Z]*',
@@ -45,18 +45,30 @@ module MetaProject
45
45
  login do |session|
46
46
  issue_struct = session.createIssue(issue_struct)
47
47
  issue.attributes[:identifier] = issue_struct["key"]
48
+ issue
48
49
  end
49
50
  end
50
51
 
51
52
  def materialize(issue)
52
- login do |session|
53
- issue.attributes[:identifier] = issue.attributes[:identifier].upcase
54
- issue_struct = session.getIssue(issue.identifier)
55
-
56
- issue.attributes[:summary] = issue_struct["summary"].strip
57
- issue.attributes[:detail] = issue_struct["description"].strip
53
+ issue.attributes[:identifier] = issue.attributes[:identifier].upcase
54
+
55
+ # Getting summary and detail requires login
56
+ begin
57
+ login do |session|
58
+ issue_struct = session.getIssue(issue.identifier)
59
+ issue.attributes[:url] = "#{@jira_base_url}/browse/#{issue.identifier}"
60
+ issue.attributes[:summary] = issue_struct["summary"].strip
61
+ issue.attributes[:detail] = issue_struct["description"].strip
62
+ end
63
+ rescue JiraEnvVarException => e
64
+ # Couldn't log in because of missing login info. Assume issue exists
58
65
  issue.attributes[:url] = "#{@jira_base_url}/browse/#{issue.identifier}"
66
+ STDERR.puts("WARNING: #{e.message}")
67
+ rescue XMLRPC::FaultException => e
68
+ # Probably bad issue number. Don't set URL.
69
+ STDERR.puts("WARNING: Exception from JIRA: #{e.faultCode}, #{e.faultString} Issue id: #{issue.identifier}")
59
70
  end
71
+ issue
60
72
  end
61
73
 
62
74
  private
@@ -64,27 +76,17 @@ module MetaProject
64
76
  def login
65
77
  client = XMLRPC::Client.new2("#{@jira_base_url}/rpc/xmlrpc")
66
78
  token = client.call("#{JIRA_API}.login", user, password)
67
- begin
68
- yield Session.new(client, token)
69
- rescue XMLRPC::FaultException => e
70
- # Probably bad issue number or failed login
71
- STDERR.puts("WARNING: Exception from JIRA: #{e.faultCode}, #{e.faultString}")
72
- nil
73
- rescue LoginException => e
74
- # Missing env vars
75
- STDERR.puts("WARNING: Couldn't log in to JIRA at #{@rooturl}: #{e.message}")
76
- nil
77
- end
79
+ yield Session.new(client, token)
78
80
  end
79
81
 
80
82
  def user
81
83
  var = "#{login_env_var_prefix}_JIRA_USER"
82
- ENV[var] || login_error(var)
84
+ ENV[var] || missing_env_var(var)
83
85
  end
84
86
 
85
87
  def password
86
88
  var = "#{login_env_var_prefix}_JIRA_PASSWORD"
87
- ENV[var] || login_error(var)
89
+ ENV[var] || missing_env_var(var)
88
90
  end
89
91
 
90
92
  def login_env_var_prefix
@@ -95,13 +97,14 @@ module MetaProject
95
97
  end
96
98
  end
97
99
 
98
- def login_error(var)
99
- raise LoginException.new("#{var} environment variable not defined")
100
+ def missing_env_var(var)
101
+ raise JiraEnvVarException.new("Couldn't log in to JIRA at #{@rooturl}: #{e.message}. The " +
102
+ "#{var} environment variable must be set in order to communicate with JIRA")
100
103
  end
101
104
 
102
- class LoginException < Exception
105
+ class JiraEnvVarException < Exception
103
106
  end
104
-
107
+
105
108
  # This wrapper around XMLRPC::Client that allows simpler method calls
106
109
  # via method_missing and doesn't require to manage the token
107
110
  class Session
@@ -24,6 +24,7 @@ module MetaProject
24
24
  rescue OpenURI::HTTPError => e
25
25
  STDERR.puts e.message
26
26
  end
27
+ issue
27
28
  end
28
29
 
29
30
  end
@@ -3,11 +3,11 @@ module MetaProject
3
3
  module XForge
4
4
  class RubyForgeTracker < XForgeTracker
5
5
 
6
- def subtracker_regexp
6
+ def subtracker_pattern
7
7
  /\/tracker\/\?atid=(\d+)&group_id=\d*&func=browse/
8
8
  end
9
9
 
10
- def issue_summary_regexp(identifier)
10
+ def issue_summary_pattern(identifier)
11
11
  /<a href=\"\/tracker\/index.php\?func=detail&aid=#{identifier}&group_id=\d+&atid=\d+\">([^<]*)<\/a>/
12
12
  end
13
13
 
@@ -3,11 +3,11 @@ module MetaProject
3
3
  module XForge
4
4
  class SourceForgeTracker < XForgeTracker
5
5
 
6
- def subtracker_regexp
6
+ def subtracker_pattern
7
7
  /\/tracker\/\?atid=(\d+)&amp;group_id=\d*&amp;func=browse/
8
8
  end
9
9
 
10
- def issue_summary_regexp(identifier)
10
+ def issue_summary_pattern(identifier)
11
11
  /<a href=\"\/tracker\/index.php\?func=detail&amp;aid=#{identifier}&amp;group_id=\d+&amp;atid=\d+\">([^<]*)<\/a>/
12
12
  end
13
13
 
@@ -1,3 +1,4 @@
1
+
1
2
  require 'meta_project/tracker/base'
2
3
  require 'meta_project/tracker/digit_issues'
3
4
  require 'meta_project/tracker/issue'
@@ -26,6 +27,7 @@ module MetaProject
26
27
  end
27
28
 
28
29
  def materialize(issue)
30
+ issue
29
31
  end
30
32
 
31
33
  class SubTracker
@@ -40,8 +42,8 @@ module MetaProject
40
42
  def issue(identifier)
41
43
  html = better_open(@uri).read
42
44
 
43
- issue_summary_regexp = @tracker.issue_summary_regexp(identifier)
44
- if(html =~ issue_summary_regexp)
45
+ issue_summary_pattern = @tracker.issue_summary_pattern(identifier)
46
+ if(html =~ issue_summary_pattern)
45
47
  issue_url = @tracker.project.group_id_uri("tracker/index.php", "&atid=#{@atid}&func=detail&aid=#{identifier}")
46
48
  issue_summary = $1.strip
47
49
  return Issue.new(@tracker, :summary => issue_summary, :url => issue_url)
@@ -54,14 +56,32 @@ module MetaProject
54
56
 
55
57
  # The ids of the subtrackers
56
58
  def atids
59
+ # headers = {
60
+ # "User-Agent" => "Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4",
61
+ # "Accept" => "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5",
62
+ # "Accept-Language" => "en-us,en;q=0.5",
63
+ # "Accept-Encoding" => "gzip,deflate",
64
+ # "Accept-Charset" => "ISO-8859-1,utf-8;q=0.7,*;q=0.7",
65
+ # "Keep-Alive" => "300",
66
+ # "Connection" => "close",
67
+ # "X-Requested-With" => "XMLHttpRequest",
68
+ # "X-Prototype-Version" => "1.3.1",
69
+ # "Content-Type" => "application/x-www-form-urlencoded",
70
+ # "Content-Length" => "0",
71
+ # "Cookie" => "author=AnonymousCoward; _session_id=975a583d513190522ce3aeba315552d0",
72
+ # "Pragma" => "no-cache",
73
+ # "Cache-Control" => "no-cache"
74
+ # }
75
+
57
76
  html = better_open(overview).read
77
+ STDERR.puts "The HTML returned from #{overview} was empty! This might be because the server is trying to fool us" if html == ""
58
78
 
59
79
  # TODO: there has to be a better way to extract the atids from the HTML!
60
80
  atids = []
61
81
  offset = 0
62
82
  look_for_atid = true
63
83
  while(look_for_atid)
64
- match_data = subtracker_regexp.match(html[offset..-1])
84
+ match_data = subtracker_pattern.match(html[offset..-1])
65
85
  if(match_data)
66
86
  offset += match_data.begin(1)
67
87
  atids << match_data[1]
@@ -69,6 +89,14 @@ module MetaProject
69
89
  look_for_atid = false
70
90
  end
71
91
  end
92
+ if atids.empty?
93
+ debug_file = "xforge_tracker_debug.html"
94
+ File.open(debug_file, "w"){|io| io.write html}
95
+ STDERR.puts "WARNING: No subtrackers found at #{overview}."
96
+ STDERR.puts "I was looking for /#{subtracker_pattern.source}/"
97
+ STDERR.puts "Please consider filing a bug report at http://rubyforge.org/tracker/?atid=3161&group_id=801&func=browse"
98
+ STDERR.puts "The HTML has been saved to #{debug_file}"
99
+ end
72
100
  atids
73
101
  end
74
102
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: meta_project
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.4.9
7
- date: 2005-09-06 00:00:00 -04:00
6
+ version: 0.4.10
7
+ date: 2005-09-08 00:00:00 -04:00
8
8
  summary: Ruby based make-like utility.
9
9
  require_paths:
10
10
  - lib