Repositories

Repository API

1. Get a tree

Request

GET https://api.gitcode.com/api/v5/repos/{owner}/{repo}/git/trees/{sha}

Parameters

ParameterDescriptionTypeData Type
access_token*personal access tokenquerystring
owner*Repository Owner Path (Organization or User Path)pathstring
repo*Repository Path(path)pathstring
sha*Can be a branch name (e.g., master), a commit SHA, or a directory tree SHApathstring
pageCurrent Page Numberqueryint
per_pageItems Per Page, Maximum 100queryint
recursiveSet to 1 to recursively retrieve the directoryqueryint

Response

{
    "tree": [
        {
            "sha": "5259c4b24f015ffdc3663e81837a730c2a108e1f",
            "name": "b",
            "type": "tree",
            "path": "a/b",
            "mode": "040000",
            "md5": "a7e86136543b019d72468ceebf71fb8e"
        }
    ]
}

Demo

curl --location 'https://api.gitcode.com/api/v5/repos/xiaogang_test/test222/git/trees/main?access_token=?'

2. Retrieve Contents Under a Specific Repository Path

Request

GET https://api.gitcode.com/api/v5/repos/{owner}/{repo}/contents/{path}

Parameters

ParameterDescriptionTypeData Type
access_token*personal access tokenquerystring
owner*Repository Owner Path (Organization or User Path)pathstring
repo*Repository Path(path)pathstring
path*Path of the Filepathstring
refBranch, tag, or commit. Default: Repository’s default branch (main)querystring

Response

{
    "type": "file",
    "encoding": "base64",
    "size": 19,
    "name": "Note2.md",
    "path": "Note2.md",
    "content": "JXU2RDRCJXU4QkQ1d2ViaG9vaw==",
    "sha": "e5699fe1b360d6c799ee58b24fb5a670b1e14851",
    "url": "https://gitcode.com/api/v5/repos/daming_1/zhu_di/contents/Note2.md",
    "html_url": "https://gitcode.com/daming_1/zhu_di/blob/master/Note2.md",
    "download_url": "https://gitcode.com/daming_1/zhu_di/raw/master/Note2.md",
    "_links": {
        "self": "https://gitcode.com/api/v5/repos/daming_1/zhu_di/contents/Note2.md",
        "html": "https://gitcode.com/daming_1/zhu_di/blob/master/Note2.md"
    }
}

Demo

curl --location 'https://api.gitcode.com/api/v5/repos/xiaogang_test/test222/contents/1.txt?access_token=?&ref=main'

3. Get File List

Request

GET https://api.gitcode.com/api/v5/repos/{owner}/{repo}/file_list

Parameters

ParameterDescriptionTypeData Type
access_token*personal access tokenquerystring
owner*Repository Owner Path (Organization or User Path)pathstring
repo*Repository Path(path)pathstring
ref_nameref(Branch, tag, or commit)querystring
file_namefile namequerystring

Response

[
    "abc/test.rs",
    "bcd/test.rs"
]

Demo

curl --location 'https://api.gitcode.com/api/v5/repos/owner-test/secure-issue/file_list?access_token=******&file_name=%2Ftest.rs&ref_name=main'

4. Create File

Request

POST https://api.gitcode.com/api/v5/repos/{owner}/{repo}/contents/{path}

ParameterDescriptionTypeData Type
access_token*personal access tokenquerystring
owner*Repository Owner Path (Organization or User Path)pathstring
repo*Repository Path(path)pathstring
path*file pathpathstring
content*File content, must be Base64 encoded.bodystring
message*commit messagebodystring
branchbranchbodystring
author[name]author namebodystring
author[email]author emailbodystring

Response

{
    "commit": {
        "sha": "668cb104692b30d537b07f3721df9956d073d343",
        "author": {
            "name": "GitCode2023",
            "email": "13328943+gitcode_admin@user.noreply.gitcode.com",
            "date": "2024-04-11T09:15:20+00:00"
        },
        "committer": {
            "name": "Gitee",
            "email": "noreply@gitcode.com",
            "date": "2024-04-11T09:15:20+00:00"
        },
        "message": "22222"
        "parents": [
            {
                    "sha":
      "0117aa5c6bc8e33d18ad8911afa3cbb54a1faabe"
            }
        ]
    }
}

Demo

curl --location 'https://api.gitcode.com/api/v5/repos/xiaogang/test/contents/xg8.txt?access_token=?' \
--header 'Content-Type: application/json;charset=UTF-8' \
--data-raw '{
    "content":"你好你好",
    "message":"api提交",
    "author[name]":"xg1",
    "author[email]":"xg1@qq.com",
    "committer[name]":"xg2",
    "committer[email]":"xg2@qq.com"
}'

5. Update File

Request

PUT https://api.gitcode.com/api/v5/repos/{owner}/{repo}/contents/{path}

ParameterDescriptionTypeData Type
access_token*personal access tokenquerystring
owner*Repository Owner Path (Organization or User Path)pathstring
repo*Repository Path(path)pathstring
path*file pathpathstring
content*File content, must be Base64 encoded.bodystring
sha*文件的 Blob SHAbodystring
branchbranchbodystring
message*commit messagebodystring
author[name]author namebodystring
author[email]author emailbodystring

Response

{
    "content": {
        "name": "Note2.md",
        "path": "Note2.md",
        "url": "https://gitcode.com/api/v5/repos/daming_1/zhu_di/contents/Note2.md",
        "html_url": "https://gitcode.com/daming_1/zhu_di/blob/master/Note2.md",
        "download_url": "https://gitcode.com/daming_1/zhu_di/raw/master/Note2.md",
        "_links": {
            "self": "https://gitcode.com/api/v5/repos/daming_1/zhu_di/contents/Note2.md",
            "html": "https://gitcode.com/daming_1/zhu_di/blob/master/Note2.md"
        }
    }
}

Demo

