What is this module about?

Gitolite module (based in Gitosis module, that I created a few months ago) automates access rights on a set of git repositories managed by Gitolite. It integrates perfectly with Open Atrium, or with any site with Organic Groups module configured.

Each group defines a set of git repositores. Users in a group which have added an ssh key to their account can clone the repositories of that group.

This module adds the following interactions:

  • admin/settings/gitolite: allows you to set the url to your gitolite-admin repository.
  • When editing a group, a section called Gitolite lets you define git repositories for it.
  • When a user edits his account, a section called "SSH Keys" let's her add public keys (thanks to sshkey module).
  • There are three drush tasks involved:
    • 'gitolite' is the main task that will update your Gitolite configuration periodically.
    • 'gitolite-load-config' takes your current gitolite.conf and saves it at admin/settings/gitolite > Main configuration.
    • 'gitolite-load-keys' looks for public keys at gitolite's keydir directory and attempts to match them with your users email, adding them if so.

Why did I created it?

I started doing some sysadmin work on top of programming at ideup! and got fed up of very repetitive tasks such as grant me access to this repository or revoke access to all repositories to this guy. We use Open Atrium to manage our projects, and in most of the cases everyone in a group deals with the repositories we created for it in Gitolite, so it made sense to link together Atrium and Gitolite so they could talk to each other automatically.

In which scenarios it can be useful?

Generally in organizations where Drupal is used as a communication tool between groups and there is a considerable amount of git repositories related to each group.

How compatible is it with Drupal?

I wanted this module to run in a Drupal installation with the least dependencies as possible, so right now it works either at a Drupal site with modules Content, Text, Organic Groups and Sshkey enabled, or an Open Atrium with Sshkey module.

Where is it and what is its status?

The module is stable. I am currently writing functional tests for it. The next step will be to create a Drupal 7 version.

The module can be found at http://drupal.org/sandbox/juampy/1209492

CommentFileSizeAuthor
#5 drupal-gitolite-coder-review.patch6.77 KBao2

Comments

joachim’s picture

Status: Needs review » Needs work
Issue tags: -git

Nice to see this! Not sure how it all works yet, but looks promising :)

> 2. The Content Type where Gitolite repositories will be managed must be called
"group". Otherwise the module will fail to add the field that manages repositories
in a group (this is configured by default if you are using Open Atrium).

Is that enforced by OG too? IIRC any node type can be declared a group. Might be an idea to follow that.

> 3. Enable the module, clear the cache and go to admin/settings/gitolite. In the first
field, set your gitolite-admin url. In order to test it, run the following drush task:
[path to drush] gitolite-load-config
If the task completed with no errors, it will load the contents of your gitolite.conf
file into the field "Main configuration for gitolite.conf" at admin/settings/gitolite.

Can the testing be done in the GUI too?

Also, I think you can say

$ drush foo

instead of

[path to drush] foo

And also:

> set your gitolite-admin url

What is that? can you give an example?

> [path to drush] gitolite
Which does:
1. Clone gitolite-admin to a temporary directory.

Can this be done by pointing to an existing clone of the gitolite admin?

> crontab -e # opens your crontab console. Then type:
*/1 * * * * /path/to/php /path/to/drush gitolite --root=/root/directory/of/your/site

Euw... why can't this run through hook_cron()?

// $Id$
/**
 * @file
 */

The $Id is no longer needed. The @file block should say something!

    case 'admin/modules#description':

IIRC this is obsolete; set it in the info file instead.

> 'title' => 'Gitolite Administration',

Should be sentence case.

> 'type' => MENU_NORMAL_ITEM,

Superfluous.

juampynr’s picture

Issue tags: +git

Here are my replies:

> 2. The Content Type where Gitolite repositories will be managed must be called
"group". Otherwise the module will fail to add the field that manages repositories
in a group (this is configured by default if you are using Open Atrium).

>> Discussed at IRC, I will add a widget so the user can choose which content type will have the "Git repositories" field.

> 3. Enable the module, clear the cache and go to admin/settings/gitolite. In the first
field, set your gitolite-admin url. In order to test it, run the following drush task:
[path to drush] gitolite-load-config
If the task completed with no errors, it will load the contents of your gitolite.conf
file into the field "Main configuration for gitolite.conf" at admin/settings/gitolite.

Can the testing be done in the GUI too?
>> No it can't (or at least I could not find a way for it). The reason is that you need to run the "git clone" command, which uses a linux user who has an ssh key that gitolite recognizes and authorizes to clone the gitolite-admin repository.

Also, I think you can say

$ drush foo

instead of

[path to drush] foo

>> Updated: http://drupalcode.org/sandbox/juampy/1209492.git/commit/08cb86f

And also:

> set your gitolite-admin url

What is that? can you give an example?

>> Added examples:

> [path to drush] gitolite
Which does:
1. Clone gitolite-admin to a temporary directory.

Can this be done by pointing to an existing clone of the gitolite admin?
>> It could reuse the clone created last time, but it is faster to just erase it and clone it again, as it would complicate the logic having to check the status, pulling it, checking that there are no conflicts (if someone touches it). So, unless someone reports a performance issue with it (I doubt it, as this repository is very light), I would rather keep it as just cloning it every time the task runs.

> crontab -e # opens your crontab console. Then type:
*/1 * * * * /path/to/php /path/to/drush gitolite --root=/root/directory/of/your/site

Euw... why can't this run through hook_cron()?
>> Related to "Can the testing be done in the GUI too?". There are exec() calls which need SSH access. A solution would be to give the web server user (normally www-data) access to gitolite-admin.git. But I am not sure how this would behave when the admin runs cron either in the browser or in the command line.

// $Id$
/**
* @file
*/

The $Id is no longer needed. The @file block should say something!
>> Removed $Id$ references and added description for each @file block.

case 'admin/modules#description':

IIRC this is obsolete; set it in the info file instead.
>> Removed hook_help. The description was already at gitolite.info.

> 'title' => 'Gitolite Administration',

Should be sentence case.
>> Corrected.

> 'type' => MENU_NORMAL_ITEM,

Superfluous.
>> Removed

>> Some of these little corrections were fixed at http://drupalcode.org/sandbox/juampy/1209492.git/commit/5932bb7

juampynr’s picture

Regarding the following pending issue:

2. The Content Type where Gitolite repositories will be managed must be called
"group". Otherwise the module will fail to add the field that manages repositories
in a group (this is configured by default if you are using Open Atrium).

>> I have studied how organic groups sets up content types to be group nodes. They are defined at table og. I will work in the following change:
1 On hook_install, if there is just one group node, I will add the "Git repositores" field to it. That will be the typical behaviour.
2 If there is more than one content type configured as group node, I will add a form field at admin/settings/gitosis which must be set in order to use the module. This field will list content types from table og so the admin can select one of them in order to add the field "Git repositories".
3 Hook_uninstall will remove the field from the respective content type.

juampynr’s picture

Status: Needs work » Needs review

Done, now the installation process works this way:

  • If you are using Open Atrium, it installs the Git Repositories field in your Group content type.
  • If you are using Drupal, it will ask you at admin/settings/form to select a content type so it can add the field to it.

Code changes can be seen at the following commits:

This update completes all suggestions posted. The module needs more reviews to continue the process.

ao2’s picture

StatusFileSize
new6.77 KB

@juampy: you may want to run the code through the coder module: http://drupal.org/project/coder

There are still some minor things to fix:

Coder found 1 projects, 4 files, 1 critical warnings, 31 minor warnings, 0 warnings were flagged to be ignored

The attached patch fixes some of them:

  • Trailing spaces and indentation
  • A typo: s/Implemenation/Implementation/
  • drupal_set_message() want all the placeholder filtered, for the installation message I use something like that:
      drupal_set_message(st('Your module settings are available under <a href="@link">Administer > Site configuration > @module_name</a>.',
        array(
          '@link' => url('admin/settings/gitolite'),
          '@module_name' => 'Gitolite',
        )
      ));
    

