Skip to content

Commit

Permalink
update repository model to support modules
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Feb 6, 2020
1 parent 9d8739d commit c4ec984
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/lib/forge.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 2 additions & 0 deletions app/models/module.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# a module represents a release on https://forge.puppet.com/
class Module < ApplicationRecord
belongs_to :repository
Expand Down
10 changes: 10 additions & 0 deletions app/models/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit c4ec984

Please sign in to comment.