Project

General

Profile

Actions

Feature #23894

open

Expose repository through REST API

Added by Daniel Dehennin about 8 years ago. Updated over 3 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
REST API
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:

Description

Hello,

The public REST API does not contains information about repository.

It seems that the only way to access repository information is through the repository WS, but there is only one key.

I would like to have repository information per project, like what I get with GET /sys/projects.xml?key=<WS KEY>.

We may only list repositories when adding an ?include=repositories:

  • for all projects GET /projects.json?include=repositories
    {
       "projects" : [
          {
             "identifier" : "project",
             "id" : 1,
             "name" : "Project Name",
         [...]
             "repositories" : [
                {
                   "id" : 1,
                   "identifier" : "",
                   "is_default" : true,
                   "type" : "Repository::Git",
                   "url" : "repositories/project-repo.git" 
                }
             ]
          }
       ],
       "limit" : 25,
       "total_count" : 1,
       "offset" : 0
    }
    
  • per project GET /projects/1.json?include=repositories
    {
       "project" : {
          "id" : 1,
          "identifier" : "project",
          "name" : "Project Name",
          "repositories" : [
             {
                "id" : 1,
                "identifier" : "",
                "is_default" : true,
                "url" : "repositories/project-repo.git",
                "type" : "Repository::Git" 
             }
          ]
       }
    }
    

Regards.


Files


Related issues

Related to Redmine - Feature #11977: REST API for repositoriesNew

Actions
Has duplicate Redmine - Patch #35612: Applied patches from #23894Closed

Actions
Actions #1

Updated by Daniel Dehennin about 8 years ago

I made a patch to include the repositories in projects API.

I'll work on adding a complete CRUD with two routes

  • per project under /projects/:id/repositories
  • global under /repositories

The patch was made against the Git repository.

Actions #2

Updated by Holger Just about 8 years ago

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.

Actions #3

Updated by Daniel Dehennin about 8 years ago

Holger Just wrote:

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 :(

Thanks, that's part of what I wanted to do, I'll include your patch in a branch of my Git and extend it to be a simple CRUD.

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:

[...]

If you intend to use both patches, the supplied data should be adapted so that both APIs provide similar data.

I agree, the :url is not very useful, I'm wondering about using it for a list of clone URLs but not all SCM support it.

Regards.

Actions #4

Updated by Toshi MARUYAMA about 8 years ago

  • Category set to REST API
Actions #5

Updated by Toshi MARUYAMA about 8 years ago

Actions #6

Updated by Holger Just over 3 years ago

  • Has duplicate Patch #35612: Applied patches from #23894 added
Actions #7

Updated by Holger Just over 3 years ago

  • Target version set to Candidate for next major release

Setting this as a candidate for the next major version.

Actions #8

Updated by Go MAEDA over 3 years ago

Holger Just wrote:

Setting this as a candidate for the next major version.

Could you update the patch for the latest trunk?

Actions #9

Updated by Jan Catrysse over 3 years ago

Could this be looked upon to? #23894
It's a small feature I made to add revision info and related issues by API.

Actions #10

Updated by Mischa The Evil over 3 years ago

Jan Catrysse wrote:

Could this be looked upon to? #23894

Given that you meant to write #35769: that's another feature not (directly) related to this one. This one is about adding repository information to the projects endpoint and to a proposed repositories endpoint, where yours is about adding related issues information to a newly proposed revision endpoint.

Actions #11

Updated by Mischa The Evil over 3 years ago

Go MAEDA wrote:

Holger Just wrote:

Setting this as a candidate for the next major version.

Could you update the patch for the latest trunk?

Go, I think it would be good to discuss first what actually needs to be integrated before we go any further. I.e. do you also think about adding what's proposed/patched/posted in note-1 by Daniel Dehennin, or not? Besides that, we should make sure that any API addition is documented with some basic test coverage at least.

Actions

Also available in: Atom PDF