curl --location --request PUT 'https://api.gitcode.com/api/v5/repos/xiaogang/test/contents/xg8.txt?access_token=?' \
--header 'Content-Type: application/json;charset=UTF-8' \
--data '{
    "content":"你好你好",
    "message":"api提交",
    "sha":"e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"
}'

6. Delete File

Request

DELETE https://api.gitcode.com/api/v5/repos/{owner}/{repo}/contents/{path}

ParameterDescriptionTypeData Type
access_token*personal access tokenquerystring
owner*Repository Owner Path (Organization or User Path)pathstring
repo*Repository Path(path)pathstring
path*file pathpathstring
sha*file Blob SHAbodystring
branchbranch namebodystring
message*commit messagebodystring

Response

{
    "commit": {
        "sha": "2a90c33ede2c1eafc5943727fd57129d870ad2e4",
        "author": {
            "name": "xiaogang",
            "email": "1150456356@qq.com",
            "date": "2024-11-25T02:11:56.000Z"
        },
        "committer": {
            "name": "xiaogang",
            "email": "1150456356@qq.com",
            "date": "2024-11-25T02:11:56.000Z"
        },
        "message": "api删除文件",
        "tree": "791f24a0da8c8458e40da3243bde183d59773514",
        "parents": [
            "33e9ee7ccd32835a0fb9f2af99264931c06fbe11"
        ]
    }
}

Demo

curl --location --request DELETE 'https://api.gitcode.com/api/v5/repos/testyl001/test001/contents/1/2/3/4/5/test.md?access_token={your-token}' \
--header 'Content-Type: application/json' \
--data '{
    "sha": "52cfcc97f43188d16050e6395d456fc61f085eb9",
    "message": "删除文件",
    "branch": "branch01"
}'

7. Get File Blob

Request

GET https://api.gitcode.com/api/v5/repos/{owner}/{repo}/git/blobs/{sha}

ParameterDescriptionTypeData Type
access_token*personal access tokenquerystring
owner*Repository Owner Path (Organization or User Path)pathstring
repo*Repository Path(path)pathstring
sha*blob shapathstring

Response

{
    "sha":"e5699fe1b360d6c799ee58b24fb5a670b1e14851",
    "size":19,
    "url":"https://gitcode.com/api/v5/repos/daming_1/zhu_di/git/blobs/e5699fe1b360d6c799ee58b24fb5a670b1e14851",
    "content":"JXU2RDRCJXU4QkQ1d2ViaG9vaw==",
    "encoding":"base64"
}

Demo

curl --location 'https://api.gitcode.com/api/v5/repos/xiaogang_test/test222/git/blobs/e69de29bb2d1d6434b8b29ae775ad8c2e48c5391?access_token=?' \

8. Get Repository Languages

Request

GET https://api.gitcode.com/api/v5/repos/{owner}/{repo}/languages

Parameters

ParameterDescriptionTypeData Type
access_token*personal access tokenformDatastring
owner*Repository Owner Path (Organization or User Path)pathstring
repo*Repository Path(path)pathstring

Response

Map<语言名称, 百分比>

{
    "Shell": 49.77,
    "Python": 50.23
}

Demo

curl --location 'https://api.gitcode.com/api/v5/repos/xiaogang_test/test222/languages?access_token=?' \

9. Get Repository Contributors

Request

GET https://api.gitcode.com/api/v5/repos/{owner}/{repo}/contributors

Parameters

ParameterDescriptionTypeData Type
access_token*personal access tokenquerystring
owner*Repository Ownership Path (Company, Organization, or Personal Path)pathstring
repo*Repository Path(path)pathstring
typeContributor Type(committers/authors)querystring

Response

[
    {
        "name": "dengmengmian",
        "contributions": 3,
        "email": "my@dengmengmian.com"
    }
]

Demo

curl --location 'https://api.gitcode.com/api/v5/repos/dengmengmian/oneapi/contributors?access_token=xxxx&type=committers'

10. Set Repository Modules

Request

PUT https://api.gitcode.com/api/v5/repos/{owner}/{repo}/module/setting

Parameters

ParameterDescriptionTypeData Type
access_token*personal access tokenformDatastring
owner*Repository Owner Path (Organization or User Path)pathstring
repo*Repository Path(path)pathstring
has_wikiwikibodyboolean
has_issueissuebodyboolean
has_securitysecurity issuebodyboolean
has_merge_requestmerge requestbodyboolean
has_forkfork allowedbodyboolean
has_analysisanalysisbodyboolean
has_discussiondiscussionbodyboolean

Response

When the response returns “success”, it indicates the operation was successful. Any other response would indicate failure.

{
    "msg": "success",
    "code": 1
}

Demo

curl --location --request PUT 'https://api.gitcode.com/api/v5/repos/testyl001/test001/module/setting?access_token={your-token}' \
--header 'Content-Type: application/json' \
--data '{
    "has_wiki": true,
}'

11. Update Repository Settings

Request

PATCH https://api.gitcode.com/api/v5/repos/{owner}/{repo}

ParameterDescriptionTypeData Type
access_token*personal access tokenquerystring
owner*Repository Owner Path (Organization or User Path)pathstring
repo*Repository Path(path)pathstring
name*Repository Namebodystring
descriptionRepository Descriptionbodystring
homepagehomepage, eg: https://gitcode.combodystring
pathRepository Pathbodystring
privateprivate: true/falsebodyboolean
default_branchdefault branchbodystring
lfs_enabledlfs enabledbodyboolean

Response

