Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Graph support #15

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions app/lib/forge.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

class Forge
def self.user
@user ||= begin
PuppetForge.user_agent = 'vox-pupuli-tasks'
PuppetForge::User.find('puppet')
end
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
6 changes: 6 additions & 0 deletions app/models/module.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

# a module represents a release on https://forge.puppet.com/
class Module < ApplicationRecord
belongs_to :repository
end
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


##
# 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' })
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

metadata = content[:content]
module_name = JSON.load(Base64.decode64(metadata))['name']
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# somehow save the result from the following lib in the module model
Forge.module(module_name)
end
end