プロジェクト

全般

プロフィール

Vote #77826

未完了

Expose repository through REST API

Admin Redmine さんが3年以上前に追加. 3年以上前に更新.

ステータス:
New
優先度:
通常
担当者:
-
カテゴリ:
REST API_32
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
32
version_id:
32
issue_org_id:
23894
author_id:
45902
assigned_to_id:
0
comments:
11
status_id:
1
tracker_id:
2
plus1:
0
affected_version:
closed_on:
affected_version_id:
ステータス-->[New]

説明

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=@.

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.


journals

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.
--------------------------------------------------------------------------------
As an alternative to the proposed patch by Daniel (or maybe in addition to it), we at "Planio":http://plan.io/redmine-hosting 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:

<pre><code class="ruby">
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
</code></pre>

If you intend to use both patches, the supplied data should be adapted so that both APIs provide similar data.
--------------------------------------------------------------------------------
Holger Just wrote:
> As an alternative to the proposed patch by Daniel (or maybe in addition to it), we at "Planio":http://plan.io/redmine-hosting 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.

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Setting this as a candidate for the next major version.
--------------------------------------------------------------------------------
Holger Just wrote:
> Setting this as a candidate for the next major version.

Could you update the patch for the latest trunk?
--------------------------------------------------------------------------------
Could this be looked upon to? #23894
It's a small feature I made to add revision info and related issues by API.
--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------


related_issues

relates,New,11977,REST API for repositories
duplicates,Closed,35612,Applied patches from #23894

Admin Redmine さんが3年以上前に更新

  • カテゴリREST API_32 にセット
  • 対象バージョンCandidate for next major release_32 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0