Exemple #1
0
        private List <ContribCommit> GetCommits(JArray ContribList, string url, int cnt)
        {
            ContribCommit        contrib         = null;
            List <ContribCommit> lstContribLogin = new List <ContribCommit>();
            int    ActiveWeeks  = 0;
            string strLoginName = "";

            JToken[] comms = null;

            try
            {
                strLoginName = ContribList[cnt]["author"]["login"].ToString();
                comms        = ContribList[cnt]["weeks"].ToArray();

                int Wcnt = 0;
                for (Wcnt = comms.Length - 1; Wcnt >= 0; Wcnt--)
                {
                    ActiveWeeks++;
                    if (ActiveWeeks > 48)
                    {
                        break;
                    }

                    int contribdate = Int32.Parse(GetTimeFromEpoch(comms[Wcnt]["w"].ToString()));
                    contrib           = new ContribCommit();
                    contrib.LoginName = strLoginName;
                    contrib.CommTime  = contribdate.ToString();
                    contrib.Additions = comms[Wcnt]["a"].ToString();
                    contrib.Deletions = comms[Wcnt]["d"].ToString();
                    contrib.Commits   = comms[Wcnt]["c"].ToString();
                    contrib.ErrNum    = 0;
                    contrib.ErrMes    = "-";
                    contrib.Url       = url;
                    contrib.Cnt       = Wcnt;
                    lstContribLogin.Add(contrib);
                }
            }
            catch (Exception ex)
            {
                if (contrib == null)
                {
                    contrib = new ContribCommit();
                }
                contrib.LoginName = strLoginName;
                contrib.ErrNum    = 700;
                contrib.ErrMes    = ex.Message;
                contrib.Url       = url;
                contrib.Cnt       = cnt;
                lstContribLogin.Add(contrib);

                return(lstContribLogin);
            }

            if (lstContribLogin.Count < 48)
            {
                ComplimentEmptyCommits(comms, lstContribLogin, url);
            }

            return(lstContribLogin);
        }
Exemple #2
0
        private void ComplimentEmptyCommits(JToken[] comms, List <ContribCommit> lstContribLogin, string url)
        {
            int           contribdate = Int32.Parse(TimeConverter.GetTimeFromEpoch(comms[0]["w"].ToString()));
            int           startdt     = 0;
            int           startind    = 0;
            ContribCommit contrib     = null;

            for (int i = 0; i < lstWeeks.Count; i++)
            {
                startdt = lstWeeks[i];
                if (startdt == contribdate)
                {
                    startind = i; break;
                }
            }

            for (int k = startind - 1; k >= 0; k--)
            {
                contrib           = new ContribCommit();
                contrib.LoginName = "00nologin00";
                contrib.CommTime  = lstWeeks[k].ToString();
                contrib.Additions = "0";
                contrib.Deletions = "0";
                contrib.Commits   = "0";
                contrib.ErrNum    = 0;
                contrib.ErrMes    = "-";
                contrib.Cnt       = k;
                contrib.Url       = url;
                lstContribLogin.Add(contrib);
            }

            string str = "checksum";
        }
        public int LoadGitHubInfo(TokenGitHubInfo inf, bool truncate)
        {
            StringBuilder sbRepo           = new StringBuilder();
            StringBuilder sbContribCommits = new StringBuilder();
            Repo          rpRepo           = null;
            ContribCommit cbcCommits       = null;

            //sb.Append(inf.CoinID + DL)

            //string RootInfo = inf.CoinID + DL + inf.Symbol + DL + inf.GitHubRoot + DL + inf.ReposNumber + DL + inf.Followers + DL +
            //                  inf.CreatedAt + DL + inf.UpdatedAt + DL + inf.ErrNum.ToString() + DL + inf.ErrMes;

            //File.WriteAllText("rootinfo.txt", RootInfo);
            if (inf.ErrNum > 0)
            {
                LoadInfoDB(inf, truncate); return(inf.ErrNum);
            }

            for (int i = 0; i < inf.RepoList.Count; i++)
            {
                rpRepo = inf.RepoList[i];
                sbRepo.Append(inf.CoinID + DL + inf.Symbol + DL + rpRepo.RepoID + DL + rpRepo.RepoName + DL + rpRepo.Created + DL + rpRepo.Updated + DL +
                              rpRepo.Pushed + DL + rpRepo.Size + DL + rpRepo.Language + DL + rpRepo.Forks + DL + rpRepo.ErrNum.ToString() + DL +
                              rpRepo.ErrMes + DL + rpRepo.Cnt.ToString() + DL + rpRepo.Url + "\n");

                if (rpRepo.Contribs == null)
                {
                    continue;
                }

                for (int k = 0; k < rpRepo.Contribs.Count; k++)
                {
                    cbcCommits = rpRepo.Contribs[k];
                    if (cbcCommits == null)
                    {
                        continue;
                    }
                    sbContribCommits.Append(inf.CoinID + DL + inf.Symbol + DL + rpRepo.RepoID + DL + rpRepo.RepoName + DL + cbcCommits.LoginName + DL +
                                            cbcCommits.Additions + DL + cbcCommits.Deletions + DL + cbcCommits.Commits + DL + cbcCommits.CommTime + DL +
                                            cbcCommits.ErrNum.ToString() + DL + cbcCommits.ErrMes + DL + cbcCommits.Cnt.ToString() + DL + cbcCommits.Url + "\n");
                }
            }

            File.WriteAllText("repoinfo.txt", sbRepo.ToString());
            File.WriteAllText("contribinfo.txt", sbContribCommits.ToString());

            if (LoadInfoDB(inf, truncate) > 0)
            {
                return(intErr);
            }

            return(intErr);
        }
