GitLab APIにマルチファイルコミットを送信しようとしています。RestSharp POST GitLab-APIでコミットします
私は承認を受けて、BadRequest
という応答を得ています。 I私のJSON
を検証してきましたが、私は、応答
でこれを取得しています "{" エラー ":" ブランチはcommit_messageが欠落している、欠けている、アクションが欠落している "}"
JSON
{
"branch": "master",
"commit_message": "Ticket-27 6\/29\/2017 4:37:13 PM",
"author_name": "My Name",
"author_email": "[email protected]",
"actions": [{
"action": "create",
"file_path": "procedures\/dbo.sp_SomeProc1.sql",
"content": "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n-- =============================================\r\n-- Author:\t\t<,,Name>\r\n-- Create date: <Create Date,,>\r\n-- Description:\t<Description,,>\r\n-- =============================================\r\n\r\nCREATE PROCEDURE [dbo].[sp_SomeProc1] @ID int,@StartDate datetime\r\n\t-- Add the parameters for the stored procedure here\r\n\r\nAS\r\nBEGIN\r\n\r\n\tSET NOCOUNT ON;\r\n\tSELECT * FROM MyTable WHERE MEMBERID = @ID \r\n\t"
}, {
"action": "create",
"file_path": "procedures\/dbo.sp_SomeProc2.sql",
"content": "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n-- =============================================\r\n-- Author:\t\t<,,Name>\r\n-- Create date: <Create Date,,>\r\n-- Description:\t<Description,,>\r\n-- =============================================\r\n\r\nCREATE PROCEDURE [dbo].[sp_SomeProc2] @ID int,@StartDate datetime\r\n\t-- Add the parameters for the stored procedure here\r\n\r\nAS\r\nBEGIN\r\n\r\n\tSET NOCOUNT ON;\r\n\tSELECT * FROM MyTable WHERE MEMBERID = @ID \r\n\t"
}, {
"action": "create",
"file_path": "procedures\/dbo.sp_SomeProc3.sql",
"content": "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n-- =============================================\r\n-- Author:\t\t<,,Name>\r\n-- Create date: <Create Date,,>\r\n-- Description:\t<Description,,>\r\n-- =============================================\r\n\r\nCREATE PROCEDURE [dbo].[sp_SomeProc3] @ID int,@StartDate datetime\r\n\t-- Add the parameters for the stored procedure here\r\n\r\nAS\r\nBEGIN\r\n\r\n\tSET NOCOUNT ON;\r\n\tSELECT * FROM MyTable WHERE MEMBERID = @ID \r\n\t"
}
]
}
私はその後"test"
するコンテンツを変更しますが、私はRestSharpから信じている別のエラーを取得します。
StatusCode = 0
ErrorMessage = "Object reference not set to an instance of an object."
JSON
{
"branch": "master",
"commit_message": "Ticket-27 6\/29\/2017 4:37:13 PM",
"author_name": "My Name",
"author_email": "[email protected]",
"actions": [{
"action": "create",
"file_path": "procedures\/dbo.sp_SomeProc1.sql",
"content": "test"
}, {
"action": "create",
"file_path": "procedures\/dbo.sp_SomeProc2.sql",
"content": "test"
}
]
}
そして最後に、私のC#
コード:
RestRequest request =
new RestRequest([email protected]"api/v4/projects/{project.id}/repository/commits", Method.POST);
request.Parameters.Add(new Parameter() {
ContentType = "application/json",
Type = ParameterType.RequestBody,
Value = commit
});
request.Parameters.Add(new Parameter() {
Name = "PRIVATE-TOKEN",
Type = ParameterType.HttpHeader,
Value = ConfigurationManager.AppSettings["GitLabPrivateToken"]
});
request.RequestFormat = DataFormat.Json;
IRestResponse respone = _restClient.Execute(request);
今、"file_path"
はブランチには実際には存在しませんが、私は"create"
のアクションを取っていたので、それは必要ではないと思いました。 StatusCode = 0
at RestSharp.RestClient.<ConfigureHttp>b__2f(Parameter p2)
at System.Linq.Enumerable.All[TSource](IEnumerable`1 source, Func`2 predicate)
at RestSharp.RestClient.ConfigureHttp(IRestRequest request, IHttp http)
at RestSharp.RestClient.Execute(IRestRequest request, String httpMethod, Func`3 getResponse)