Changeset - 0b6982223baa
[Not reviewed]
beta
0 2 0
Marcin Kuzminski - 13 years ago 2013-04-22 14:11:53
marcin@python-works.com
cleanup code
2 files changed with 2 insertions and 4 deletions:
0 comments (0 inline, 0 general)
docs/api/api.rst
Show inline comments
 
.. _api:
 

	
 
===
 
API
 
===
 

	
 

	
 
Starting from RhodeCode version 1.2 a simple API was implemented.
 
There's a single schema for calling all api methods. API is implemented
 
with JSON protocol both ways. An url to send API request to RhodeCode is
 
<your_server>/_admin/api
 

	
 
API ACCESS FOR WEB VIEWS
 
++++++++++++++++++++++++
 

	
 
API access can also be turned on for each web view in RhodeCode that is
 
decorated with `@LoginRequired` decorator. To enable API access simple change
 
the standard login decorator to `@LoginRequired(api_access=True)`.
 

	
 
To make this operation easier, starting from version 1.7.0 there's a white list
 
of views that will have API access enabled. Simply edit `api_access_controllers_whitelist`
 
option in your .ini file, and define views that should have API access enabled.
 
Following example shows how to enable API access to patch/diff raw file and archive
 
in RhodeCode::
 

	
 
    api_access_controllers_whitelist = 
 
    api_access_controllers_whitelist =
 
        ChangesetController:changeset_patch,
 
        ChangesetController:changeset_raw,
 
        FilesController:raw,
 
        FilesController:archivefile
 

	
 

	
 
After this change, a rhodecode view can be accessed without login by adding a
 
GET parameter `?api_key=<api_key>` to url. By default this is only
 
enabled on RSS/ATOM feed views. Exposing raw diffs is a good way to integrate with
 
3rd party services like code review, or build farms that could download archives.
 

	
 

	
 
API ACCESS
 
++++++++++
 

	
 
All clients are required to send JSON-RPC spec JSON data::
 

	
 
    {
 
        "id:"<id>",
 
        "api_key":"<api_key>",
 
        "method":"<method_name>",
 
        "args":{"<arg_key>":"<arg_val>"}
 
    }
 

	
 
Example call for autopulling remotes repos using curl::
 
    curl https://server.com/_admin/api -X POST -H 'content-type:text/plain' --data-binary '{"id":1,"api_key":"xe7cdb2v278e4evbdf5vs04v832v0efvcbcve4a3","method":"pull","args":{"repo":"CPython"}}'
 

	
 
Simply provide
 
 - *id* A value of any type, which is used to match the response with the request that it is replying to.
 
 - *api_key* for access and permission validation.
 
 - *method* is name of method to call
 
 - *args* is an key:value list of arguments to pass to method
 

	
 
.. note::
 

	
 
    api_key can be found in your user account page
 

	
 

	
 
RhodeCode API will return always a JSON-RPC response::
 

	
 
    {
 
        "id":<id>, # matching id sent by request
 
        "result": "<result>"|null, # JSON formatted result, null if any errors
 
        "error": "null"|<error_message> # JSON formatted error (if any)
 
    }
 

	
 
All responses from API will be `HTTP/1.0 200 OK`, if there's an error while
 
calling api *error* key from response will contain failure description
 
and result will be null.
 

	
 

	
 
API CLIENT
 
++++++++++
 

	
 
From version 1.4 RhodeCode adds a script that allows to easily
 
communicate with API. After installing RhodeCode a `rhodecode-api` script
 
will be available.
 

	
 
To get started quickly simply run::
 

	
 
  rhodecode-api _create_config --apikey=<youapikey> --apihost=<rhodecode host>
 

	
 
This will create a file named .config in the directory you executed it storing
 
json config file with credentials. You can skip this step and always provide
 
both of the arguments to be able to communicate with server
 

	
 

	
 
after that simply run any api command for example get_repo::
 

	
 
 rhodecode-api get_repo
 

	
 
 calling {"api_key": "<apikey>", "id": 75, "args": {}, "method": "get_repo"} to http://127.0.0.1:5000
 
 rhodecode said:
 
 {'error': 'Missing non optional `repoid` arg in JSON DATA',
 
  'id': 75,
 
  'result': None}
 

	
 
Ups looks like we forgot to add an argument
 

	
 
Let's try again now giving the repoid as parameters::
 

	
 
    rhodecode-api get_repo repoid:rhodecode
 

	
 
    calling {"api_key": "<apikey>", "id": 39, "args": {"repoid": "rhodecode"}, "method": "get_repo"} to http://127.0.0.1:5000
 
    rhodecode said:
 
    {'error': None,
 
     'id': 39,
 
     'result': <json data...>}
 

	
 

	
 

	
 
