• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

hulu/restfulgit: REST API for Git data

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

hulu/restfulgit

开源软件地址:

https://github.com/hulu/restfulgit

开源编程语言:

Python 100.0%

开源软件介绍:

RestfulGit: A Restful API for Git data

PyPI version Build Status Coverage Status Requirements Status Can I Use Python 3?

Provides a read-only restful interface for accessing data from Git repositories (local to the server). Modeled off the GitHub API for compatibility (see http://developer.github.com/v3/).

Requires:

  • Python 3
  • Flask
  • pygit2 (This project works ok with the latest version 1.0.1 as of Jan 2020), which itself requires the C library libgit2. Before installing the Python pygit2 package first install the libgit2 dependency:
    • On Mac brew install libgit2
    • On Linux sudo apt install libgit2-dev

Optional:

  • filemagic (= 1.6) (offers improved MIME-type guessing), which itself requires libmagic (= 5.11)
    Note: filemagic usage not yet tested with this Python 3 port, though filemagic is still the same version 1.6 as of Jan 2020

The restfulgit.app module is a valid WSGI application.

While the app can be run with python -m restfulgit.app -- this runs Flask in debug mode and should NOT be used in production. Instead, the app can be run with any WSGI server, such as gunicorn (pip install gunicorn; gunicorn restfulgit.app) (Note: If you haven't installed restfulgit into your Python environment, you may need to explicitly set PYTHONPATH when running the above commands.)

Example installation, config and run:

Assuming Mac.

brew install libgit2
cp example_config.py config.py

Edit config.py e.g. set the root directory to look for git repositories RESTFULGIT_REPO_BASE_PATH = '/tmp/myrepos/'

Create a virtual environment and install dependencies - assuming Pipenv:

pipenv --python 3
pipenv install
pipenv shell

otherwise set up a virtual enviroment using your favourite technique (if you choose to use a virtual environment) then run the usual pip -r requirements.txt

Running the server on a development machine:

export RESTFULGIT_CONFIG=/.../config.py
python -m restfulgit.app

The RESTFULGIT_CONFIG environment variable should point to the config.py you just edited.

The -m parameter restfulgit.app refers to the module path and thus to the file restfulgit/app.py where you can see this project's bootstrapping code for Flask.

Configuration

RestfulGit uses Flask's config system. See example_config.py for an example config file. If the $RESTFULGIT_CONFIG environment variable is set, RestfulGit will assume its value is a config filepath and will attempt to load its config from that file. If the variable is not set or the loading attempt fails, RestfulGit will then attempt to load its config from /etc/restfulgit.conf.py.

Config parameter Default value Description
RESTFULGIT_REPO_BASE_PATH (none) Root path for Git repositories. Restfulgit will look for 5 repositories deep in directory tree.
RESTFULGIT_DEFAULT_COMMIT_LIST_LIMIT 50 Number of most recent commits to return by default from the "commits" API endpoint.
RESTFULGIT_ENABLE_CORS False Whether to enable cross-origin resource sharing (CORS) headers for the API endpoints.
RESTFULGIT_CORS_ALLOWED_HEADERS [] (empty list) List of HTTP header names (strings) that are allowed be used by the client when making a CORS request.
RESTFULGIT_CORS_ALLOW_CREDENTIALS False Whether HTTP Cookies and HTTP Authentication information should be sent by the client when making a CORS request.
RESTFULGIT_CORS_MAX_AGE 30 days datetime.timedelta specifying how long the results of a CORS preflight request can be cached by clients.
RESTFULGIT_CORS_ALLOWED_ORIGIN * (all origins) Which origin is allowed to access the API endpoints using CORS.

--

All of these routes return JSON unless otherwise specified.

For repositories within directories slashes should be replaced with ; (semicolon). If there is ; in directory name, it can be encoded with ;;.

Commits

Retrieves a list of commit objects (in plumbing format):

GET /repos/:repo_key/git/commits/

optional: ?start_sha=:sha
optional: ?ref_name=:ref_name
optional: ?limit=:limit (default=50, or as specified by the config)
[
    {
        "sha": "f85df530d8413b0390364b291eb97d1cc5798dee",
        "url": "http://localhost:5000/repos/restfulgit/git/commits/f85df530d8413b0390364b291eb97d1cc5798dee/",
        "author": {
            "date": "2013-05-20T23:11:30Z",
            "name": "Rajiv Makhijani",
            "email": "[email protected]"
        },
        "committer": {
            "date": "2013-05-20T23:11:30Z",
            "name": "Rajiv Makhijani",
            "email": "[email protected]"
        },
        "tree": {
            "url": "http://localhost:5000/repos/restfulgit/git/trees/4c392547aa3d644877f3b22e198a5caac99a69a3/",
            "sha": "4c392547aa3d644877f3b22e198a5caac99a69a3"
        },
        "parents": [
            {
                "url": "http://localhost:5000/repos/restfulgit/git/commits/7b3f40ff9aba370a59732522420201b744297317/",
                "sha": "7b3f40ff9aba370a59732522420201b744297317"
            }
        ],
        "message": "Renamed main api file, added production recommendation to README"
    },
    ...
]

Retrieves a specific commit object (plumbing format) given its SHA:

GET /repos/:repo_key/git/commits/:sha/

Retrieves a specific commit object (porcelain format) given a branch name, tag name, or commit SHA:

GET /repos/:repo_key/commits/:refspec/
{
    "sha": "07b9bf1540305153ceeb4519a50b588c35a35464",
    "url": "http://localhost:5000/repos/restfulgit/commits/07b9bf1540305153ceeb4519a50b588c35a35464/",
    "files": [
        {
            "filename": "api.py",
            "status": "added",
            "sha": "ae9d90706c632c26023ce599ac96cb152673da7c",
            "raw_url": "http://localhost:5000/repos/restfulgit/raw/07b9bf1540305153ceeb4519a50b588c35a35464/api.py",
            "contents_url": "http://localhost:5000/repos/restfulgit/contents/api.py?ref=07b9bf1540305153ceeb4519a50b588c35a35464",
            "changes": 179,
            "additions": 179,
            "deletions": 0,
            "patch": ...,
        }
    ],
    "stats": {
        "additions": 179,
        "deletions": 0,
        "total": 179
    },
    "author": {
        "date": "2013-02-24T13:25:46Z",
        "name": "Rajiv Makhijani",
        "email": "[email protected]"
    },
    "committer": {
        "date": "2013-02-24T13:25:46Z",
        "name": "Rajiv Makhijani",
        "email": "[email protected]"
    },
    "parents": [],
    "commit": {
        "committer": {
            "date": "2013-02-24T13:25:46Z",
            "name": "Rajiv Makhijani",
            "email": "[email protected]"
        },
        "author": {
            "date": "2013-02-24T13:25:46Z",
            "name": "Rajiv Makhijani",
            "email": "[email protected]"
        },
        "url": "http://localhost:5000/repos/restfulgit/git/commits/07b9bf1540305153ceeb4519a50b588c35a35464/",
        "tree": {
            "url": "http://localhost:5000/repos/restfulgit/git/trees/6ca22167185c31554aa6157306e68dfd612d6345/",
            "sha": "6ca22167185c31554aa6157306e68dfd612d6345"
        },
        "sha": "07b9bf1540305153ceeb4519a50b588c35a35464",
        "parents": [],
        "message": "Initial support for read-only REST api for Git plumbing"
    }
}

Retrieves a diff of the changes in a given commit (specified by branch name, tag name, or commit SHA):

GET /repos/:repo_key/commit/:refspec.diff
Content-Type: text/x-diff; charset=utf-8

diff --git a/api.py b/api.py
new file mode 100644
index 0000000..ae9d907
--- /dev/null
+++ b/api.py
@@ -0,0 +1,179 @@
+from flask import Flask, url_for
...

Given two commits, retrieves as good a common ancestor commit as possible for a merge. If there is no common ancestor, returns null (and HTTP 200 OK).

GET /repos/<repo_key>/git/commits/<sha:left_sha>/merge-base/<sha:right_sha>/
{
    "committer": {
        "date": "2013-02-24T13:25:46Z",
        "name": "Rajiv Makhijani",
        "email": "[email protected]"
    },
    "author": {
        "date": "2013-02-24T13:25:46Z",
        "name": "Rajiv Makhijani",
        "email": "[email protected]"
    },
    "url": "http://localhost:5000/repos/restfulgit/git/commits/07b9bf1540305153ceeb4519a50b588c35a35464/",
    "tree": {
        "url": "http://localhost:5000/repos/restfulgit/git/trees/6ca22167185c31554aa6157306e68dfd612d6345/",
        "sha": "6ca22167185c31554aa6157306e68dfd612d6345"
    },
    "sha": "07b9bf1540305153ceeb4519a50b588c35a35464",
    "parents": [],
    "message": "Initial support for read-only REST api for Git plumbing"
}

Branches

Retrieves a list of branches:

GET /repos/:repo_key/branches/
[
    {
        "name": "master",
        "commit": {
            "url": "http://localhost:5000/repos/restfulgit/commits/7ad9ae851a4491ab55042bccbab24fc8d740aaea/",
            "sha": "7ad9ae851a4491ab55042bccbab24fc8d740aaea"
        }
    },
    ...
]

Retrieves a specific branch object:

GET /repos/:repo_key/branches/:branch_name/
{
    "name": "master",
    "url": "http://localhost:5000/repos/restfulgit/branches/master/",
    "commit": {
        "sha": "dc745192fba83adc48361c36f73d0c7b6e060ed3",
        "url": "http://localhost:5000/repos/restfulgit/commits/dc745192fba83adc48361c36f73d0c7b6e060ed3/",
        "committer": {
            "date": "2014-05-09T18:38:19Z",
            "name": "Chris Rebert",
            "email": "[email protected]"
        },
        "author": {
            "date": "2014-05-09T18:38:19Z",
            "name": "Chris Rebert",
            "email": "[email protected]"
        },
        "parents": [
            {
                "sha": "6c1626a0d07e4bcfdbee4a11c898199a6f7d07b6",
                "url": "http://localhost:5000/repos/restfulgit/commits/6c1626a0d07e4bcfdbee4a11c898199a6f7d07b6/"
            }
        ],
        "commit": {
            "sha": "dc745192fba83adc48361c36f73d0c7b6e060ed3",
            "url": "http://localhost:5000/repos/restfulgit/git/commits/dc745192fba83adc48361c36f73d0c7b6e060ed3/",
            "committer": {
                "date": "2014-05-09T18:38:19Z",
                "name": "Chris Rebert",
                "email": "[email protected]"
            },
            "author": {
                "date": "2014-05-09T18:38:19Z",
                "name": "Chris Rebert",
                "email": "[email protected]"
            },
            "tree": {
                "url": "http://localhost:5000/repos/restfulgit/git/trees/3c02cb0f836416718a76d853583c3aae37c1dff7/",
                "sha": "3c02cb0f836416718a76d853583c3aae37c1dff7"
            },
            "parents": [
                {
                    "url": "http://localhost:5000/repos/restfulgit/commits/6c1626a0d07e4bcfdbee4a11c898199a6f7d07b6/",
                    "sha": "6c1626a0d07e4bcfdbee4a11c898199a6f7d07b6"
                }
            ],
            "message": "document commit-in-porcelain-format endpoint in README"
        }
    },
    "_links": {
        "self": "http://localhost:5000/repos/restfulgit/branches/master/"
    }
}

Retrieves a list of other branches that have been merged into the given branch:

GET /repos/:repo_key/branches/:branch_name/merged/
[
    {
        "name": "ambiguous",
        "commit": {
            "sha": "1f51b91ac383806df9d322ae67bbad3364f50811",
            "url": "http://localhost/repos/restfulgit/commits/1f51b91ac383806df9d322ae67bbad3364f50811/",
        }
    },
    ...
]

Retrieves a list of commits that are unique to the branch (not in any other ref), sorted either chronologically or topologically:

GET /repos/example/branches/:branch_name/unique-commits/sorted/chronological/
GET /repos/example/branches/:branch_name/unique-commits/sorted/topological/
{
    "commits": [
        {
            "sha": "c655dffe0fed2a78dc5f38c1bc8e5628e2605017",
            "url": "http://localhost/repos/my-project/commits/c655dffe0fed2a78dc5f38c1bc8e5628e2605017/",
            "commit": {
                "sha": "c655dffe0fed2a78dc5f38c1bc8e5628e2605017",
                "url": "http://localhost/repos/example/git/commits/c655dffe0fed2a78dc5f38c1bc8e5628e2605017/",
                "author": {...},
                "committer": {...},
                "message": "",
                "parents": [...],
                "tree": {...}
            },
            "author": {...},
            "committer": {...},
            "parents": [...]
        },
        ...
    ]
}

Blobs

Retrieves a specific blob object:

GET /repos/:repo_key/git/blobs/:sha/
{
    "url": "http://localhost:5000/repos/restfulgit.git/git/blobs/0d20b6487c61e7d1bde93acf4a14b7a89083a16d/",
    "sha": "0d20b6487c61e7d1bde93acf4a14b7a89083a16d",
    "encoding": "utf-8",
    "data": "*.pyc ",
    "size": 6
}

Trees

Retrieves a specific tree object:

GET /repos/:repo_key/git/trees/:sha/

optional: ?recursive=:zero_or_one (default=0, non-recursive)
{
    "url": "http://localhost:5000/repos/restfulgit.git/git/trees/4c392547aa3d644877f3b22e198a5caac99a69a3/",
    "sha": "4c392547aa3d644877f3b22e198a5caac99a69a3",
    "tree": [
        {
            "url": "http://localhost:5000/repos/restfulgit.git/git/blobs/0d20b6487c61e7d1bde93acf4a14b7a89083a16d/",
            "sha": "0d20b6487c61e7d1bde93acf4a14b7a89083a16d",
            "mode": "0100644",
            "path": ".gitignore",
            "type": "blob",
            "size": 6
        },
        ...
    ]
}

Tags

Retrieves a list of tags:

GET /repos/:repo_key/tags/
[
    {
        "name": "initial",
        "url": "http://localhost:5000/repos/restfulgit/tags/initial/",
        "commit": {
            "url": "http://localhost:5000/repos/restfulgit/commits/07b9bf1540305153ceeb4519a50b588c35a35464/",
            "sha": "07b9bf1540305153ceeb4519a50b588c35a35464"
        }
    },
    ...
]

Retrieves a specific tag object by name:

GET /repos/:repo_key/tags/:tag_name/
{
    "name": "initial",
    "url": "http://localhost:5000/repos/restfulgit/tags/initial/",
    "tag": {
        "message": "initial commit\n",
        "object": {
            "sha": "07b9bf1540305153ceeb4519a50b588c35a35464",
            "type": "commit",
            "url": "http://localhost:5000/repos/restfulgit/git/commits/07b9bf1540305153ceeb4519a50b588c35a35464/"
        },
        "sha": "1dffc031c9beda43ff94c526cbc00a30d231c079",
        "tag": "initial",
        "tagger": {
            "date": "2013-09-28T01:14:09Z",
            "email": "[email protected]",
            "name": "Chris Rebert"
        },
        "url": "http://localhost:5000/repos/restfulgit/git/tags/1dffc031c9beda43ff94c526cbc00a30d231c079/"
    },
    "commit": {
        "author": {
            "date": "2013-02-24T13:25:46Z",
            "email": "[email protected]",
            "name": "Rajiv Makhijani"
        },
        "commit": {
            "author": {
                "date": "2013-02-24T13:25:46Z",
                "email": "[email protected]",
                "name": "Rajiv Makhijani"
            },
            "committer": {
                "date": "2013-02-24T13:25:46Z",
                "email": "[email protected]",
                "name": "Rajiv Makhijani"
            },
            "message": "Initial support for read-only REST api for Git plumbing",
            "parents": [],
            "sha": "07b9bf1540305153ceeb4519a50b588c35a35464",
            "tree": {
                "sha": "6ca22167185c31554aa6157306e68dfd612d6345",
                "url": "http://localhost:5000/repos/restfulgit/git/trees/6ca22167185c31554aa6157306e68dfd612d6345/"
            },
            "url": "http://localhost:5000/repos/restfulgit/git/commits/07b9bf1540305153ceeb4519a50b588c35a35464/"
        },
        "committer": {
            "date": "2013-02-24T13:25:46Z",
            "email": "[email protected]",
            "name": "Rajiv Makhijani"
        },
        "parents": [],
        "sha": "07b9bf1540305153ceeb4519a50b588c35a35464",
        "url": "http://localhost:5000/repos/restfulgit/commits/07b9bf1540305153ceeb4519a50b588c35a35464/"
    }
}

Retrieves a specific tag object by SHA:

GET /repos/:repo_key/git/tags/:tag_sha/
{
    "url": "http://localhost:5000/repos/restfulgit.git/git/tags/89571737c474fae7ea4c092b5ed94e4eccb11b2a/",
    "object": {
        "url": "http://localhost:5000/repos/restfulgit.git/git/commits/b6b05bb0f230b591d82fcc07d169b7453e04cf89/",
        "sha": "b6b05bb0f230b591d82fcc07d169b7453e04cf89",
        "type": "commit"
    },
    "sha": "89571737c474fae7ea4c092b5ed94e4eccb11b2a",
    "tag": "v0.1",
    "tagger": {
        "date": "2013-09-13T04:00:28Z",
        "name": "Rajiv Makhijani",
        "email": "[email protected]"
    },
    "message": "this is our first release"
}

Refs

Retrieves a list of refs:

GET /repos/:repo_key/git/refs/

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap