From c4ec9844ca4d350026ae1f7fe3cd8c4c7251c72d Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 12 Jul 2019 23:29:42 +0200 Subject: [PATCH] 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