{
    "id": 34171993,
    "full_name": "daming_1/test_create_project_2",
    "human_name": "daming/test_create_project_2",
    "url": "https://gitcode.com/api/v5/repos/daming_1/test_create_project_2",

    "path": "test_create_project_2",
    "name": "test_create_project_2",

    "description": "Description",
    "private": false,
    "public": true,
    "namespace": {
        "id": 74962,
        "name": "group1111",
        "path": "group11111",
        "develop_mode": "normal",
        "region": null,
        "cell": "default",
        "kind": "group",
        "full_path": "group11111",
        "full_name": "group1111",
        "parent_id": null,
        "visibility_level": 20,
        "enable_file_control": false,
        "owner_id": null
    },
    "empty_repo": null,
    "starred": null,
    "visibility": "public",
    "owner": null,
    "creator": null,
    "forked_from_project": null,
    "item_type": null,
    "main_repository_language": null,
    "homepage": "http://www.baidi.com"
}

Demo

curl --location --request PATCH 'https://api.gitcode.com/api/v5/repos/testyl001/test001?access_token={your-token}' \
--header 'Content-Type: application/json' \
--data '{
    "name": "test002",
    "description": "1"
}'

12. Modify Repository Code Review Settings

Request

PUT https://api.gitcode.com/api/v5/repos/{owner}/{repo}/reviewer

Parameters

ParameterDescriptionTypeData Type
access_token*personal access tokenquerystring
owner*Repository Owner Path (Organization or User Path)pathstring
repo*Repository Path(path)pathstring
assignees*aprroval username, can provide multiple values, separated by commas. eg: (username1,username2)bodystring
testers*tester username, can provide multiple values, separated by commas. eg: (username1,username2)bodystring
assignees_number*Minimum number of approvalsbodyint
testers_number*Minimum number of testersbodyint

Response

{
    "id": 7543745,
    "created_at": "2024-01-24T14:33:44+08:00",
    "updated_at": "2024-04-07T21:23:08+08:00"
}

Demo

curl --location --request PUT 'https://api.gitcode.com/api/v5/repos/testyl001/test001/reviewer?access_token={your-token}' \
--header 'Content-Type: application/json' \
--data '{
    "assignees": "username1,username2",
    "testers": "username1,username2",
    "assignees_number": 1,
    "testers_number": 1
}'

13. Archive Repository

Request

PUT https://api.gitcode.com/api/v5/org/{org}/repo/{repo}/status

ParameterDescriptionTypeData Type
access_token*personal access tokenquerystring
org*Repository Ownership Path (Company, Organization, or Personal Path)pathstring
repo*Repository Path(path)pathstring
status*state, 0: open,2: archivedbodyint
password*passwordbodystring

Response

{
    "code": 1,
    "msg": "success"
}

Demo

curl --location --request PUT 'https://api.gitcode.com/api/v5/repos/testyl001/test001/reviewer?access_token={your-token}' \
--header 'Content-Type: application/json' \
--data '{
    "assignees": "username1,username2",
    "testers": "username1,username2",
    "assignees_number": 1,
    "testers_number": 1
}'

14. Transfer Repository

Request

POST https://api.gitcode.com/api/v5/org/{org}/projects/{repo}/transfer

ParameterDescriptionTypeData Type
access_token*personal access tokenquerystring
org*Repository Ownership Path (Company, Organization, or Personal Path)pathstring
repo*Repository Pathpathstring
transfer_to*target namespacebodystring
password*passwordbodystring

Response

{
    "code": 1,
    "msg": "success"
}

Demo

curl --location --request POST 'https://api.gitcode.com/api/v5/org/xiaogang/projects/test/transfer?access_token={your-token}' \
--header 'Content-Type: application/json' \
--data '{
    "transfer_to": "xiaogang_test",
    "password": "password"
}'

15. Get Repository Permission Mode

Request

GET https://api.gitcode.com/api/v5/repos/{owner}/{repo}/transition

Parameters

ParameterDescriptionTypeData Type
access_token*personal access tokenformDatastring
owner*Repository Owner Path (Organization or User Path)pathstring
repo*Repository Path(path)pathstring

Response

Permission mode 1, 2, where 1 is inheritance mode and 2 is independent mode.

{
    "memberMgntMode": 1
}

Demo

curl --location --request GET 'https://api.gitcode.com/api/v5/repos/xiaogang/test/transition?access_token={your-token}'

16. Update Repository Permission Mode

Request

PUT https://api.gitcode.com/api/v5/repos/{owner}/{repo}/transition

Parameters

ParameterDescriptionTypeData Type
access_token*personal access tokenformDatastring
owner*Repository Owner Path (Organization or User Path)pathstring
repo*Repository Path(path)pathstring
source_member_mgnt_mode*origin Permission modebodyint
target_member_mgnt_mode*new Permission modebodyint

Response

{
    "msg": "success",
    "code": 1
}

Demo

curl --location --request POST 'https://api.gitcode.com/api/v5/repos/xiaogang/test/transition?access_token={your-token}' \
--header 'Content-Type: application/json' \
--data '{
    "source_member_mgnt_mode": 1,
    "target_member_mgnt_mode": 2
}'

17. Set Repository Push Rules

Request

PUT https://api.gitcode.com/api/v5/repos/{owner}/{repo}/push_config

Parameters

ParameterDescriptionTypeData Type
access_token*personal access tokenformDatastring
owner*Repository Owner Path (Organization or User Path)pathstring
repo*Repository Path(path)pathstring
reject_not_signed_by_gpgOnly commits with verified signatures are allowedbodyboolean
commit_message_regexCommit message validationbodystring
max_file_sizeCommit file size limit (in MB)bodyInteger
skip_rule_for_ownerCommits by project administrators are not subject to the above rulesbodyboolean
deny_force_pushForce push is prohibited (including for administrators)bodyboolean

Response

返回参数含义参考 body

{
    "reject_not_signed_by_gpg": false,
    "deny_force_push": true,
    "max_file_size": 10,
    "skip_rule_for_owner": false
}

Demo

curl --location --request GET 'https://api.gitcode.com/api/v5/repos/gitcode-dev/euler-api-list/push_config' \
--header 'PRIVATE-TOKEN: {your-token}' \
--header 'Cookie: GitCodeUserName=bond007; HWWAFSESID=ac1f8735c7a0f5acb6; HWWAFSESTIME=1730276856784'

18. Get Repository Push Rules

Request

GET https://api.gitcode.com/api/v5/repos/{owner}/{repo}/push_config

Parameters

ParameterDescriptionTypeData Type
access_token*personal access tokenformDatastring
owner*Repository Owner Path (Organization or User Path)pathstring
repo*Repository Path(path)pathstring

Response

Return parameter meanings: refer to the body of setting project push rules.

{
    "reject_not_signed_by_gpg": false,
    "deny_force_push": true,
    "max_file_size": 10,
    "skip_rule_for_owner": false
}

Demo

curl --location --request PUT 'https://api.gitcode.com/api/v5/repos/gitcode-dev/euler-api-list/push_config' \
--header 'PRIVATE-TOKEN: {your-token}' \
--form 'deny_force_push="true"'

19. Delete a Repository

Request

DELETE https://api.gitcode.com/api/v5/repos/{owner}/{repo}

Parameters

ParameterDescriptionTypeData Type
access_token*personal access tokenformDatastring
owner*Repository Owner Path (Organization or User Path)pathstring
repo*Repository Path(path)pathstring

Response

Demo

curl --location --request DELETE 'https://api.gitcode.com/api/v5/repos/xiaogang/test?access_token={your-token}' \
--header 'Content-Type: application/json'

20. Create Organization Repository

Request

POST https://api.gitcode.com/api/v5/orgs/{org}/repos

Parameters

ParameterDescriptionTypeData Type
access_token*personal access tokenquerystring
name*Repository Namebodystring
descriptionRepository Descriptionbodystring
homepagehomepagebodystring
has_issuesTRUE Allow Issues to Be Created (Enabled/Disabled). Default: truebodyboolean
has_wikihas wiki. Default: truebodyboolean
auto_initWhen set to true, the repository will be initialized with a README. Default: Do not initialize (false).bodyboolean
gitignore_templategitignore templatebodystring
license_templatelicense templatebodystring
pathRepository Pathbodystring
privateprivate: true/falsebodyboolean
import_urlRepository import URL, which must end with .git, for example: https://github.com/apache/kafka.gitbodystring

Response

Return parameter meanings: Refer to the body for setting project push rules.

{
    "id": 729293,
    "full_name": "xiaogang/4",
    "human_name": "xiaogang / 4",
    "url": "https://api.gitcode.com/api/v5/repos/xiaogang/4",
    "namespace": {
        "id": 137117,
        "name": "xiaogang",
        "path": "xiaogang",
        "develop_mode": "normal",
        "kind": "user",
        "full_path": "xiaogang",
        "full_name": "xiaogang",
        "visibility_level": 20,
        "enable_file_control": false,
        "owner_id": 496
    },
    "path": "4",
    "name": "4",
    "private": true,
    "public": false,
    "visibility": "private"
}

Demo

curl --location --request POST 'https://api.gitcode.com/api/v5/orgs/xiaogang_test/repos?access_token={your-token}' \
--header 'Content-Type: application/json' \
--data '{
    "name": "4",
    "has_issues": "true",
    "has_wiki": "true",
    "can_comment": "true",
    "private": "true"
}'

21. Fork a Repository

Request

POST https://api.gitcode.com/api/v5/repos/{owner}/{repo}/forks

Parameters

ParameterDescriptionTypeData Type
access_token*personal access tokenquerystring
owner*Repository Ownership Path (Company, Organization, or Personal Path)pathstring
repo*Repository Path(path)pathstring
organizationFull organization space address, if not provided, it will default to forking to the user’s personal space addressbodystring
nameForked repository name. Default: Source repository namebodystring
pathForked repository address. Default: Source repository addressbodystring

Response

{
    "id": 729292,
    "full_name": "xiaogang_test/fork2",
    "human_name": "测试组织 / fork2",
    "url": "https://api.gitcode.com/api/v5/repos/xiaogang_test/fork2",
    "namespace": {
        "id": 138108,
        "name": "测试组织",
        "path": "xiaogang_test",
        "develop_mode": "normal",
        "cell": "default",
        "kind": "group",
        "full_path": "xiaogang_test",
        "full_name": "测试组织",
        "visibility_level": 20,
        "enable_file_control": false
    }
}

Demo

curl --location --request POST 'https://api.gitcode.com/api/v5/repos/nevins/LessConsole/forks?access_token={your-token}' \
--header 'Content-Type: application/json' \
--data '{
    "name":"fork2",
    "path":"fork2",
    "organization":"xiaogang_test"
}'

22. List Forks of a Repository

Request

GET https://api.gitcode.com/api/v5/repos/{owner}/{repo}/forks

Parameters

ParameterDescriptionTypeData Type
access_token*personal access tokenquerystring
owner*Repository Ownership Path (Company, Organization, or Personal Path)pathstring
repo*Repository Path(path)pathstring
sortsort: fork(newest, oldest),star(stargazers)querystring
pageCurrent Page Numberqueryint
per_pageItems Per Page, Maximum 100queryint
created_aftercreated afterquerystring
created_beforecreated beforequerystring

Response

[
    {
        "id": 567682,
        "full_name": "wangwt/RuoYi",
        "human_name": "wangwt / RuoYi",
        "url": "https://api.gitcode.com/api/v5/repos/wangwt/RuoYi",
        "namespace": {
            "id": 153748,
            "type": "personal",
            "name": "wangwt",
            "path": "wangwt",
            "html_url": "https://test.gitcode.net/wangwt"
        },
        "description": "",
        "status": "",
        "created_at": "2024-07-29T15:42:45.149+08:00",
        "updated_at": "2024-07-29T15:42:45.149+08:00",
        "owner": {
            "id": 970,
            "login": "wangwt",
            "name": "wangwt"
        },
        "pushed_at": "2024-11-08T16:24:10.576+08:00",
        "parent": {
            "id": 517092,
            "full_name": "xiaogang/RuoYi",
            "human_name": "xiaogang / RuoYi",
            "url": "https://api.gitcode.com/api/v5/repos/xiaogang/RuoYi",
            "namespace": {
                "id": 137117,
                "type": "personal",
                "name": "xiaogang",
                "path": "xiaogang",
                "html_url": "https://test.gitcode.net/xiaogang"
            }
        },
        "private": false,
        "public": true
    }
]

