Class: GithubIssueImporter::Launchpad

Inherits:
Object
  • Object
show all
Defined in:
lib/github-issue-importer/launchpad.rb

Instance Method Summary collapse

Constructor Details

#initializeLaunchpad

Returns a new instance of Launchpad.



8
9
10
# File 'lib/github-issue-importer/launchpad.rb', line 8

def initialize
  @owners = Hash.new
end

Instance Method Details

#get(url) ⇒ Object



79
80
81
# File 'lib/github-issue-importer/launchpad.rb', line 79

def get(url)
  JSON.parse Net::HTTP.get_response(URI.parse(url)).body rescue nil
end

#get_bug(id) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/github-issue-importer/launchpad.rb', line 27

def get_bug(id)
  if id.is_a? Hash
    bug_link = id['bug_link']
  else
    bug_link = "https://api.launchpad.net/1.0/bugs/#{id}"
  end
  get bug_link
end

#get_bug_comments(id) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/github-issue-importer/launchpad.rb', line 49

def get_bug_comments(id)
  if id.is_a? Hash
    bug_comments_link = id['messages_collection_link']
  else
    bug_comments_link = "https://api.launchpad.net/1.0/bugs/#{id}/comments"
  end
  comments = get bug_comments_link
  comments['entries']
end

#get_bug_entries(project) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/github-issue-importer/launchpad.rb', line 12

def get_bug_entries(project)
  entries = []

  url = "https://api.launchpad.net/1.0/#{project}?ws.op=searchTasks"
  loop do
    bugs = get url
    entries += bugs['entries']

    url = bugs['next_collection_link']
    break unless url
  end

  entries.sort_by! { |o| o['date_created'] }
end

#get_comment_attachments(comment) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/github-issue-importer/launchpad.rb', line 36

def get_comment_attachments(comment)
	comment_attachments_link = comment['bug_attachments_collection_link']
	comment_attachments = get comment_attachments_link
	body = ""
	if !comment_attachments.nil?
	  comment_attachments['entries'].each do |attachment|
 body += "Attachment: [#{attachment['title']}](#{attachment['data_link']})\n"
	  end
	  body += "\n"
	end
	return body
end

#get_owner(id) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/github-issue-importer/launchpad.rb', line 59

def get_owner(id)
  if id.is_a? Hash
    owner_link = id['owner_link']
  else
    owner_link = "https://api.launchpad.net/1.0/~#{id}"
  end

  if @owners[owner_link].nil?
	  response = Net::HTTP.get_response(URI.parse(owner_link)).body
	  if response.include? "User is suspended"
 @owners[owner_link] = response[22,response.length].concat("suspended user'")
	  else
 json = JSON.parse response
 @owners[owner_link] = json['display_name']
	  end
  end

  @owners[owner_link]
end