Git Product home page Git Product logo

Comments (2)

sweep-ai avatar sweep-ai commented on May 25, 2024

I'm sorry, but it looks like an error has occured. Try removing and re-adding the sweep label. I'll try again in a minute. If this error persists contact [email protected].


I'm a bot that handles simple bugs and feature requests but I might make mistakes. Please be kind!

from changepack.

sweep-ai avatar sweep-ai commented on May 25, 2024

Hey @nicieja,

I've started working on this PR. The plan is to create a new spec file pullable_spec.rb under spec/controllers/concerns/ where we'll define a dummy controller, include the Pullable concern in it, and write tests for the methods provided by Pullable. We'll also mock the necessary methods to simulate the behavior of the including controllers.

Give me a minute!

Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description.

# typed: false
# frozen_string_literal: true
class Commit
module Pull
extend ActiveSupport::Concern
extend T::Helpers
extend T::Sig
include Provided
abstract!
included do
provider :github
end
class_methods do
extend T::Sig
sig { overridable.params(repository: Repository).returns(T::Boolean) }
def pull(repository)
transaction do
source = Pull.source(repository)
repository.git
.commits(source, after: repository.cursor)
.each { |commit| Pull.upsert!(commit, repository:) }
repository.update!(pulled_at: Time.current)
end
true
end
end
sig { params(attributes: Hash, repository: Repository).returns(Commit) }
def self.upsert!(attributes, repository:)
providers = attributes.fetch(:providers)
repository_id = repository.id
Commit
.lock
.find_or_initialize_by(repository_id:, providers:)
.tap { |commit| commit.update!(attributes) }
end
sig { params(repository: Repository).returns T.nilable(T::Integer) }
def self.source(repository)
case repository.provider
when 'github'
repository.github
end
end
end

module Settings
extend ActiveSupport::Concern
extend T::Helpers
abstract!
module ClassMethods
attr_accessor :transition_class, :state_machine, :transition_name
end
included do |base|
@transition_class = "#{base.name}Transition".constantize # rubocop:disable Sorbet/ConstantsFromStrings
@state_machine = "#{base.name}StateMachine".constantize # rubocop:disable Sorbet/ConstantsFromStrings
@transition_name = :transitions
end
end
included do |base|
base.include Settings
base.include Base
base.include Statesman::Adapters::ActiveRecordQueries[transition_class:, initial_state:, transition_name:]

# typed: false
# frozen_string_literal: true
class TeamsController < ApplicationController
include Pullable
private
sig { override.returns Team }
def resource
@resource ||= authorized(Team.all).find(id)
end
sig { override.returns T::Locals }
def item
{
locals: { team: resource }
}
end
sig { override.params(_resource: Team).returns String }
def after_transition_path_for(_resource)
sources_path
end
end

# typed: false
# frozen_string_literal: true
class RepositoriesController < ApplicationController
include Pullable
private
sig { override.returns Repository }
def resource
@resource ||= authorized(Repository.all).find(id)
end
sig { override.returns T::Locals }
def item
{
locals: { repository: resource }
}
end
sig { override.params(_resource: Repository).returns String }
def after_transition_path_for(_resource)
sources_path
end
end

# typed: false
# frozen_string_literal: true
module Pullable
extend ActiveSupport::Concern
extend T::Helpers
extend T::Sig
interface!
def confirm_update
authorize! resource, to: :update? and render item
end
def update
authorize! resource
resource.transition_to!(:active)
redirect_to after_transition_path_for(resource)
end
def confirm_destroy
authorize! resource, to: :destroy? and render item
end
def destroy
authorize! resource
resource.transition_to!(:inactive)
redirect_to after_transition_path_for(resource)
end
private
sig { abstract.returns ApplicationRecord }
def resource; end
sig { abstract.returns T::Locals }
def item; end
sig { abstract.params(resource: T.untyped).returns String }
def after_transition_path_for(resource); end
end


I'm a bot that handles simple bugs and feature requests but I might make mistakes. Please be kind!

from changepack.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.