我正在尝试使用GitLab webhook“推送事件”在文件发生更改时通知用户。
根据这个GitLab help我应该收到这个请求正文:
{
"object_kind": "push",
"before": "95790bf891e76fee5e1747ab589903a6a1f80f22",
"after": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
"ref": "refs/heads/master",
"user_id": 4,
"user_name": "John Smith",
"user_email": "john@example.com",
"project_id": 15,
"repository": {
"name": "Diaspora",
"url": "git@example.com:mike/diasporadiaspora.git",
"description": "",
"homepage": "http://example.com/mike/diaspora",
"git_http_url":"http://example.com/mike/diaspora.git",
"git_ssh_url":"git@example.com:mike/diaspora.git",
"visibility_level":0
},
"commits": [
{
"id": "b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
"message": "Update Catalan translation to e38cb41.",
"timestamp": "2011-12-12T14:27:31+02:00",
"url": "http://example.com/mike/diaspora/commit/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
"author": {
"name": "Jordi Mallach",
"email": "jordi@softcatala.org"
}
},
{
"id": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
"message": "fixed readme",
"timestamp": "2012-01-03T23:36:29+02:00",
"url": "http://example.com/mike/diaspora/commit/da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
"author": {
"name": "GitLab dev user",
"email": "gitlabdev@dv6700.(none)"
}
}
],
"total_commits_count": 4
}
但我的WebAPI方法没有正确解决此请求,我尝试过的是
public async Task Post()
public void Post([FromBody] dynamic value)
public void Post([FromBody] PushEvent value)
(强类型)上述方法似乎都不起作用,但是如example method所示,在红宝石中尝试这种方法确实有效。
所以我认为这与我使用Web API的方式有关。有什么想法吗?
我的PushEvent类看起来像这样:
public class PushEvent
{
public string name { get; set; }
public string url { get; set; }
public string description { get; set; }
public string homepage { get; set; }
public string git_http_url { get; set; }
public string git_ssh_url { get; set; }
public int visibility_level { get; set; }
public string object_kind { get; set; }
public string before { get; set; }
public string after { get; set; }
public int user_id { get; set; }
public string user_name { get; set; }
public string user_email { get; set; }
public int project_id { get; set; }
public IList<Commit> commits { get; set; }
public int total_commits_count { get; set; }
public class Author
{
public string name { get; set; }
public string email { get; set; }
}
public class Commit
{
public string id { get; set; }
public string message { get; set; }
public DateTime timestamp { get; set; }
public string url { get; set; }
public Author author { get; set; }
}
}
答案 0 :(得分:1)
我&#39;我遇到了同样的问题,我的问题是由PAI代码引起的
以下是我的代码: pushEvents:
namespace LuckyGitlabStatWebAPI.Models
{
public class PushEvent
{
public string object_kind { get; set; }
public string before { get; set; }
public string after { get; set; }
public string @ref { get; set; }
public int user_id { get; set; }
public string user_name { get; set; }
public string user_email { get; set; }
public string user_avatar { get; set; }
public int project_id { get; set; }
public project project;
public repository repository;
public List<commits> commits;
public int total_commits_count { get; set; }
}
public class project
{
public string name { get; set; }
public string description { get; set; }
public string web_url { get; set; }
public string avatar_url { get; set; }
public string git_ssh_url { get; set; }
public string git_http_url { get; set; }
public string @namespace { get; set; }
public int visibility_level { get; set; }
public string path_with_namespace { get; set; }
public string default_branch { get; set; }
public string homepage { get; set; }
public string url { get; set; }
public string ssh_url { get; set; }
public string http_url { get; set; }
}
public class repository
{
public string name { get; set; }
public string url { get; set; }
public string description { get; set; }
public string homepage { get; set; }
public string git_http_url { get; set; }
public string git_ssh_url { get; set; }
public int visibility_level { get; set; }
}
public class commits
{
public string id { get; set; }
public string message { get; set; }
public string timestamp { get; set; }
public string url { get; set; }
public string added { get; set; }
public Array modified;
public Array removed { get; set; }
public author author;
}
public class author
{
public string name { get; set; }
public string email { get; set; }
}
}
答案 1 :(得分:0)
我确实发现了问题所在,这是由于身份验证。一旦我允许该方法允许anonmymous,该方法被成功命中。