Git Product home page Git Product logo

Comments (1)

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

Hey @nicieja,

I've started working on this PR. The plan is to add a callback in the Update model that triggers an Update::Done event whenever Update#done is saved as true. I'll also create a new event handler for this Update::Done event.

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 Update
class OnCommitCreated < Handler
on ::Commit::Created
sig { override.returns Update }
def run
Update.create(
sourced_at: event.commited_at,
account_id: event.account_id,
commit_id: event.id,
name: event.message,
type: :commit,
changelog:,
source:,
tags:
)
end
sig { returns T.nilable(Source) }
def source
@source ||= Source.find_by(repository_id: event.repository_id)
end
sig { returns Changelog }
def changelog
@changelog ||= Account.find(event.account_id).changelogs.first
end
sig { returns T::Array[String] }
def tags
[
event.author.fetch(:email)
]
end
end

# typed: false
# frozen_string_literal: true
class Commit
module Events
extend ActiveSupport::Concern
extend T::Helpers
abstract!
module Resource
include ::Resource
included do
attribute :id, String
attribute :account_id, String
attribute :repository_id, String
attribute :message, String
attribute :author, Hash
attribute :commited_at, T::Time
end
sig { params(commit: Commit).returns Hash }
def self.to_event(commit)
commit
.as_json(only: %i[id account_id repository_id message author])
.symbolize_keys
.merge(commited_at: commit.commited_at) # Needed for type safety
end
end
class Created < Event
include Resource
end
end

# typed: false
# frozen_string_literal: true
class Source
class OnTeamUpdated < Handler
on ::Team::Updated
delegate :account_id, :name, :status, to: :event
delegate :id, to: :event, prefix: :team
sig { override.returns T::Boolean }
def run
return false if source.blank?
source.update!(
account_id:,
team_id:,
status:,
name:
)
end
sig { returns T.nilable(Source) }
def source
@source ||= Source.find_by(team_id:)
end
end

# typed: false
# frozen_string_literal: true
class Source
class OnRepositoryUpdated < Handler
on ::Repository::Updated
delegate :account_id, :name, :status, to: :event
delegate :id, to: :event, prefix: :repository
sig { override.returns T::Boolean }
def run
return false if source.blank?
source.update!(
repository_id:,
account_id:,
status:,
name:
)
end
sig { returns T.nilable(Source) }
def source
@source ||= Source.find_by(repository_id:)
end
end

class Post
describe Publish do
let!(:user) { create(:user) }
let(:update) { create(:update, :commit, account: user.account) }
let(:post) { create(:post, user:) }
describe '#publish' do
subject(:command) { post.publish(publishable) }
let(:publishable) { true }
it 'sets status to published' do
expect { command }.to change(post, :status).from('draft').to('published')
end
context 'when reverting' do
let(:publishable) { false }
let(:post) { create(:post, :published, user:) }
it 'sets status back to draft' do
expect { command }.to change(post, :status).from('published').to('draft')
end
end
end
describe '#attach' do
subject(:command) { post.attach(updates) }
let(:updates) { [update.id] }
it 'sets post on updates' do
expect { command }.to change { update.reload.post_id }.from(nil).to(post.id)
end
end
describe '#detach' do
subject(:command) { post.detach(except: updates) }
let(:updates) { [] }
before { update.update!(post:) }
it 'removes post from updates' do
expect { command }.to change { update.reload.post_id }.from(post.id).to(nil)
end
context 'when excepting updates' do
let(:updates) { [update.id] }
it 'does not remove post from updates' do
expect { command }.not_to change(update, :post_id)
end
end
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.