Exemple #4
0
        public static void SetErrArray600(Repo rep, List <ContribCommit> lstContrib, string errmes, string input)
        {
            ContribCommit contrib = new ContribCommit();

            contrib.Additions = "0";
            contrib.Deletions = "0";
            contrib.Commits   = "0";
            contrib.CommTime  = "0";
            contrib.LoginName = "0";
            contrib.Cnt       = 0;
            contrib.Url       = input;
            contrib.ErrNum    = 600;
            contrib.ErrMes    = "Contrib Array Error 600 - " + errmes;
            lstContrib.Add(contrib);
            rep.Contribs = lstContrib;
        }
Exemple #5
0
        public static void SetErrNoData500(Repo rep, List <ContribCommit> lstContrib, string input)
        {
            ContribCommit contrib = new ContribCommit();

            contrib.Additions = "0";
            contrib.Deletions = "0";
            contrib.Commits   = "0";
            contrib.CommTime  = "0";
            contrib.LoginName = "0";
            contrib.Cnt       = 0;
            contrib.Url       = input;
            contrib.ErrNum    = 500;
            contrib.ErrMes    = "No Commits Data {} - 500";
            lstContrib.Add(contrib);
            rep.Contribs = lstContrib;
        }
Exemple #6
0
 public static void SetErrWeek700(ContribCommit contrib, string errmes, string url, int cnt)
 {
     if (contrib == null)
     {
         contrib = new ContribCommit();
     }
     contrib.Additions = "0";
     contrib.Deletions = "0";
     contrib.Commits   = "0";
     contrib.CommTime  = "0";
     contrib.LoginName = "0";
     contrib.Cnt       = cnt;
     contrib.Url       = url;
     contrib.ErrNum    = 700;
     contrib.ErrMes    = "Error Reading Weeks - " + errmes;
 }
Exemple #7
0
        public void GetContribCommits(Repo rep, string proot)
        {
            //** Avoid certificate error
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            //** Format URL string
            string               input      = "https://api.github.com/repos/" + proot + "/" + rep.RepoName + "/stats/contributors" + "?access_token=" + GthAuth;
            WebClient            currClient = new WebClient();
            List <ContribCommit> lstContrib = new List <ContribCommit>();

            currClient.Headers.Add("user-agent", "karloskolley");
            string jsonInput = "";

            Uri urUrl = new Uri(input);

            Thread.Sleep(100);

            try
            {
                jsonInput = currClient.DownloadString(urUrl);
                Thread.Sleep(1000);
            }
            catch (Exception ex)
            {
                ContribCommit.SetErr300(rep, lstContrib, ex.Message, input);
                currClient.Dispose();
                currClient = null;
                GC.Collect();
                Thread.Sleep(1000);
                return;
            }

            if (jsonInput.Equals(string.Empty))
            {
                ContribCommit.SetErrNoData400(rep, lstContrib, input);
                currClient.Dispose();
                currClient = null;
                GC.Collect();
                Thread.Sleep(1000);
                return;
            }

            Thread.Sleep(100);

            if (jsonInput.Equals("{}"))
            {
                ContribCommit.SetErrNoData500(rep, lstContrib, input);
                currClient.Dispose();
                currClient = null;
                GC.Collect();
                Thread.Sleep(1000);
                return;
            }

            JArray ContribList = null;
            int    Cnt         = 0;

            try
            {
                ContribList = JArray.Parse(jsonInput);
                Thread.Sleep(100);
            }
            catch (Exception ex)
            {
                ContribCommit.SetErrArray600(rep, lstContrib, ex.Message, input);
                currClient.Dispose();
                currClient = null;
                GC.Collect();
                Thread.Sleep(1000);
                return;
            }

            List <ContribCommit> lstContribLogin = null;

            for (Cnt = 0; Cnt < ContribList.Count; Cnt++)
            {
                lstContribLogin = GetCommits(ContribList, input, Cnt);
                if (lstContribLogin.Count == 0)
                {
                    continue;
                }
                for (int i = 0; i < lstContribLogin.Count; i++)
                {
                    lstContrib.Add(lstContribLogin[i]);
                }
            }

            currClient.Dispose();
            currClient = null;
            GC.Collect();
            GC.Collect();
            Thread.Sleep(100);
            rep.Contribs = lstContrib;
        }
