diff --git a/app/controllers/api/github_webhooks_controller.rb b/app/controllers/api/github_webhooks_controller.rb index f06c0b7..e3e7dbd 100644 --- a/app/controllers/api/github_webhooks_controller.rb +++ b/app/controllers/api/github_webhooks_controller.rb @@ -9,8 +9,7 @@ def checks repository = Repository.find_by(github_id: repository_params[:id]) return render(json: { error: 'not_found' }, status: :not_found) if repository.blank? - last_check = repository.checks.last - return render(json: { error: 'conflict' }, status: :conflict) if last_check.present? && (last_check.created? || last_check.in_process?) + return render(json: { error: 'conflict' }, status: :conflict) if repository.being_checked? CheckRepositoryJob.perform_async(repository.id) render json: { message: 'created' }, status: :ok diff --git a/app/models/repository.rb b/app/models/repository.rb index c3c1adf..75b94c0 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -48,4 +48,8 @@ def check_enabled? def check_disabled? !check_enabled? end + + def being_checked? + checks.last.present? && (checks.last.created? || checks.last.in_process?) + end end