project.rb
1.56 KB
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
class Gitlab::Project
include ActiveModel::Model
attr_accessor :id, :description, :default_branch, :tag_list, :public,
:archived, :visibility_level, :ssh_url_to_repo, :http_url_to_repo,
:web_url, :name, :name_with_namespace, :path, :path_with_namespace,
:issues_enabled, :merge_requests_enabled, :wiki_enabled, :builds_enabled,
:snippets_enabled, :created_at, :last_activity_at,
:shared_runners_enabled, :creator_id, :namespace, :owner, :avatar_url,
:star_count, :forks_count, :open_issues_count, :public_builds,
:permissions
def self.all
all = Array.new;
api_base_uri = Rails.configuration.x.gitlab['api_base_uri']
auth_token = Rails.configuration.x.gitlab['auth_token']
links = {
'next' => api_base_uri + 'projects?visibility=public',
'first' => nil,
'last' => nil
}
uri = URI.parse(links['next'])
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true # TODO make this aware of http/https
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
while true
request = Net::HTTP::Get.new(uri.request_uri)
request['PRIVATE-TOKEN'] = auth_token
response = http.request(request)
JSON.parse(response.body).each do |project|
all.push(Gitlab::Project.new(project))
end
links = response['link'].split(',').map! { |a|
_tmp = a.strip.split(';').map! { |a|
a.strip
}
{_tmp[1][5...-1] => _tmp[0][1...-1]}
}.reduce({}, :merge)
break unless links['next']
uri = URI.parse(links['next'])
end
return all
end
def self.find
end
def deliver
if valid?
# deliver email
end
end
end
# vim: set ts=2 sw=2: