Cargowire.CIBridge.HookParsers.GitHubHookParser.Parse C# (CSharp) Method

Parse() public method

Translates an http get/post from the Source control solution into a generic format for use with a build engine
public Parse ( NameValueCollection requestData ) : IEnumerable
requestData System.Collections.Specialized.NameValueCollection
return IEnumerable
        public IEnumerable<HookInfo> Parse(NameValueCollection requestData)
        {
            string jsonData = requestData["payload"];
            if (!string.IsNullOrEmpty(jsonData))
            {
                string json = jsonData;
                JObject o = JObject.Parse(json);
                User u = null;
                Repository r = new Repository { Name = (string)((JObject)o["repository"])["name"], Uri = new Uri((string)((JObject)o["repository"])["url"]) };
                List<Commit> commits = new List<Commit>();
                foreach(JObject commit in (JArray)o["commits"]){
                    commits.Add(new Commit { Author = u, Id = (string)commit["id"], DateTime = DateTime.Parse((string)commit["timestamp"]), Uri = new Uri((string)commit["url"]) });
                }
                r.Commits = commits;
                string branchName = (string)(JObject)o["ref"];
                string branchFullName = branchName;
                branchName = branchName.Substring(branchName.LastIndexOf("/") + 1);
                return new List<HookInfo>(new HookInfo[] { new HookInfo { Branch = new Branch { Name = branchName, FullName = branchFullName, IsMaster = (string.Compare(branchName, "master", true) == 0) }, User = u, Repository = r } });
            }
            return null;
        }
GitHubHookParser