Hi Ovanes,

answering inline below:


project = Project.find_by_slug "gitorious"
repository = project.repositories.find_by_name "mainline"
These two lines find a specific repository withing a project. What if I want to install hook for all repositories, because I run a private gitorious and would like the bug tracker to be notified if any of the repositories changes???

If you want to install a hook for *all* repositories, you could do something like this:

Repository.all.each do |repository|
  hook = repository.hooks.build
  hook.user = repository.user
  hook.url = "http://www.postbin.org/wqpx3l";
  hook.save
end

hook = repository.hooks.build
Creates a hook object for some repository.

Yep.

hook.user = repository.user
Do I just assign to the hook object a repository user? Or should I state here which user is going to be assigned. In other words is repository.user a property access, or a placeholder?
Repository.user is a property access to the User who originally created the repo (the underlying ORM in rails maps repository.user to a row in the User table). Assigning the same user to the hook creates a new relation from the hook to that user.



hook.save
This persists the hook in the DB?

Exactly.


I think the most interesting approach is to install hooks for particular repository pattern within a project, like:

project = Project.find_by_slug "gitorious"
repository = project.repositories.find_by_name "main*"

...

What you could do here is to first find all repositories with a certain pattern (see http://stackoverflow.com/questions/251345/activerecord-find-starts-with) for a discussion of ways to use partial/"LIKE" queries. Once you have the result e.g array of repositories, simple loop over, and update them all, like in the example I gave above.



--
best regards,
Thomas Kjeldahl Nilsson
http://gitorious.com

--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]

Reply via email to