Commit d7fe22c7f70f870e6eccda97ea452482536126ba
1 parent
5d6b3215
Add Model to access The gitlab API.
Showing
10 changed files
with
115 additions
and
2 deletions
app/models/gitlab.rb
0 → 100644
app/models/gitlab/project.rb
0 → 100644
| 1 | +class Gitlab::Project | ||
| 2 | + include ActiveModel::Model | ||
| 3 | + | ||
| 4 | + attr_accessor :id, :description, :default_branch, :tag_list, :public, | ||
| 5 | + :archived, :visibility_level, :ssh_url_to_repo, :http_url_to_repo, | ||
| 6 | + :web_url, :name, :name_with_namespace, :path, :path_with_namespace, | ||
| 7 | + :issues_enabled, :merge_requests_enabled, :wiki_enabled, :builds_enabled, | ||
| 8 | + :snippets_enabled, :created_at, :last_activity_at, | ||
| 9 | + :shared_runners_enabled, :creator_id, :namespace, :owner, :avatar_url, | ||
| 10 | + :star_count, :forks_count, :open_issues_count, :public_builds, | ||
| 11 | + :permissions | ||
| 12 | + | ||
| 13 | + def self.all | ||
| 14 | + all = Array.new; | ||
| 15 | + | ||
| 16 | + api_base_uri = Rails.configuration.x.gitlab['api_base_uri'] | ||
| 17 | + auth_token = Rails.configuration.x.gitlab['auth_token'] | ||
| 18 | + | ||
| 19 | + links = { | ||
| 20 | + 'next' => api_base_uri + 'projects?visibility=public', | ||
| 21 | + 'first' => nil, | ||
| 22 | + 'last' => nil | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + uri = URI.parse(links['next']) | ||
| 26 | + http = Net::HTTP.new(uri.host, uri.port) | ||
| 27 | + http.use_ssl = true # TODO make this aware of http/https | ||
| 28 | + http.verify_mode = OpenSSL::SSL::VERIFY_NONE | ||
| 29 | + | ||
| 30 | + while true | ||
| 31 | + request = Net::HTTP::Get.new(uri.request_uri) | ||
| 32 | + request['PRIVATE-TOKEN'] = auth_token | ||
| 33 | + | ||
| 34 | + response = http.request(request) | ||
| 35 | + | ||
| 36 | + JSON.parse(response.body).each do |project| | ||
| 37 | + all.push(Gitlab::Project.new(project)) | ||
| 38 | + end | ||
| 39 | + | ||
| 40 | + links = response['link'].split(',').map! { |a| | ||
| 41 | + _tmp = a.strip.split(';').map! { |a| | ||
| 42 | + a.strip | ||
| 43 | + } | ||
| 44 | + {_tmp[1][5...-1] => _tmp[0][1...-1]} | ||
| 45 | + }.reduce({}, :merge) | ||
| 46 | + | ||
| 47 | + break unless links['next'] | ||
| 48 | + uri = URI.parse(links['next']) | ||
| 49 | + end | ||
| 50 | + | ||
| 51 | + return all | ||
| 52 | + end | ||
| 53 | + | ||
| 54 | + def self.find | ||
| 55 | + end | ||
| 56 | + | ||
| 57 | + def deliver | ||
| 58 | + if valid? | ||
| 59 | + # deliver email | ||
| 60 | + end | ||
| 61 | + end | ||
| 62 | +end | ||
| 63 | +# vim: set ts=2 sw=2: |
| @@ -38,4 +38,7 @@ Rails.application.configure do | @@ -38,4 +38,7 @@ Rails.application.configure do | ||
| 38 | 38 | ||
| 39 | # Raises error for missing translations | 39 | # Raises error for missing translations |
| 40 | # config.action_view.raise_on_missing_translations = true | 40 | # config.action_view.raise_on_missing_translations = true |
| 41 | + | ||
| 42 | + # Load Gitlab configuration | ||
| 43 | + config.x.gitlab = config_for(:gitlab) | ||
| 41 | end | 44 | end |
| @@ -76,4 +76,7 @@ Rails.application.configure do | @@ -76,4 +76,7 @@ Rails.application.configure do | ||
| 76 | 76 | ||
| 77 | # Do not dump schema after migrations. | 77 | # Do not dump schema after migrations. |
| 78 | config.active_record.dump_schema_after_migration = false | 78 | config.active_record.dump_schema_after_migration = false |
| 79 | + | ||
| 80 | + # Load Gitlab configuration | ||
| 81 | + config.x.gitlab = config_for(:gitlab) | ||
| 79 | end | 82 | end |
| @@ -39,4 +39,7 @@ Rails.application.configure do | @@ -39,4 +39,7 @@ Rails.application.configure do | ||
| 39 | 39 | ||
| 40 | # Raises error for missing translations | 40 | # Raises error for missing translations |
| 41 | # config.action_view.raise_on_missing_translations = true | 41 | # config.action_view.raise_on_missing_translations = true |
| 42 | + | ||
| 43 | + # Load Gitlab configuration | ||
| 44 | + config.x.gitlab = config_for(:gitlab) | ||
| 42 | end | 45 | end |
config/gitlab.yml
0 → 100644
test/fixtures/gitlab/projects.yml
0 → 100644
| 1 | +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
| 2 | + | ||
| 3 | +# This model initially had no columns defined. If you add columns to the | ||
| 4 | +# model remove the '{}' from the fixture names and add the columns immediately | ||
| 5 | +# below each fixture, per the syntax in the comments below | ||
| 6 | +# | ||
| 7 | +one: {} | ||
| 8 | +# column: value | ||
| 9 | +# | ||
| 10 | +two: {} | ||
| 11 | +# column: value |
Please
register
or
login
to post a comment