Regards,
Antonio

juampynr’s picture

Phew, that was fast! I have reviewed, applied the patch. It can be seen at http://drupalcode.org/sandbox/juampy/1209492.git/commit/f247eec

Thanks!

univate’s picture

I have set this up in openatrium and can confirm it works. Looking over the code I can't see any major issues or problems with the code. I do have a few feature ideas but will post them in the issue queue for the module.

joachim’s picture

Issue tags: -git

You want http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_ge... rather than a clunky file_exists().

+  if (!variable_get('gitolite_content_type_name', FALSE)) {
+    $options = node_get_types('names');
+    $form['gitolite_node_types'] = array(
+      '#type' => 'radios',
+      '#title' => t('Select a content type to add the field "Git repositories" to'),
+      '#options' => $options,
+      '#default_value' => variable_get('gitolite_node_types', ''),
+      '#description' => t('This setting is mandatory for the module to work correcly. There  must be a content type acting as "group node".'),
+      '#required' => TRUE,
+    );
+  }
+  else {
+    $form['gitolite_repository'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Full URL of gitolite-admin repository'),
+      '#default_value' => variable_get('gitolite_repository', ''),
+      '#description' => t("The url of the gitolite-admin repository. For example 
+        'git@domain.to.my.repo:gitolite-admin.git'."),
+      '#required' => TRUE,
+    );

You seem to be showing different form elements depending on the situation. That seems a bit confusing. It's better to always show the content type selector but lock it once set, and explain in the description text 'this may not be changed'. Same as parts of CCK.

juampynr’s picture

Done @joachim.

At hook_install, instead of using the suggested drupal_get_profile() (just for Drupal 7 and 8), I am checking the value of the variable 'install_profile'.

Regarding the settings page form, now instead of showing/hiding the fields I am enabling/disabling them.

Commit details can be found at http://drupalcode.org/sandbox/juampy/1209492.git/commitdiff/88dfe81.

Cheers

juampynr’s picture

@univate, thanks for reviewing. If you have tested the module and verified it works, what it is pending to be tested/reviewed in order to get a "reviewed and tested by the community" status?

Cheers

univate’s picture

@juampy - I'm not completely familiar with the current review process, so not really in a position to confirm everything has been done to satisfy the review requirements. But for other reviewers I can confirm that the module works as specified.

The one issue I do have, is with the modules design. Which I think is relevant to the review process since I prefer to see drupal modules trying to solve problems in generic ways which other developers can then build off. So I would prefer to see the gitolite module as its own module that focuses just on the gitolite configurations files and not integrating with openatrium at all.

There is the possiblity of a lot of interesting permission based configurations that could be incorporated into the modules functionality. Giving users access to just read or write specific repositories or branches. With my own use of gitolite I have created sandbox areas where a user can create their own repositories, that functionality would be really cool to be configurable trough a drupal project management site.

Then it would be great to have a submodule that is a feature which is spaces aware so will work with openatrium and allows you to enable git repositories just on specific groups. I would probably also make each repo a new node so you could add a title, description and any other field to it. Then you could use the node permissions as the basis of permissions which are set in gitolite.

I'm not sure this is a big enough reason to not accept the module in its current form though.

juampynr’s picture

@univate, that is a good point. I think that what you are talking about can be achieved up to some extent through project versioncontrol_git. If that is the case, it could be possible to integrate gitolite with it to build a proper gitolite integration, and then offer gitolite_atrium as a submodule.

Please @sdboyer and @marvil07, could you throw in some light? Could gitolite module be built on top of versioncontrol_git or benefit from it anyhow?

marvil07’s picture

@juampy: It's great to see your interest on this topic. Actually I really wanted to have a open atrium integration, since some users there wanted some related features.

From the Version Control API perspective, you can re-use the abstraction there to integrate with gitosis/gitolite through Repository manager (ctools) plugins, actually there is an extension of the interface used for it at Version Control Git backend module. For a reference implementation, take a look to the default plugin provided by versioncontrol_git and the one used on d.o.

For the access control side you can integrate using vcs_auth (ctools) plugins. For reference implementation take a look to the two plugins provided by versioncontrol.

@sdboyer: Please correct me if I failed in guide somewhere here ;-)

sdboyer’s picture

@juampy - Yeah, let me second marvil07's comment that this is a great effort, I'm very excited to see it. And I'll also second the notion that it could (bordering on should) be built on top of the vc* suite. We've designed that whole system to be *the* way to keep track of repositories that you want to do something with. The visible functionality it provides does appear to be more oriented towards generating lists of commits, but tbh, that's the messiest stuff we have. Treating git repositories as entities, hooking into their events...that's the kind of thing the API is really great for.

What you're doing might require us to make some additions to the API to really be done comfortably, but we'd be super, super open to that. I'd even go so far as to say that we might want to roll the cck integration into vcapi's core. If you are interested The best place to really talk it over is probably irc, so please feel free to ping marvil07 or I in #drupal-vcs.

Integrating with vc* does pertain to @univate's comment in #11, in that it'd really be ideal if providing gitolite functionality was separate from integration with OA. Integration with OA is great, and something I've been hoping would happen for a while, but gitolite integration is a segment of functionality that's really useful outside of OA. So it'd be good to build in layers, gitolite first then OA on (even if it's contained in the same project package).

