diff --git a/src/FilterLists.Services/FilterLists.Services.csproj b/src/FilterLists.Services/FilterLists.Services.csproj index 132e8ae0f..e30801363 100644 --- a/src/FilterLists.Services/FilterLists.Services.csproj +++ b/src/FilterLists.Services/FilterLists.Services.csproj @@ -31,7 +31,6 @@ - diff --git a/src/FilterLists.Services/GitHub/GitHubService.cs b/src/FilterLists.Services/GitHub/GitHubService.cs deleted file mode 100644 index edbea3552..000000000 --- a/src/FilterLists.Services/GitHub/GitHubService.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using FilterLists.Services.GitHub.Models; -using JetBrains.Annotations; -using Octokit; - -namespace FilterLists.Services.GitHub -{ - [UsedImplicitly] - public class GitHubService - { - private const string RawFileUrlRoot = "raw.githubusercontent.com"; - private const string ProductHeader = "FilterLists"; - private const string ReadOnlyPersonalAccessToken = "25ef3c8e20d2fcacf1583e7650b63cfa3e784fec"; - private readonly GitHubClient client; - - public GitHubService() => - client = new GitHubClient(new ProductHeaderValue(ProductHeader)) - { - Credentials = new Credentials(ReadOnlyPersonalAccessToken) - }; - - public async Task GetCommitDatesAsync(string rawFileUrl) - { - if (!IsValidUrl(rawFileUrl)) - return null; - var commits = await GetAllCommits(rawFileUrl); - return new CommitDates - { - First = commits.LastOrDefault()?.Commit.Author.Date.DateTime, - Last = commits.FirstOrDefault()?.Commit.Author.Date.DateTime - }; - } - - private static bool IsValidUrl(string fileRawUrl) => fileRawUrl.Contains(RawFileUrlRoot); - - private async Task> GetAllCommits(string rawFileUrl) - { - var meta = ParseMeta(rawFileUrl); - return await client.Repository.Commit.GetAll( - meta.Owner, - meta.RepositoryName, - new CommitRequest {Path = meta.FilePath}); - } - - private static FileMeta ParseMeta(string rawFileUrl) - { - var urlPath = rawFileUrl.Split(new[] {RawFileUrlRoot}, StringSplitOptions.None)[1]; - var urlPathSlugs = urlPath.Split('/'); - var filePath = string.Empty; - for (var i = 4; i < urlPathSlugs.Length; i++) - filePath = filePath + '/' + urlPathSlugs[i]; - return new FileMeta - { - Owner = urlPathSlugs[1], - RepositoryName = urlPathSlugs[2], - FilePath = filePath.Substring(1) - }; - } - - private class FileMeta - { - public string Owner { get; set; } - public string RepositoryName { get; set; } - public string FilePath { get; set; } - } - } -} \ No newline at end of file diff --git a/src/FilterLists.Services/GitHub/Models/CommitDates.cs b/src/FilterLists.Services/GitHub/Models/CommitDates.cs deleted file mode 100644 index 421291c38..000000000 --- a/src/FilterLists.Services/GitHub/Models/CommitDates.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; - -namespace FilterLists.Services.GitHub.Models -{ - public class CommitDates - { - public DateTime? First { get; set; } - public DateTime? Last { get; set; } - } -} \ No newline at end of file diff --git a/tests/FilterLists.Services.Tests/GitHubServiceTests.cs b/tests/FilterLists.Services.Tests/GitHubServiceTests.cs deleted file mode 100644 index 466ea290a..000000000 --- a/tests/FilterLists.Services.Tests/GitHubServiceTests.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; -using System.Threading.Tasks; -using FilterLists.Services.GitHub; -using FilterLists.Services.GitHub.Models; -using Xunit; - -namespace FilterLists.Services.Tests -{ - public class GitHubServiceTests - { - [Fact] - public async Task GetCommitDatesAsync_InvalidGitHubRawUrl_ReturnsNull() - { - const string url = "https://github.com/collinbarrett/FilterLists/blob/master/.gitattributes"; - var actualDates = await new GitHubService().GetCommitDatesAsync(url); - Assert.Null(actualDates); - } - - [Fact] - public async Task GetCommitDatesAsync_ValidGitHubRawUrl_ReturnsCorrectFirstAndLastCommitDates() - { - const string url = "https://raw.githubusercontent.com/collinbarrett/FilterLists/master/LICENSE"; - var expectedDates = new CommitDates - { - First = DateTime.Parse("2016-12-10T20:28:16.0000000"), - Last = DateTime.Parse("2018-01-24T00:08:21.0000000") - }; - var actualDates = await new GitHubService().GetCommitDatesAsync(url); - Assert.Equal(expectedDates.First, actualDates.First); - Assert.Equal(expectedDates.Last, actualDates.Last); - } - - [Fact] - public async Task GetCommitDatesAsync_ValidGitHubRawUrlToNonexistentFile_ReturnsNull() - { - const string url = "https://github.com/collinbarrett/FilterLists/blob/master/doesnotexist"; - var actualDates = await new GitHubService().GetCommitDatesAsync(url); - Assert.Null(actualDates); - } - - [Fact] - public async Task GetCommitDatesAsync_ValidGitHubRawUrlWithOnlyOneCommit_ReturnsSameFirstAndLastCommitDates() - { - const string url = "https://raw.githubusercontent.com/collinbarrett/FilterLists/master/.gitattributes"; - var expectedDate = DateTime.Parse("2017-04-08T00:05:26.0000000"); - var actualDates = await new GitHubService().GetCommitDatesAsync(url); - Assert.Equal(expectedDate, actualDates.First); - Assert.Equal(expectedDate, actualDates.Last); - } - } -} \ No newline at end of file