Exemple #8
0
        private void GetContribCommits(Repo rep, string proot)
        {
            //** Avoid certificate error
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            //** Format URL string
            string    input      = "https://api.github.com/repos/" + proot + "/" + rep.RepoName + "/stats/contributors" + "?access_token=" + GthAuth;
            WebClient currClient = new WebClient();

            currClient.Headers.Add("user-agent", "karloskolley");
            string jsonInput = "";

            ContribCommit        contrib    = null;
            List <ContribCommit> lstContrib = new List <ContribCommit>();

            try
            {
                jsonInput = currClient.DownloadString(input);
            }
            catch (Exception ex)
            {
                contrib        = new ContribCommit();
                contrib.Cnt    = 0;
                contrib.Url    = input;
                contrib.ErrNum = 300;
                contrib.ErrMes = "404 No Commits Data 300 - " + ex.Message;
                lstContrib.Add(contrib);
                rep.Contribs = lstContrib;
                currClient.Dispose();
                currClient = null;
                return;
            }



            if (jsonInput.Equals(string.Empty))
            {
                contrib        = new ContribCommit();
                contrib.Cnt    = 0;
                contrib.Url    = input;
                contrib.ErrNum = 400;
                contrib.ErrMes = "No Commits Data - 400";
                lstContrib.Add(contrib);
                rep.Contribs = lstContrib;
                currClient.Dispose();
                currClient = null;
                return;
            }

            if (jsonInput.Equals("{}"))
            {
                contrib        = new ContribCommit();
                contrib.Cnt    = 0;
                contrib.Url    = input;
                contrib.ErrNum = 500;
                contrib.ErrMes = "No Commits Data  500";
                lstContrib.Add(contrib);
                rep.Contribs = lstContrib;
                currClient.Dispose();
                currClient = null;
                return;
            }

            JArray ContribList = null;
            int    Cnt         = 0;

            try
            {
                ContribList = JArray.Parse(jsonInput);
            }
            catch (Exception ex)
            {
                contrib        = new ContribCommit();
                contrib.Cnt    = 600;
                contrib.Url    = input;
                contrib.ErrNum = 600;
                contrib.ErrMes = "Contrib Array Error 600 - " + ex.Message;
                lstContrib.Add(contrib);
                rep.Contribs = lstContrib;
                currClient.Dispose();
                currClient = null;
                return;
            }

            for (Cnt = 0; Cnt < ContribList.Count; Cnt++)
            {
                List <ContribCommit> lstContribLogin = GetCommits(ContribList, input, Cnt);
                if (lstContribLogin.Count == 0)
                {
                    continue;
                }
                for (int i = 0; i < lstContribLogin.Count; i++)
                {
                    lstContrib.Add(lstContribLogin[i]);
                }
            }

            rep.Contribs = lstContrib;
        }
