API出处Repository submodules API | GitLab;
PUT /projects/:id/repository/submodules/:submodule
Attribute | Type | Required | Description |
---|---|---|---|
id | integer/string | yes | The ID or URL-encoded path of the project owned by the authenticated user |
submodule | string | yes | URL-encoded full path to the submodule. For example, lib%2Fclass%2Erb |
branch | string | yes | Name of the branch to commit into |
commit_sha | string | yes | Full commit SHA to update the submodule to |
commit_message | string | no | Commit message. If no message is provided, a default is set |
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/repository/submodules/lib%2Fmodules%2Fexample" \
--data "branch=master&commit_sha=3ddec28ea23acc5caa5d8331a6ecb2a65fc03e88&commit_message=Update submodule reference"
这是API给的参数,我个人在使用id和submodule的时候很疑惑,最后尝试好多次终于成功了。
eg:
function eg(){
return new Promise(function (u, f) {
var d = `https://gitlab.example.com/api/v4/projects/5/repository/submodules/lib%2Fmodules%2Fexample`;
fetch(d, {
method: "PUT",
headers: {
"PRIVATE-TOKEN": "you TOKEN",
"Content-Type": "application/json"
},
body: JSON.stringify({
branch: "you branch",
commit_message: "you message",
author_email: "",
author_name: "",
commit_sha: "your new commit id",
})
}).then(e => e.json()).then(e => {
u(e)
}).catch(e => {
f(e)
})
})
}
对于上面函数,变量d部分`https://gitlab.example.com/api/v4/projects/5/`是主模块的路径,repository/submodules/是固定的,后面的“lib%2Fmodules%2Fexample”是子模块路径,
例如图片中,最后的路径截止到@前面就可以了。
虽然API上说commit_message可以不要,但是不用的话会使用默认值,还是用上最好。
commit_sha,我刚开始以为是hash值,后面才知道原来是子模块最新提交的commit id,并不是本分支第一次提交的sha;
API中的id属性就是Project ID,项目的id,上面代码中的变量d的5。
submodules属性是子模块路径。