how to get push info from gitlab hooks with .NET

匿名 (未验证) 提交于 2019-12-03 08:56:10

问题:

I need to write a website to display our team's push info. Now I meet a problem that how to get info form gitlab?

回答1:

the type of push infomation is JSON, and what you need to do is to add a URL hook to gitlab,and the url is your API's address. just like:

and then ,click test button to check you API

following is my push_events API, :

 public int PushEventInfo([FromBody]PushEvent push)     {         bool flag = true;         ProjectController project = new ProjectController();         List<string> projectName = new List<string>();         try         {             SqlConnection conn = connectLocaldb.ConnectDataBase();             conn.Open();             string sql = "INSERT INTO MemberCommitBeforeCompiling(Username,ProjectName,Version,GroupName,CommitTime,Branch) VALUES ('" + push.user_name + "','" + push.project.name + "','" + push.after + "','" + groupname + "',getdate(),'" + push.@ref + "') ";             SqlCommand cmd = new SqlCommand(sql, conn);             int result = cmd.ExecuteNonQuery();             //判断项目是否已存在             IList<Project> namelist = project.GetAllProjectInfo();             foreach(var i in namelist)             {                //如果MemberProject表中已经存在该项目                 if (i.projectName.Contains(push.project.name)|| push.project.name.Contains(i.projectName))                     flag = false;             }             if (flag==true)             {                 sql = "INSERT INTO MemberProject(ProjectName,CommitTime,isdelete) VALUES ('" + push.project.name + "',getdate(),'0') ";                 cmd = new SqlCommand(sql, conn);                 result = cmd.ExecuteNonQuery();             }             conn.Close();             return result;         }         catch (Exception e)         {             FileStream fs = new FileStream("c:\\test\\log.txt", FileMode.Append, FileAccess.Write);             StreamWriter sw = new StreamWriter(fs); // 创建写入流             sw.WriteLine(e.ToString()); // 写入             sw.Close();             return 0;         }


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!