Demo

curl --location --request GET 'https://api.gitcode.com/api/v5/repos/nevins/LessConsole/forks?access_token={your-token}'

23. Upload Image

Request

POST https://api.gitcode.com/api/v5/repos/{owner}/{repo}/img/upload

Parameters

ParameterDescriptionTypeData Type
access_token*personal access tokenquerystring
owner*Repository Ownership Path (Company, Organization, or Personal Path)pathstring
repo*Repository Path(path)pathstring
body*File content in base64 format (limit: 20MB).bodystring
file_name*File Namebodystring

Response

{
    "success": true,
    "path": "uploads/4c98ad75-729f-49ce-82ab-b41c1f7ffc90/test3.txt",
    "full_path": "https://gitcode.com/xiaogang/test/attachment/uploads/4c98ad75-729f-49ce-82ab-b41c1f7ffc90/test3.txt"
}

Demo

curl --location 'https://api.gitcode.com/api/v5/repos/tiandi/YanF4/img/upload?access_token=******' \
--header 'Content-Type: application/json' \
--data '{
"body":"1",
"file_name":"2.png"
}'

24. Upload File

Request

POST https://api.gitcode.com/api/v5/repos/{owner}/{repo}/file/upload

Parameters

ParameterDescriptionTypeData Type
access_token*personal access tokenquerystring
owner*Repository Ownership Path (Company, Organization, or Personal Path)pathstring
repo*Repository Path(path)pathstring
file*File content in base64 format (limit: 20MB)formDatafile

Response

{
    "success": true,
    "path": "uploads/4c98ad75-729f-49ce-82ab-b41c1f7ffc90/test3.txt",
    "full_path": "https://gitcode.com/xiaogang/test/attachment/uploads/4c98ad75-729f-49ce-82ab-b41c1f7ffc90/test3.txt"
}

Demo

curl --location 'https://api.gitcode.com/api/v5/repos/xiaogang_test/test222/file/upload' \
--header 'Content-Type: application/json;charset=UTF-8' \
--header 'PRIVATE-TOKEN: token' \
--form 'file=@"/Users/xiaogang/Downloads/test3.txt"'

25. List Users Watching a Repository

Request

POST https://api.gitcode.com/api/v5/repos/{owner}/{repo}/subscribers

Parameters

ParameterDescriptionTypeData Type
access_token*personal access tokenquerystring
owner*Repository Ownership Path (Company, Organization, or Personal Path)pathstring
repo*Repository Path(path)pathstring
pageCurrent Page Numberqueryint
per_pageItems Per Page, Maximum 100queryint
watched_afterwatched afterqueryString
watched_beforewatched beforequeryString

Response

[
    {
        "id": 496,
        "login": "xiaogang",
        "name": "xiaogang",
        "avatar_url": "https://gitcode-img.obs.cn-south-1.myhuaweicloud.com:443/bc/cd/6bc422546cdf276c147f267030d83a43e927fec67ca66f0b22f7e03556206fa3.jpg",
        "watch_at": "2024-11-13T16:15:53.287+08:00"
    }
]

Demo

curl --location 'https://api.gitcode.com/api/v5/repos/xiaogang_test/test222/subscribers' \
--header 'PRIVATE-TOKEN: token'

26. List Users Starring a Repository

Request

POST https://api.gitcode.com/api/v5/repos/{owner}/{repo}/stargazers

Parameters

ParameterDescriptionTypeData Type
access_token*personal access tokenquerystring
owner*Repository Ownership Path (Company, Organization, or Personal Path)pathstring
repo*Repository Path(path)pathstring
pageCurrent Page Numberqueryint
per_pageItems Per Page, Maximum 100queryint
starred_afterstarred afterquerystring
starred_beforestarred beforequerystring

Response

[
    {
        "id": 496,
        "login": "xiaogang",
        "name": "xiaogang",
        "avatar_url": "https://gitcode-img.obs.cn-south-1.myhuaweicloud.com:443/bc/cd/6bc422546cdf276c147f267030d83a43e927fec67ca66f0b22f7e03556206fa3.jpg",
        "watch_at": "2024-11-13T16:15:53.287+08:00"
    }
]

Demo

curl --location 'https://api.gitcode.com/api/v5/repos/xiaogang_test/test222/stargazers' \
--header 'PRIVATE-TOKEN: token'

27. Update Repository Settings

Request

PUT https://api.gitcode.com/api/v5/repos/{owner}/{repo}/repo_settings

Parameters

ParameterDescriptionTypeData Type
access_token*personal access tokenquerystring
owner*Repository Ownership Path (Company, Organization, or Personal Path)pathstring
repo*Repository Path(path)pathstring
disable_forkdisable forkbodyBoolean
forbidden_developer_create_branchforbidden developer create branchbodyBoolean
forbidden_developer_create_tagforbidden developer create tagbodyBoolean
forbidden_committer_create_branchforbidden committer create branchbodyBoolean
forbidden_developer_create_branch_user_idsforbidden developer create branch user idsbodyString
branch_name_regexbranch name regexbodyString
tag_name_regextag name regexbodyString
generate_pre_merge_refgenerate pre-merge refbodyBoolean
rebase_disable_trigger_webhookrebase disable trigger webhookbodyBoolean
open_gpg_verifiedopen gpg verifiedbodyBoolean
include_lfs_objectsZIP downlaod include lfs objectsbodyBoolean

Response

