As an alternative to the proposed patch by Daniel (or maybe in addition to it), we at Planio have already rolled out a read-only API for repositories related to #11977 which we provide in the attached patch. Unfortunately, we haven't managed to provide the patch earlier :(
You can call the API as http://redmine.example.com/repositories.json
. It supports the following optional parameters:
scm
: The type of repositories that should be shown. We support any of the registered repository types here. If no scm
is given or the type is unknown, we show all repositories visible to the current user.
include
: fetch associated data (optional, use comma to fetch multiple associations). Possible values:
branches
: Include known branches of the repository. This is only useful if the repository type knows the concept of branches like git or mercurial.
In the API response, we deliberately do not include the repository URL that is configured in Redmine. The reason for that is that most of the time, this URL won't be the one visible to clients. Instead, this is often a file system path (mandatory for at least git and mercurial) or an internal URL in the case of SVN. Instead, we offer an extension point for repository hosting plugins to easily add information they deem useful. This data can be fetched from the respective configuration of the plugin. Alternatively, an administrator setting up their internal Redmine with tools like Redmine.pm
can easily write a very simple plugin which hooks into the API to provide this information. This could look like this:
Redmine::Plugin.register :redmine_my_repositories do
name 'My Repositories'
author 'John Doe'
description 'Add custom repository information to the API'
version '1.0.0'
end
module MyRepositories
class ApiHooks < Redmine::Hook::Listener
def api_repositories_index(context)
render_repository_urls(context[:api], context[:repository])
end
private
def render_repository_urls(api, repository)
if repository.is_a? Repository::Subversion
api.svn_url "https://#{Setting.hostname}/svn/#{[repository.project.identifier, repository.identifier].compact.join('/')}
elsif repository.is_a? Repository::Git
api.git_url "git@#{Setting.hostname}:#{[repository.project.identifier, repository.identifier].compact.join('/')}
end
end
end
end
If you intend to use both patches, the supplied data should be adapted so that both APIs provide similar data.