Ejemplo n.º 1
0
        public async Task GetRepositoryInformation(RepositoryInput input)
        {
            string path = $"https://api.github.com/repos/{input.Login}/{input.RepositoryName}/commits";

            Client.BaseAddress = new Uri(path);
            Client.DefaultRequestHeaders.Accept.Clear();
            Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            Client.DefaultRequestHeaders.UserAgent.TryParseAdd("request");

            HttpResponseMessage response = await Client.GetAsync(path);

            if (response.IsSuccessStatusCode)
            {
                response.EnsureSuccessStatusCode();
                string responseBody = await response.Content.ReadAsStringAsync();

                CommitsList = JsonSerializer.Deserialize <List <CommitEntry> >(responseBody);
                DisplayCommitsEntries(input, CommitsList);
            }
            else
            {
                Console.WriteLine("Application was unable to get repository information");
            }
            Client.CancelPendingRequests();
        }
Ejemplo n.º 2
0
        private static async Task MainAsync(RepositoryInput repositoryInput)
        {
            RESTConnector RESTConnector = new RESTConnector();
            await RESTConnector.GetRepositoryInformation(repositoryInput);

            DatabaseConnector DatabaseConnector = new DatabaseConnector();
            await DatabaseConnector.SaveCommitsEntriesToDatabase(repositoryInput, RESTConnector.CommitsList);
        }
Ejemplo n.º 3
0
 private void DisplayCommitsEntries(RepositoryInput input, List <CommitEntry> commitEntries)
 {
     if (commitEntries.Any())
     {
         foreach (CommitEntry entry in commitEntries)
         {
             Console.WriteLine($"[{input.RepositoryName}]/[{entry.sha}]: {entry.commit.message} [{entry.commit.committer.name}]");
         }
     }
     else
     {
         Console.WriteLine("Application was unable to display commit details.");
     }
 }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            string command = "";

            while (command != "exit")
            {
                var repositoryInput = new RepositoryInput();

                Console.WriteLine("Hello there! You are in GitHubConnector application");
                Console.WriteLine("To close the application, write 'exit'");

                Console.WriteLine("Lets start - please enter name of GitHub user: "******"Please enter name of repository: ");
                repositoryInput.RepositoryName = Console.ReadLine();

                MainAsync(repositoryInput);

                Console.ReadKey();
                Console.Clear();
            }
        }
Ejemplo n.º 5
0
        public async Task SaveCommitsEntriesToDatabase(RepositoryInput repositoryInput, List <CommitEntry> commitEntries)
        {
            await CreateTable();

            try
            {
                using (SqlConnection = new SqlConnection(GetConnectionStringsFromConfiguratioFile()))
                {
                    var sqlCommand = new SqlCommand();
                    sqlCommand.Connection = SqlConnection;

                    sqlCommand.CommandText = @"INSERT INTO CommitEntry (SHA, Committer, Message)
											VALUES (@SHA, @Committer, @Message);"                                            ;

                    SqlConnection.Open();

                    foreach (var commit in commitEntries)
                    {
                        sqlCommand.Parameters.Clear();
                        sqlCommand.Parameters.AddWithValue("@SHA", commit.sha);
                        sqlCommand.Parameters.AddWithValue("@Committer", commit.commit.committer.name);
                        sqlCommand.Parameters.AddWithValue("@Message", commit.commit.message);
                        sqlCommand.ExecuteNonQuery();
                    }
                    Console.WriteLine($"Saving data in database complete");
                    SqlConnection.Close();
                }
            }
            catch (SqlException e)
            {
            }
            catch (Exception e)
            {
                Console.WriteLine($"Application was unable to save information on database:{e.Message}");
            }
        }