{
    "disable_fork": true,
    "forbidden_developer_create_branch": false,
    "forbidden_developer_create_tag": false,
    "forbidden_committer_create_branch": false,
    "generate_pre_merge_ref": false,
    "forbidden_gitlab_access": true,
    "rebase_disable_trigger_webhook": false,
    "include_lfs_objects": false
}

Demo

curl --location --request PUT 'https://api.gitcode.com/api/v5/repos/test-org/test-repo/repo_settings?access_token=token' \
--header 'Content-Type: application/json' \
--data '{"disable_fork": true}'

28. Get Repository Settings

Request

GET https://api.gitcode.com/api/v5/repos/{owner}/{repo}/repo_settings

Parameters

ParameterDescriptionTypeData Type
access_token*personal access tokenquerystring
owner*Repository Ownership Path (Company, Organization, or Personal Path)pathstring
repo*Repository Path(path)pathstring

Response

{
    "disable_fork": true,
    "forbidden_developer_create_branch": false,
    "forbidden_developer_create_tag": false,
    "forbidden_committer_create_branch": false,
    "generate_pre_merge_ref": false,
    "forbidden_gitlab_access": true,
    "rebase_disable_trigger_webhook": false,
    "include_lfs_objects": false
}

Demo

curl --location 'https://api.gitcode.com/api/v5/repos/test-org/test-repo/repo_settings?access_token=token'

29. Get Pull Request Settings

Request

GET https://api.gitcode.com/api/v5/repos/{owner}/{repo}/pull_request_settings

Parameters

ParameterDescriptionTypeData Type
access_token*personal access tokenquerystring
owner*Repository Ownership Path (Company, Organization, or Personal Path)pathstring
repo*Repository Path(path)pathstring

Response

{
    "merge_request_setting": {
        "id": 1431,
        "project_id": 2745002,
        "disable_merge_by_self": false,
        "created_at": "2024-03-28T10:04:13.523+08:00",
        "updated_at": "2024-11-13T21:30:45.261+08:00",
        "can_force_merge": false,
        "disable_squash_merge": true,
        "approval_required_reviewers": 0,
        "approval_required_approvers": 0,
        "add_notes_after_merged": false,
        "merged_commit_author": "merged_by",
        "mark_auto_merged_mr_as_closed": false,
        "delete_source_branch_when_merged": false,
        "auto_squash_merge": false,
        "squash_merge_with_no_merge_commit": false,
        "close_issue_when_mr_merged": false,
        "can_reopen": true,
        "is_check_cla": false,
        "approval_approvers": [],
        "approval_testers": [],
        "approval_required_testers": 0,
        "is_allow_lite_merge_request": false
    },
    "only_allow_merge_if_all_discussions_are_resolved": false,
    "only_allow_merge_if_pipeline_succeeds": false,
    "merge_method": "merge"
}

Demo

curl --location 'https://api.gitcode.com/api/v5/repos/test-org/test-repo/pull_request_settings?access_token=token'

30. Update Pull Request Settings

Request

PUT https://api.gitcode.com/api/v5/repos/{owner}/{repo}/pull_request_settings

Parameters

ParameterDescriptionTypeData Type
access_token*personal access tokenquerystring
owner*Repository Ownership Path (Company, Organization, or Personal Path)pathstring
repo*Repository Path(path)pathstring
approval_required_reviewers_enable是否启用审批必需的评审者功能bodyBoolean
approval_required_reviewers需要的审批者数量(最小评审人数【选择的数字:1~5, 如果取消评审人功能传入0】)bodyInteger
only_allow_merge_if_all_discussions_are_resolved评审问题全部解决才能合入bodyBoolean
only_allow_merge_if_pipeline_succeeds是否仅在流水线成功后才允许合并bodyBoolean
disable_merge_by_self禁止合入自己创建的合并请求bodyBoolean
can_force_merge允许管理员强制合入bodyBoolean
add_notes_after_merged允许合并请求合并后继续做代码检视和评论bodyBoolean
mark_auto_merged_mr_as_closed是否将自动合并的MR状态标记为关闭状态bodyBoolean
can_reopen是否可以重新打开一个已经关闭的合并请求bodyBoolean
delete_source_branch_when_merged合并时是否删除源分支,默认删除原分支bodyBoolean
disable_squash_merge禁止 Squash 合并bodyBoolean
auto_squash_merge新建合并请求,默认开启 Squash 合并bodyBoolean
merge_method合并模式三选一(通过 merge commit 合并:merge;通过 merge commit 合并 (记录半线性历史):rebase_merge;fast - forward 合并:ff)bodyString
squash_merge_with_no_merge_commitSquash 合并不产生 Merge 节点bodyBoolean
merged_commit_author使用 MR (合入/创建) 者生成 Merge Commit(使用 PR 合入者生成 Merge Commit:传 merged_by; 使用 PR 创建者生成 Merge Commit:传 created_by)bodyString
approval_required_approvers需要审批的批准者数量bodyInteger
approval_approver_ids项目审查人, user_id 以逗号分隔bodyString
approval_tester_ids项目测试人,user_id以逗号分隔bodyString
approval_required_testers测试最小通过人数bodyInteger
is_check_cla是否校验CLAbodyBoolean
is_allow_lite_merge_request是否启用轻量级 Pull RequestbodyBoolean
lite_merge_request_prefix_title轻量级 pr 的标题前缀bodyString
close_issue_when_mr_merged创建 Pull Request 时,默认选中 “合并后关闭已关联的 Issue”bodyBoolean

Response

