Skip to content

Commit

Permalink
Move code from Token::Rebuild to Token::Workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
vpereira committed Apr 30, 2021
1 parent 677d15b commit 5b59d1d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 51 deletions.
51 changes: 0 additions & 51 deletions src/api/app/models/token/rebuild.rb
Expand Up @@ -8,57 +8,6 @@ def call(options)
Backend::Api::Sources::Package.rebuild(project_from_association_or_params.name,
package_from_association_or_params.name,
options.slice(:repository, :arch))

# TODO: This will be done beforehand... so we can use that
# payload = SCMExtractor.new(options[:request]).call
#
# Pseudo code for SCMExtractor
# - is it GitHub or GitLab
# - retrieve the webhook payload
# - return the fields we need
#
# payload would contain the following:
# GitHub:
# {
# scm: :github,
# repository_owner: 'openSUSE',
# repository_name: 'open-build-service',
# commit_sha: okgofdkgok4305045ofkodkgodfkg
# }
# GitLab:
# {
# scm: :gitlab,
# project_id: 123
# commit_sha: ogfkgofdkgoo095043939
# }
#
# Just a test for GitHub
# payload = {
# scm: :github,
# repository_owner: 'vpereira',
# repository_name: 'test-repo',
# commit_sha: '1793ce9f361c9eb19c0874b209a43fc1faae41e9'
# }
#
# Just a test for GitLab
# payload = {
# scm: :gitlab,
# project_id: 26270676,
# commit_sha: '78139bf5d91ca3df43eebe8d3381544fd8e2d061'
# }

# TODO: Everything below is going to be in Token::Workflow once we have that model
['Event::BuildFail', 'Event::BuildSuccess'].each do |event|
EventSubscription.create!(eventtype: event,
receiver_role: 'watcher', # TODO: check if this makes sense
user: user,
channel: 'scm',
enabled: true,
token: self,
payload: payload)
end

SCMStatusReporter.new(payload, scm_token).call
end

def package_find_options
Expand Down
12 changes: 12 additions & 0 deletions src/api/app/models/token/workflow.rb
Expand Up @@ -12,6 +12,18 @@ def call(options)

return unless extractor.accepted_event_and_action?


['Event::BuildFail', 'Event::BuildSuccess'].each do |event|
EventSubscription.create!(eventtype: event,
receiver_role: 'watcher', # TODO: check if this makes sense
user: user,
channel: 'scm',
enabled: true,
token: self,
payload: payload)
end

SCMStatusReporter.new(extractor.extract, scm_token).call
# scm_extractor_payload = extractor.extract # returns { scm: 'github', repo_url: 'http://...' }

# Read configuration file
Expand Down

0 comments on commit 5b59d1d

Please sign in to comment.