Example #1
0
        public static void GitDiffLineNumberTest(int Line, int?ExceptedLine)
        {
            GitAPI git = new GitAPI(GitRepPath);

            var RepositoryObject = new DbObjectRepository("SIA", "BLAMETEST", "PROCEDURE");

            RepositoryObject.DirectoriesChecks();

            repository.AddFile(RepositoryObject);
            repository.StageAll();
            repository.DoCommit("add test blame");

            var lines = File.ReadAllLines(RepositoryObject.GetRawFilePath()).ToList();

            lines[10] = "HOP";                  // Подменяем строку 11
            lines.RemoveAt(11);                 // Удаляем строку 12
            lines[25] = "REPLACE NEW LINE!";    // Подменяем строку 25
            lines.Insert(26, "ins26");          // Добавляем строку 26
            lines.Insert(27, "ins27");          // Добавляем строку 27

            IDbObjectText dbObj = new DbObjectText(RepositoryObject, string.Join("\r\n", lines));

            int?val = git.GitDiffLineNumber(dbObj, Line);

            Assert.AreEqual(ExceptedLine, val);
        }
        public IActionResult GitRepositories()
        {
            GitAPI repos = new GitAPI("https://api.github.com/user/repos", _config["AJAX:GitToken"], "quinceyfreeman");
            IEnumerable <Repository> repositories = repos.getUserRepos();

            return(Json(repositories));
        }
        public IActionResult GitUser()
        {
            GitAPI user = new GitAPI("https://api.github.com/user", _config["AJAX:GitToken"], "quinceyfreeman");
            User   data = user.getUserData();

            return(Json(data));
        }
Example #4
0
        public static void GetBlameCommitsInfo()
        {
            GitAPI cmd     = new GitAPI(GitRepPath);
            var    commits = cmd.GetBlameCommitsInfo(repository.Files.Last(), 2, 4);

            Console.WriteLine($"Commit INFO >>\n{commits.First()}\n<<");
            Assert.AreEqual(1, commits.Count);
        }
        public IActionResult GitCommits(string user, string repo)
        {
            string url   = "https://api.github.com/repos/" + user + "/" + repo + "/commits";
            GitAPI repos = new GitAPI(url, _config["AJAX:GitToken"], "quinceyfreeman");
            IEnumerable <Commit> commits = repos.getCommits();

            return(Json(commits));
        }
Example #6
0
        /// <summary>
        /// sync commit to database
        /// </summary>
        /// <param name="value"></param>
        // POST api/<controller>
        public IHttpActionResult Post()
        {
            var codes = dal.GetAll <Code>();

            foreach (var item in codes)
            {
                GitAPI gitApi = new GitAPI();
                gitApi.GetGitHubCommitObject(item.GitHubUrl).ConvertToCommit(gitApi.CommitBody, item.id).InsertToDatabase(gitApi.Commits, dal, item.GitHubUrl);
            }
            return(Ok());
        }
        public IActionResult Index()
        {
            var    model = new ViewModel();
            GitAPI user  = new GitAPI("https://api.github.com/user", _config["AJAX:GitToken"], "quinceyfreeman");
            GitAPI repos = new GitAPI("https://api.github.com/user/repos", _config["AJAX:GitToken"], "quinceyfreeman");

            model.UserData     = user.getUserData();
            model.Repositories = repos.getUserRepos();

            return(View(model));
        }
Example #8
0
        public static void GitBLame_ReturnListOfRows(int BegLine, int EndLine, int ExceptedRowCnt)
        {
            GitAPI cmd             = new GitAPI(GitRepPath);
            var    ListOrBlameRows = cmd.GitBlame <List <string> >(repository.Files.Last(), BegLine, EndLine);

            Console.WriteLine("Blame Row(s):");
            ListOrBlameRows.ForEach(x => Console.WriteLine($"[{x}]"));

            Assert.IsTrue(ListOrBlameRows.Count(x => string.IsNullOrEmpty(x)) == 0, "Blame вернул пустую строку!");
            Assert.AreEqual(ExceptedRowCnt, ListOrBlameRows.Count, "Кол-во строк после операции Blame не верное");
            Assert.Pass();
        }
Example #9
0
        public static void GitShow_ReturnTextOfCommit(bool ShortStat, int ExceptedRowCount)
        {
            string TestCommitSHA = repository.GetCommits().First();
            GitAPI cmd           = new GitAPI(GitRepPath);

            var CommitAsString = cmd.GitShow <string>(TestCommitSHA, ShortStat);

            Assert.AreEqual(ExceptedRowCount, CommitAsString.Count(x => x == '\n'));

            var CommitAsListString = cmd.GitShow <List <string> >(TestCommitSHA, ShortStat);

            Assert.AreEqual(ExceptedRowCount, CommitAsListString.Count());
        }
Example #10
0
        public static void GetCommitInfo_AllFieldsHasValue()
        {
            string TestCommitSHA = repository.GetCommits().First();

            GitAPI     cmd    = new GitAPI(GitRepPath);
            CommitInfo commit = cmd.GetCommitInfo(TestCommitSHA);

            Console.WriteLine($"Commit INFO >>\n{commit}\n<<");

            Assert.NotZero(commit.SHA.Length, "SHA не заполнен");
            Assert.AreEqual(TestCommitSHA, commit.SHA, "SHA коммита не верный");
            Assert.NotZero(commit.Author.Length, "Автор не заполнен");
            Assert.NotZero(commit.EMail.Length, "EMail не заполнен");
            Assert.IsTrue(commit.Date > DateTime.Now.AddMinutes(-5), "Проблема с датой");
        }
Example #11
0
        /// <summary>
        /// sync all issues to database
        /// </summary>
        /// <param name="value"></param>
        // POST api/<controller>
        public HttpStatusCodeResult Post()
        {
            if (!ModelState.IsValid)
            {
                var errors = ModelState.Values.SelectMany(v => v.Errors).Select(e => e.Exception);
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, string.Join(" | ", errors)));
            }
            var codes = dal.GetAll <Code>();

            foreach (var item in codes)
            {
                GitAPI api = new GitAPI();
                api.GetGitHubIssueObject(item.GitHubUrl).ConvertToIssue(api.issueBody, item.id).InsertToDatabase(api.issues, dal);
            }
            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
Example #12
0
        public static void GitGetCurrentBranch()
        {
            string BranchMaster = "master";
            string Branch1      = "feature/SomeImportantTask";
            string Branch2      = "X123_ddE";

            GitAPI GitAPI = new GitAPI(GitRepPath);

            Assert.AreEqual(BranchMaster, GitAPI.GetCurrentBranch());

            repository.CheckoutBranch(Branch1, true);
            Assert.AreEqual(Branch1, GitAPI.GetCurrentBranch());

            repository.CheckoutBranch(Branch2, true);
            Assert.AreEqual(Branch2, GitAPI.GetCurrentBranch());

            repository.CheckoutBranch(Branch1, false);
            Assert.AreEqual(Branch1, GitAPI.GetCurrentBranch());

            repository.CheckoutBranch(BranchMaster, false);
            Assert.AreEqual(BranchMaster, GitAPI.GetCurrentBranch());
        }