{
    "merge_request_setting": {
        "id": 1431,
        "project_id": 2745002,
        "disable_merge_by_self": false,
        "created_at": "2024-03-28T10:04:13.523+08:00",
        "updated_at": "2024-11-13T21:30:45.261+08:00",
        "can_force_merge": false,
        "disable_squash_merge": true,
        "approval_required_reviewers": 0,
        "approval_required_approvers": 0,
        "add_notes_after_merged": false,
        "merged_commit_author": "merged_by",
        "mark_auto_merged_mr_as_closed": false,
        "delete_source_branch_when_merged": false,
        "auto_squash_merge": false,
        "squash_merge_with_no_merge_commit": false,
        "close_issue_when_mr_merged": false,
        "can_reopen": true,
        "is_check_cla": false,
        "approval_approvers": [],
        "approval_testers": [],
        "approval_required_testers": 0,
        "is_allow_lite_merge_request": false
    },
    "only_allow_merge_if_all_discussions_are_resolved": false,
    "only_allow_merge_if_pipeline_succeeds": false,
    "merge_method": "merge"
}

Demo

curl --location --request PUT 'https://api.gitcode.com/api/v5/repos/test-org/test-repo/pull_request_settings?access_token=token' \
--header 'Content-Type: application/json' \
--data '{"is_check_cla": false}'

31. Create Personal Repository

Request

POST https://api.gitcode.com/api/v5/user/repos

Parameters

ParameterDescriptionTypeData Type
access_token*personal access tokenquerystring
name*Repository Namebodystring
descriptionRepository Descriptionbodystring
homepagehomepagebodystring
has_issuesTRUE Allow Issues to Be Created (Enabled/Disabled)Default: truebodyboolean
has_wikihas wiki, Default: truebodyboolean
auto_initWhen set to true, the repository will be initialized with a README. Default: Do not initialize (false).bodyboolean
gitignore_templategitignore templatebodystring
license_templatelicense templatebodystring
pathRepository Pathbodystring
privatetrue/falsebodystring
import_urlRepository import URL, which must end with .git, for example: https://github.com/apache/kafka.gitbodystring

Response

Return parameter meanings: refer to the body of setting project push rules.

{
    "id": 729293,
    "full_name": "xiaogang/4",
    "human_name": "xiaogang / 4",
    "url": "https://api.gitcode.com/api/v5/repos/xiaogang/4",
    "namespace": {
        "id": 137117,
        "name": "xiaogang",
        "path": "xiaogang",
        "develop_mode": "normal",
        "kind": "user",
        "full_path": "xiaogang",
        "full_name": "xiaogang",
        "visibility_level": 20,
        "enable_file_control": false,
        "owner_id": 496
    },
    "path": "4",
    "name": "4",
    "private": true,
    "public": false,
    "visibility": "private"
}

Demo

curl --location --request PUT 'https://api.gitcode.com/api/v5/user/repos?access_token=token' \
--header 'Content-Type: application/json' \
--data '{"name": "test2"}'

32. Update Repository Member Roles

Request

PUT https://api.gitcode.com/api/v5/repos/{owner}/{repo}/members/{username}

Parameters

ParameterDescriptionTypeData Type
access_token*personal access tokenquerystring
owner*Repository Ownership Path (Company, Organization, or Personal Path)pathstring
repo*Repository Path(path)pathstring
username*usernamepathstring
permissionpermission: pull, push, admin, customized role name. Default: pushbodystring
role_idrole ID, If the permission is set to “customized”, the role ID must be provided.bodystring

Response

{
    "followers_url": "https://api-test.gitcode.com/api/v5/users/xiaogang2/followers",
    "html_url": "https://test.gitcode.net/xiaogang2",
    "id": "65ffca965079ba0d1c00f6f2",
    "login": "xiaogang2",
    "name": "肖刚2",
    "type": "User",
    "url": "https://api-test.gitcode.com/api/v5/xiaogang2",
    "permissions": {
        "admin": false,
        "push": false,
        "customized": true,
        "pull": false
    }
}

Demo

curl --location --request PUT 'https://api.gitcode.com/api/v5/repos/xiaogang/test/members/xiaogang2?access_token=token' \
--header 'Content-Type: application/json' \
--data '{
    "permission": "admin"
}'

33. Transfer Repository

Request

POST https://api.gitcode.com/api/v5/repos/{owner}/{repo}/transfer

ParameterDescriptionTypeData Type
access_token*personal access tokenquerystring
owner*Repository Owner Path (Organization or User Path)pathstring
repo*Repository Path(path)pathstring
new_owner*target namespacebodystring

Response

{
    "new_owner": "tiandi",
    "new_name": "new_repo_name"
}

Demo

curl --location --request POST 'https://api.gitcode.com/api/v5/repos/RealMadrid/repo_yf99999/transfer?access_token=your_token' \
--form 'new_owner="tiandi"' \
--form 'new_name="new_repo_name"'

34. Get Custom Roles of a Repository

Request

GET https://api.gitcode.com/api/v5/repos/{owner}/{repo}/customized_roles

Parameters

ParameterDescriptionTypeData Type
access_token*personal access tokenquerystring
owner*Repository Ownership Path (Company, Organization, or Personal Path)pathstring
repo*Repository Path(path)pathstring

Response

[
    {
        "role_id": "e6cd76d6c82f46c78c71fd7f67eaf3bf",
        "access_level": 15,
        "role_name": "测试角色",
        "role_chinese_name": "测试角色",
        "role_description": "测试角色",
        "role_type": "project-customized",
        "member_count": 1,
        "created_at": "2024-04-17 08:00",
        "updated_at": "2024-04-17 08:00"
    }
]

Demo

curl --location 'https://api.gitcode.com/api/v5/repos/xiaogang_test/test222/customized_roles?access_token=?'

35. Download Statistics

Request

GET https://api.gitcode.com/api/v5/repos/{owner}/{repo}/download_statistics

Parameters

ParameterDescriptionTypeData Type
access_token*personal access tokenquerystring
owner*Repository Ownership Path (Company, Organization, or Personal Path)pathstring
repo*Repository Path(path)pathstring
start_datestart date(eg:2024-01-06)querystring
end_dateend date (eg: 2024-12-06)querystring
directionasc/desc, Default: descquerystring

Response