Exemple #9
0
        public void TestContribs11()
        {
            //** Avoid certificate error
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            FillWeeks();

            //** Format URL string
            //string input = "https://api.github.com/repos/PoC-Consortium/burstcoin-db-manager/stats/contributors?access_token=70cc8216843131458601b3f85a9cb7420079f9a5";
            //string input = "https://api.github.com/repos/216k155/lux/stats/contributors?access_token=70cc8216843131458601b3f85a9cb7420079f9a5";
            // - has error 500 !! string input = "https://api.github.com/repos/aurarad/auroracoin-old/stats/contributors?access_token=70cc8216843131458601b3f85a9cb7420079f9a5";
            //string input = "https://api.github.com/repos/aurarad/bitcoinj-scrypt/stats/contributors?access_token=70cc8216843131458601b3f85a9cb7420079f9a5";
            //string input = "https://api.github.com/repos/ArkEcosystem/ark-kotlin/stats/contributors?access_token=70cc8216843131458601b3f85a9cb7420079f9a5";
            //string input = "https://api.github.com/repos/xenonflux/1337/stats/contributors?access_token=70cc8216843131458601b3f85a9cb7420079f9a5";
            string    input      = "https://api.github.com/repos/bounty0x/TelegramBots/stats/contributors?access_token=70cc8216843131458601b3f85a9cb7420079f9a5";
            WebClient currClient = new WebClient();

            currClient.Headers.Add("user-agent", "karloskolley");
            string jsonInput = currClient.DownloadString(input);

            ContribCommit        contrib    = null;
            List <ContribCommit> lstContrib = new List <ContribCommit>();
            Repo rep = new Repo();

            if (jsonInput.Equals(string.Empty))
            {
                contrib        = new ContribCommit();
                contrib.ErrNum = 400;
                contrib.ErrMes = "No Commits Data - 400";
                lstContrib.Add(contrib);
                rep.Contribs = lstContrib;
                return;
            }

            if (jsonInput.Equals("{}"))
            {
                contrib        = new ContribCommit();
                contrib.ErrNum = 500;
                contrib.ErrMes = "No Commits Data - 500";
                lstContrib.Add(contrib);
                rep.Contribs = lstContrib;
                return;
            }

            JArray ContribList = null;
            int    Cnt         = 0;

            try
            {
                ContribList = JArray.Parse(jsonInput);
            }
            catch (Exception ex)
            {
                contrib        = new ContribCommit();
                contrib.ErrNum = 600;
                contrib.ErrMes = ex.Message;
                lstContrib.Add(contrib);
                rep.Contribs = lstContrib;
                return;
            }

            for (Cnt = 0; Cnt < ContribList.Count; Cnt++)
            {
                List <ContribCommit> lstContribLogin = GetCommits(ContribList, Cnt);
                if (lstContribLogin.Count == 0)
                {
                    continue;
                }
                lstContrib.AddRange(lstContribLogin);
            }

            rep.Contribs = lstContrib;
        }
        private void cmdRepeatCommit_Click(object sender, EventArgs e)
        {
            DbOper    dbOper       = new DbOper();
            DataTable dtRepCommits = dbOper.GetCommitsForRepeat();
            string    coinid       = "";
            string    symbol       = "";
            string    githubroot   = "";
            string    reponame     = "";
            string    repoid       = "";

            //** Secret Key
            string strGAuth = ConfigurationManager.AppSettings["gthauth"];
            ContribInfoCompiler ctrbListComp     = null;
            ContribCommit       cbcCommits       = null;
            StringBuilder       sbContribCommits = null;
            string DL = "|";

            foreach (DataRow dr in dtRepCommits.Rows)
            {
                coinid     = dr[0].ToString();
                symbol     = dr[1].ToString();
                githubroot = dr[2].ToString();
                repoid     = dr[3].ToString();
                reponame   = dr[4].ToString();

                Repo rpRepo = new Repo();
                rpRepo.RepoID   = repoid;
                rpRepo.RepoName = reponame;

                sbContribCommits = new StringBuilder();

                ctrbListComp = new ContribInfoCompiler(strGAuth);
                ctrbListComp.GetContribCommits(rpRepo, githubroot);

                for (int k = 0; k < rpRepo.Contribs.Count; k++)
                {
                    cbcCommits = rpRepo.Contribs[k];
                    if (cbcCommits == null)
                    {
                        continue;
                    }
                    sbContribCommits.Append(coinid + DL + symbol + DL + rpRepo.RepoID + DL + rpRepo.RepoName + DL + cbcCommits.LoginName + DL +
                                            cbcCommits.Additions + DL + cbcCommits.Deletions + DL + cbcCommits.Commits + DL + cbcCommits.CommTime + DL +
                                            cbcCommits.ErrNum.ToString() + DL + cbcCommits.ErrMes + DL + cbcCommits.Cnt.ToString() + DL + cbcCommits.Url + "\n");
                }

                if (sbContribCommits.Length > 0)
                {
                    dbOper.DeleteRepeatCommits(coinid, symbol, reponame);
                    if (dbOper.ErrNum > 0)
                    {
                        intErr = dbOper.ErrNum;
                        strErr = dbOper.ErrMes;
                    }

                    File.WriteAllText("contribinfo.txt", sbContribCommits.ToString());

                    dbOper.LoadHithubInfoTable("ContribInfo", "contribinfo.txt");
                    if (dbOper.ErrNum > 0)
                    {
                        intErr = dbOper.ErrNum;
                        strErr = dbOper.ErrMes;
                    }
                }

                Thread.Sleep(3000);
            }

            MessageBox.Show("Success!");
        }