GITLAB API 在存储库中创建新文件
GITLAB API Create new file in repository
所以我试图通过这个 api 在我的 git 存储库中创建一个新文件,我在我的 React 代码库中公开了这个文件,但我收到了 403 错误?让我知道我哪里错了。
var bodyData = {
token: "**********",
ref: "main",
branch: "demo",
commit_message: "create a new file",
content: "some content"
};
fetch("https://gitlab.com/api/v4/projects/27622003/repository/files/myfile1%2Etxt", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(bodyData),
})
.then((response) => response.json())
.then((data) => {
console.log("response:", data);
})
.catch((error) => {
console.error("Error:", error);
});
您似乎缺少包含您要执行的操作类型(创建、移动、更新和删除)的操作数组。
GitLab 提交 API:https://docs.gitlab.com/ee/api/commits.html
在您的情况下,有效负载应如下所示:
var bodyData = {
token: "**********",
ref: "main",
branch: "demo",
commit_message: "create a new file",
actions: [
{
"action": "create",
"file_path": "your/file/path",
"content": "some content"
}
]
};
所以我试图通过这个 api 在我的 git 存储库中创建一个新文件,我在我的 React 代码库中公开了这个文件,但我收到了 403 错误?让我知道我哪里错了。
var bodyData = {
token: "**********",
ref: "main",
branch: "demo",
commit_message: "create a new file",
content: "some content"
};
fetch("https://gitlab.com/api/v4/projects/27622003/repository/files/myfile1%2Etxt", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(bodyData),
})
.then((response) => response.json())
.then((data) => {
console.log("response:", data);
})
.catch((error) => {
console.error("Error:", error);
});
您似乎缺少包含您要执行的操作类型(创建、移动、更新和删除)的操作数组。
GitLab 提交 API:https://docs.gitlab.com/ee/api/commits.html
在您的情况下,有效负载应如下所示:
var bodyData = {
token: "**********",
ref: "main",
branch: "demo",
commit_message: "create a new file",
actions: [
{
"action": "create",
"file_path": "your/file/path",
"content": "some content"
}
]
};