private void TopologicalSort(CommitNode node, List <Octokit.GitHubCommit> sortedCommits, HashSet <string> visitedNodes)
        {
            if (visitedNodes.Contains(node.GitHubCommit.Sha))
            {
                return;
            }

            visitedNodes.Add(node.GitHubCommit.Sha);

            foreach (var parent in node.Parents)
            {
                TopologicalSort(parent, sortedCommits, visitedNodes);
            }

            sortedCommits.Add(node.GitHubCommit);
        }
        private async Task AddCommitToTree(EventContext eventContext, Dictionary <string, CommitNode> dicCommits, long subscriptionId, long repositoryId, string commitSha, CommitNode childNode)
        {
            if (dicCommits.ContainsKey(commitSha))
            {
                return;
            }

            bool isAlreadyAnalyzed = IsCommitAlreadyAnalyzed(subscriptionId, commitSha);

            if (isAlreadyAnalyzed)
            {
                return;
            }

            var githubCommit = await eventContext.InstallationContext.Client.Repository.Commit.Get(repositoryId, commitSha);

            var commitNode = new CommitNode(githubCommit);

            if (childNode != null)
            {
                commitNode.IsRoot = false;
                dicCommits[childNode.GitHubCommit.Sha].Parents.Add(dicCommits[githubCommit.Sha]);
            }

            foreach (var parent in githubCommit.Parents)
            {
                if (!dicCommits.ContainsKey(parent.Sha))
                {
                    await AddCommitToTree(eventContext, dicCommits, subscriptionId, repositoryId, parent.Sha, dicCommits[githubCommit.Sha]);
                }
                else
                {
                    dicCommits[parent.Sha].IsRoot = false;
                    dicCommits[commitNode.GitHubCommit.Sha].Parents.Add(dicCommits[parent.Sha]);
                }
            }
        }