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

validate a PR after every PR update / prevent loops #179

Merged
merged 1 commit into from
May 10, 2020
Merged
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
10 changes: 5 additions & 5 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2020-05-07 22:11:39 +0200 using RuboCop version 0.82.0.
# on 2020-05-10 12:20:17 +0200 using RuboCop version 0.82.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 13
# Offense count: 12
# Configuration parameters: IgnoredMethods.
Metrics/AbcSize:
Max: 42
Max: 41

# Offense count: 2
# Configuration parameters: CountComments, ExcludedMethods.
Expand All @@ -20,9 +20,9 @@ Metrics/BlockLength:
# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 123
Max: 122

# Offense count: 2
# Offense count: 1
# Configuration parameters: IgnoredMethods.
Metrics/CyclomaticComplexity:
Max: 7
Expand Down
21 changes: 9 additions & 12 deletions app/models/pull_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,8 @@ def validate(saved_changes)
# If we're running in development mode, we try to run read-only and won't modify PRs
return if Rails.env.development?

# Don't run through the validaten, if only the eligible_for_merge_comment attribute got updated
if saved_changes.keys.sort != %w[updated_at eligible_for_merge_comment].sort && mergeable.nil?
# check merge status and do work if required
validate_mergeable
end

# Don't run through the validaten, if only the eligible_for_ci_comment attribute got updated
return unless saved_changes.keys.sort != %w[updated_at eligible_for_ci_comment].sort
# check merge status and do work if required
validate_mergeable

# check CI status and do work if required
validate_status(saved_changes)
Expand All @@ -176,11 +170,14 @@ def validate(saved_changes)
private

##
# Since we want to be a fancy responsive application we to all the validation
# stuff which might result in some new querys and api requests asyncronously.

# Queue a job into sidekiq that runs the validate() method above
# validate() might use update() to change attributes which would trigger a new job
# To prevent loops, we filter `saved_changed` of those attributes and won't create new job if those are the only changed attributes
def queue_validation
ValidatePullRequestWorker.perform_async(id, saved_changes) if saved_changes? || mergeable.nil?
attributes = %w[eligible_for_merge_comment eligible_for_ci_comment]
return unless [saved_changes.keys & attributes].empty?

ValidatePullRequestWorker.perform_async(id, saved_changes)
end

def validate_mergeable
Expand Down