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; }