API METHODS
 
+++++++++++
 

	
 

	
 
pull
docs/usage/general.rst
Show inline comments
 
@@ -32,128 +32,126 @@ if someone is viewing files at 'beta' br
 
checkbox the << and >> buttons will only show him revisions for 'beta' branch
 

	
 

	
 
Compare view from changelog
 
---------------------------
 

	
 
Checkboxes in compare view allow users to view combined compare view. You can
 
only show the range between the first and last checkbox (no cherry pick).
 
Clicking more than one checkbox will activate a link in top saying
 
`Show selected changesets <from-rev> -> <to-rev>` clicking this will bring
 
compare view. In this view also it's possible to switch to combined compare.
 

	
 
Compare view is also available from the journal on pushes having more than
 
one changeset
 

	
 

	
 
Non changeable repository urls
 
------------------------------
 

	
 
Due to complicated nature of repository grouping, often urls of repositories
 
can change.
 

	
 
example::
 

	
 
  #before
 
  http://server.com/repo_name
 
  # after insertion to test_group group the url will be
 
  http://server.com/test_group/repo_name
 

	
 
This can be an issue for build systems and any other hardcoded scripts, moving
 
repository to a group leads to a need for changing external systems. To
 
overcome this RhodeCode introduces a non changable replacement url. It's
 
simply an repository ID prefixed with `_` above urls are also accessible as::
 

	
 
  http://server.com/_<ID>
 

	
 
Since ID are always the same moving the repository will not affect such url.
 
the _<ID> syntax can be used anywhere in the system so urls with repo_name
 
for changelogs, files and other can be exchanged with _<ID> syntax.
 

	
 

	
 
Mailing
 
-------
 

	
 
When administrator will fill up the mailing settings in .ini files
 
RhodeCode will send mails on user registration, or when RhodeCode errors occur
 
on errors the mails will have a detailed traceback of error.
 

	
 

	
 
Mails are also sent for code comments. If someone comments on a changeset
 
mail is sent to all participants, the person who commited the changeset
 
(if present in RhodeCode), and to all people mentioned with @mention system.
 

	
 

	
 
Trending source files
 
---------------------
 

	
 
Trending source files are calculated based on pre defined dict of known
 
types and extensions. If You miss some extension or Would like to scan some
 
custom files it's possible to add new types in `LANGUAGES_EXTENSIONS_MAP` dict
 
located in `/rhodecode/lib/celerylib/tasks.py`
 

	
 

	
 
Cloning remote repositories
 
---------------------------
 

	
 
RhodeCode has an ability to clone remote repos from given remote locations.
 
Currently it support following options:
 

	
 
- hg  -> hg clone
 
- svn -> hg clone
 
- git -> git clone
 

	
 

	
 
.. note::
 

	
 
    - *`svn -> hg` cloning requires `hgsubversion` library to be installed.*
 

	
 
If you need to clone repositories that are protected via basic auth, you
 
might pass the url with stored credentials inside eg.
 
`http://user:passw@remote.server/repo`, RhodeCode will try to login and clone
 
using given credentials. Please take a note that they will be stored as
 
plaintext inside the database. RhodeCode will remove auth info when showing the
 
clone url in summary page.
 

	
 

	
 

	
 
Visual settings in admin pannel
 
-------------------------------
 

	
 

	
 
Visualisation settings in RhodeCode settings view are extra customizations
 
of server behavior. There are 3 main section in the settings.
 

	
 
General
 
~~~~~~~
 
    
 

	
 
`Use repository extra fields` option allows to set a custom fields for each
 
repository in the system. Each new field consists of 3 attributes `field key`,
 
`field label`, `field description`. Example usage of such fields would be to
 
define company specific information into repositories eg. defining repo_manager
 
key that would add give info about a manager of each repository. There's no
 
limit for adding custom fields. Newly created fields are accessible via API.
 

	
 

	
 
Icons
 
~~~~~
 

	
 
Show public repo icon / Show private repo icon on repositories - defines if
 
public/private icons should be shown in the UI.
 

	
 

	
 
Meta-Tagging
 
~~~~~~~~~~~~
 

	
 
With this option enabled, special metatags that are recognisible by RhodeCode
 
will be turned into colored tags. Currently available tags are::
 

	
 
    [featured]
 
    [stale]
 
    [dead]
 
    [lang => lang]
 
    [license => License]
 
    [requires => Repo]
 
    [recommends => Repo]
 
    [see => URI]
 

	
 

	
0 comments (0 inline, 0 general)