字段名DescriptionData Type
pdatedatestring
repo_idrepo idstring
total_dl_cnttotal downlaod countLong
today_dl_cnttoday download countLong
download_statistics_totalTotal downloads within the specified time rangeLong
download_statistics_history_totalTotal downloads up to the cutoff dateLong
{
    "download_statistics_detail": [
        {
            "pdate": "2024-11-13",
            "repo_id": "625513",
            "today_dl_cnt": 0,
            "total_dl_cnt": 38
        },
        {
            "pdate": "2024-11-14",
            "repo_id": "625513",
            "today_dl_cnt": 0,
            "total_dl_cnt": 38
        },
        {
            "pdate": "2024-11-15",
            "repo_id": "625513",
            "today_dl_cnt": 0,
            "total_dl_cnt": 38
        },
        {
            "pdate": "2024-11-16",
            "repo_id": "625513",
            "today_dl_cnt": 5,
            "total_dl_cnt": 43
        },
        {
            "pdate": "2024-11-17",
            "repo_id": "625513",
            "today_dl_cnt": 0,
            "total_dl_cnt": 43
        },
        {
            "pdate": "2024-11-18",
            "repo_id": "625513",
            "today_dl_cnt": 0,
            "total_dl_cnt": 43
        },
        {
            "pdate": "2024-11-19",
            "repo_id": "625513",
            "today_dl_cnt": 0,
            "total_dl_cnt": 43
        },
        {
            "pdate": "2024-11-20",
            "repo_id": "625513",
            "today_dl_cnt": 0,
            "total_dl_cnt": 43
        },
        {
            "pdate": "2024-11-21",
            "repo_id": "625513",
            "today_dl_cnt": 2,
            "total_dl_cnt": 45
        },
        {
            "pdate": "2024-11-22",
            "repo_id": "625513",
            "today_dl_cnt": 0,
            "total_dl_cnt": 45
        },
        {
            "pdate": "2024-11-23",
            "repo_id": "625513",
            "today_dl_cnt": 0,
            "total_dl_cnt": 45
        },
        {
            "pdate": "2024-11-24",
            "repo_id": "625513",
            "today_dl_cnt": 0,
            "total_dl_cnt": 45
        },
        {
            "pdate": "2024-11-25",
            "repo_id": "625513",
            "today_dl_cnt": 0,
            "total_dl_cnt": 45
        },
        {
            "pdate": "2024-11-26",
            "repo_id": "625513",
            "today_dl_cnt": 0,
            "total_dl_cnt": 45
        }
    ],
    "download_statistics_total": 7,
    "download_statistics_history_total": 45
}

Demo

curl --location 'https://api.gitcode.com/api/v5/repos/openharmony/applications_app_samples/download_statistics?direction=asc&access_token=your_token&start_date=2024-01-11&end_date=2024-12-11'

36. Get Raw File

Request

GET https://api.gitcode.com/api/v5/repos/{owner}/{repo}/raw/{path}

Parameters

ParameterDescriptionTypeData Type
access_token*personal access tokenquerystring
owner*Repository Ownership Path (Company, Organization, or Personal Path)pathstring
repo*Repository pathpathstring
path*File pathpathstring
refBranch, tag, or commit (default: repository’s default branch)querystring

Response

raw file content

Demo

curl --location 'https://api.gitcode.com/api/v5/repos/org-test/repo-test/raw/test/test.py?access_token=your_token'

37. Get Repository Contributor Statistics

GET https://api.gitcode.com/api/v5/repos/{owner}/{repo}/contributors/statistic?access_token=your_token

Parameters

ParameterDescriptionINType
access_token*personal access tokenquerystring
owner*Repository Ownership Path (Company, Organization, or Personal Path)pathstring
repo*Repository pathpathstring
authorFilter contributors by username. Specify a username to retrieve contribution data for that user. By default, returns contribution data for all users.querystring
current_userWhether to return data only for the current user. true returns contribution data only for the current user, false or omission returns data for all users. When set to true, it has higher priority than the author parameter.queryboolean
sinceStart date in the format YYYY-MM-DD or YYYY-MM-DD HH:mm:ss. Used to limit the start time of the returned contribution data.querystring
untilEnd date in the format YYYY-MM-DD or YYYY-MM-DD HH:mm:ss. Used to limit the end time of the returned contribution data.querystring
ref_nameSpecifies the ref_name (branch name, commit id, tag name) for which to retrieve contribution data. If not provided or empty, the default branch is used.querystring

Response

[
  {
    "name": "test",
    "email": "aa@ss.com",
    "overview": {
      "additions": 762,
      "deletions": 0,
      "total_changes": 0,
      "commit_count": 8
    },
    "contributions": [
      {
        "date": "2024-12-05",
        "additions": 759,
        "deletions": 0,
        "total_changes": 759,
        "commit_count": 5
      },
      {
        "date": "2024-12-08",
        "additions": 2,
        "deletions": 0,
        "total_changes": 2,
        "commit_count": 2
      },
      {
        "date": "2024-12-09",
        "additions": 1,
        "deletions": 0,
        "total_changes": 1,
        "commit_count": 1
      }
    ]
  }
]

Response Fields Description

FieldTypeDescription
namestringThe contributor’s name or username.
emailstringThe contributor’s email address.
overviewobjectOverall statistics for the contributor, including the following fields:
overview.additionsintegerTotal number of lines added.
overview.deletionsintegerTotal number of lines deleted.
overview.total_changesintegerTotal number of lines changed (additions + deletions).
overview.commit_countintegerTotal number of commits.
contributionsarrayArray of contribution records, containing contribution data for each date.
contributions.datestringContribution date in the format YYYY-MM-DD.
contributions.additionsintegerNumber of lines added on that date.
contributions.deletionsintegerNumber of lines deleted on that date.
contributions.total_changesintegerNumber of lines changed on that date.
contributions.commit_countintegerNumber of commits on that date.

Demo

curl --location 'https://api.gitcode.com/api/v5/repos/org-test/myrepo/contributors/statistic?access_token=your_token'