From 8bae0dbbdd57af41a872be227adc4b2650d2a878 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 12 Jul 2019 23:29:02 +0200 Subject: [PATCH 1/3] Add puppet-forge wrapper --- app/lib/forge.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 app/lib/forge.rb diff --git a/app/lib/forge.rb b/app/lib/forge.rb new file mode 100644 index 00000000..40303dec --- /dev/null +++ b/app/lib/forge.rb @@ -0,0 +1,15 @@ +class Forge + def self.user + @user ||= ( + PuppetForge.user_agent = "vox-pupuli-tasks" + PuppetForge::User.find('puppet') + ) + end + + def self.module(query) + # this should never find two modules. + # It will find zero modules if we never did a release + # returns `nil` if zero + @module ||= @user.modules.where(query: query).first + end +end From 9d8739d61331d6506373213d39d90773a42deb4f Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 12 Jul 2019 23:29:20 +0200 Subject: [PATCH 2/3] add module model --- app/models/module.rb | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 app/models/module.rb diff --git a/app/models/module.rb b/app/models/module.rb new file mode 100644 index 00000000..8c180bc8 --- /dev/null +++ b/app/models/module.rb @@ -0,0 +1,4 @@ +# a module represents a release on https://forge.puppet.com/ +class Module < ApplicationRecord + belongs_to :repository +end From c4ec9844ca4d350026ae1f7fe3cd8c4c7251c72d Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 12 Jul 2019 23:29:42 +0200 Subject: [PATCH 3/3] update repository model to support modules --- app/lib/forge.rb | 8 +++++--- app/models/module.rb | 2 ++ app/models/repository.rb | 10 ++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/lib/forge.rb b/app/lib/forge.rb index 40303dec..f81c6c0f 100644 --- a/app/lib/forge.rb +++ b/app/lib/forge.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + class Forge def self.user - @user ||= ( - PuppetForge.user_agent = "vox-pupuli-tasks" + @user ||= begin + PuppetForge.user_agent = 'vox-pupuli-tasks' PuppetForge::User.find('puppet') - ) + end end def self.module(query) diff --git a/app/models/module.rb b/app/models/module.rb index 8c180bc8..8a4aab54 100644 --- a/app/models/module.rb +++ b/app/models/module.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # a module represents a release on https://forge.puppet.com/ class Module < ApplicationRecord belongs_to :repository diff --git a/app/models/repository.rb b/app/models/repository.rb index 9a277b89..35e2dd70 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -15,6 +15,7 @@ class Repository < ApplicationRecord primary_key: :github_id, foreign_key: :gh_repository_id, inverse_of: :repository) + has_one :module ## # Checks if the given Repository name is in our application scope (a module) @@ -76,4 +77,13 @@ def update_pull_requests(only_open: false) pull_requests.count end + + def update_forge_module + # we should save the json in Redis and cache it + content = Github.client.contents("voxpupuli/#{name}", path: 'metadata.json', query: { ref: 'master' }) + metadata = content[:content] + module_name = JSON.load(Base64.decode64(metadata))['name'] + # somehow save the result from the following lib in the module model + Forge.module(module_name) + end end