To be clear, your being granted an account is in no way predicated on your choice to integrate with vc* or not. I've done a very cursory review of the code, and it at least looks consistent with coding standards. I share some concerns over the logic & structure choices you've made - using crontab instead of hook_cron(), directly attaching to a node type instead of simply offering a CCK field + widget, no hook_requirements() verification that gitolite is installed/has been configured properly - but the approaches you've taken are very reasonable for first attempts. More importantly, though, it's not the policy to reject applications on the basis of how you've chosen to solve a problem - only that you have chosen an effective way to solve it.

I haven't actually tested the module out, otherwise I'd approve the application right now. Can someone verify that the module at least more or less works? If so, I'll wrap this up.

univate’s picture

I can confirm the module works as advertised - I have tested it.

I do agree with everything @sdboyer has stated in regard to the choice of how it has been implemented and would certainly like to also see it re-factored into separate layer. But would also support this application as is and look forward to continual development in this area.

juampynr’s picture

That is what I call feedback :-D.

I am up for a rewrite towards a solution with version_control_git at the bottom, and then write a small submodule for Open Atrium. The fact that some work will be needed in the version_control_api is a great excuse for me to contribute to that module whenever I get to that point by submitting patches (yummy!).

I propose to leave the current version at the 6.x.1.x branch, and start working on the above in a brand new 6.x.2.x branch. First, I need to study version_control and the links that @marvil07 suggested.

@univate, I am happy to have some help on it in case you are up for it.

A similar approach should be taken on Gitosis module, which is also waiting in the Project Applications queue.

Thanks everyone for the opinions and suggestions.

cweagans’s picture

So, between #14 and #15, I think we can safely say that this is RTBC.

@juampy, when you are ready to do a Drupal 7 port, please ping me. At some point, I will be developing an alternative to Open Atrium with Drupal 7. It will probably more closely resemble Redmine than OA. This will be a critical piece of functionality, so I'd be very interested in helping with the port.

cweagans’s picture

Status: Needs review » Reviewed & tested by the community

Forgot to set status >.<

jthorson’s picture

If, for any reason, this application was to be blocked, then please re-open #1163170: [D6] Gitosis on behalf of the applicant.

jthorson’s picture

juampy,

Saw your question in #drupal-codereview ... the next step is for a Git administrator to actually grant you the full project permission, after which they will mark the application 'fixed' (and you will see the 'Promote to full project' link in your sandbox).

sdboyer’s picture

Status: Reviewed & tested by the community » Fixed

wfm. @juampy, you've been granted full project permissions :) do find me in irc, please please!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

avpaderno’s picture

Title: Gitolite » [D6] Gitolite
Issue summary: View changes