Esempio n. 1
0
        private async IAsyncEnumerable <LeaderboardEntryModel> FetchPrs()
        {
            foreach (var username in _usernames)
            {
                await AwaitRateLimit();

                var user = await _gitHubClient.User.Get(username);

                var result = await _gitHubClient.Search.SearchIssues(new SearchIssuesRequest
                {
                    Author  = username,
                    Type    = IssueTypeQualifier.PullRequest,
                    Is      = new [] { IssueIsQualifier.Public },
                    Created = DateRange.Between(
                        new DateTimeOffset(_searchYear, 10, 1, 0, 0, 0, TimeSpan.Zero),
                        new DateTimeOffset(_searchYear, 10, 31, 23, 59, 59, TimeSpan.Zero)),
                    Exclusions = new SearchIssuesRequestExclusions {
                        Labels = new [] { "invalid" },
                    },
                    PerPage = 1,
                });

                yield return(new LeaderboardEntryModel
                {
                    Name = user.Name,
                    PrCount = result.TotalCount,
                    Username = user.Login,
                    AvatarUrl = user.AvatarUrl,
                });
            }
        }
        public static void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton(Configuration);
            services.AddSingleton(new GitHubClient(new ProductHeaderValue("GitHub-repo-finder-for-dead-links-in-readmes")));

            services.AddSingleton(new SearchRepositoriesRequest()
            {
                // lets find a library with over ? stars
                Stars = Octokit.Range.GreaterThan(5000),
                //Stars = Octokit.Range.LessThan(1),

                // check for repos that have been updated between a given date range?
                Updated = DateRange.Between(DateTimeOffset.UtcNow.AddHours(-1), DateTimeOffset.UtcNow),

                // orrder by?
                SortField = RepoSearchSort.Updated,
                Order     = SortDirection.Descending,
            });

            var linkGetter = new LinkGetter(new HttpClient(), "readme");

            services.AddTransient <ILinkGetter>(s => linkGetter);
            services.AddTransient <ILinkChecker>(s => new LinkChecker(new HttpClient(), linkGetter));

            services.AddTransient <ProgramUI, ProgramUI>();
            services.AddTransient <IFileNameFromUri, FileNameFromUri>();


            services.AddSingleton <IUriFinder, GitHubActiveReposFinder>();
        }
Esempio n. 3
0
        private DateRange getCreatedAtParameter(string dateChoice, DateTime?startDate, DateTime?endDate)
        {
            if (!startDate.HasValue)
            {
                return(null);
            }

            if (dateChoice.Equals("Created after"))
            {
                return(DateRange.GreaterThanOrEquals(startDate.Value));
            }
            else if (dateChoice.Equals("Created before"))
            {
                return(DateRange.LessThanOrEquals(startDate.Value));
            }
            else
            {
                if (endDate.HasValue)
                {
                    return(DateRange.Between(startDate.Value, endDate.Value));
                }

                return(DateRange.GreaterThanOrEquals(startDate.Value));
            }
        }
    public void ShouldGetAllowedDateTimeRanges()
    {
        var schedule = Schedule
                       .On(new YearDay(4, 18), new YearDay(9, 7))
                       .At(TimeRange.From(10, 13).ForOneHour());
        var allowedDateTimeRanges = schedule.DateTimeRanges
                                    (
            DateRange.Between
            (
                new DateTime(2021, 9, 1),
                new DateTime(2021, 10, 11)
            )
                                    );

        Assert.That
        (
            allowedDateTimeRanges,
            Is.EqualTo
            (
                new[]
        {
            DateTimeRange.Between
            (
                new DateTime(2021, 9, 7, 10, 13, 0),
                new DateTime(2021, 9, 7, 11, 13, 0)
            )
        }
            )
        );
    }
Esempio n. 5
0
    public void ShouldBeInRange_WhenValueIsBetweenStartAndEnd()
    {
        var value     = DateTimeOffset.Now;
        var start     = value.AddDays(-1);
        var end       = value.AddDays(1);
        var dateRange = DateRange.Between(start, end);

        Assert.That(dateRange.IsInRange(start), Is.True);
        Assert.That(dateRange.IsInRange(start.AddDays(-1)), Is.False);
        Assert.That(dateRange.IsInRange(value), Is.True);
        Assert.That(dateRange.IsInRange(end), Is.True);
        Assert.That(dateRange.IsInRange(end.AddDays(1)), Is.False);
    }
    public void ShouldGetAllowedDateTimeRanges()
    {
        var schedule = Schedule
                       .First(DayOfWeek.Monday)
                       .OfEveryMonth()
                       .AndTheThird(DayOfWeek.Wednesday)
                       .OfEveryMonth()
                       .AndTheLast(DayOfWeek.Saturday)
                       .OfEveryMonth()
                       .At(TimeRange.From(21, 0).ForOneHour());
        var ranges = schedule.DateTimeRanges
                     (
            DateRange.Between
            (
                new DateTime(2021, 9, 24),
                new DateTime(2021, 10, 21)
            )
                     );

        Assert.That
        (
            ranges,
            Is.EqualTo
            (
                new[]
        {
            DateTimeRange.Between
            (
                new DateTime(2021, 9, 25, 21, 0, 0),
                new DateTime(2021, 9, 25, 22, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 4, 21, 0, 0),
                new DateTime(2021, 10, 4, 22, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 20, 21, 0, 0),
                new DateTime(2021, 10, 20, 22, 0, 0)
            )
        }
            ),
            "Should get allowed date time ranges"
        );
    }
    public void ShouldGetAllowedDateTimeRanges()
    {
        var schedule = Schedule
                       .On(DayOfWeek.Monday, DayOfWeek.Friday)
                       .At(TimeRange.From(10, 13).ForOneHour());
        var allowedTimes = schedule.DateTimeRanges
                           (
            DateRange.Between
            (
                new DateTime(2021, 10, 1),
                new DateTime(2021, 10, 11)
            )
                           );

        Assert.That
        (
            allowedTimes,
            Is.EqualTo
            (
                new[]
        {
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 1, 10, 13, 0),
                new DateTime(2021, 10, 1, 11, 13, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 4, 10, 13, 0),
                new DateTime(2021, 10, 4, 11, 13, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 8, 10, 13, 0),
                new DateTime(2021, 10, 8, 11, 13, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 11, 10, 13, 0),
                new DateTime(2021, 10, 11, 11, 13, 0)
            )
        }
            )
        );
    }
        private SearchIssuesRequest CreateQueryForNewItems(RepositoryConfiguration repoInfo, IssueIsQualifier issueType)
        {
            DateTime to = DateTime.UtcNow;
            DateTime fromTwoDaysBack = DateTime.UtcNow.AddDays(-2);

            SearchIssuesRequest requestOptions = new SearchIssuesRequest()
            {
#pragma warning disable CS0618 // Type or member is obsolete
                Created = DateRange.Between(fromTwoDaysBack, to),
#pragma warning restore CS0618 // Type or member is obsolete
                Order = SortDirection.Descending,
                Is    = new[] { IssueIsQualifier.Open, issueType },
                Repos = new RepositoryCollection()
            };

            requestOptions.Repos.Add(repoInfo.Owner, repoInfo.Name);

            return(requestOptions);
        }
Esempio n. 9
0
    public void ShouldGetAllowedDateTimeRanges()
    {
        var schedule = Schedule
                       .First(DayOfWeek.Monday).Of(Months.January)
                       .AndTheThird(DayOfWeek.Wednesday).Of(Months.June)
                       .AndTheLast(DayOfWeek.Saturday).Of(Months.October)
                       .At(TimeRange.From(21, 0).ForOneHour());
        var ranges = schedule.DateTimeRanges
                     (
            DateRange.Between
            (
                new DateTime(2021, 5, 1),
                new DateTime(2022, 2, 1)
            )
                     );

        Assert.That
        (
            ranges,
            Is.EqualTo
            (
                new[]
        {
            DateTimeRange.Between
            (
                new DateTime(2021, 6, 16, 21, 0, 0),
                new DateTime(2021, 6, 16, 22, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 30, 21, 0, 0),
                new DateTime(2021, 10, 30, 22, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2022, 1, 3, 21, 0, 0),
                new DateTime(2022, 1, 3, 22, 0, 0)
            )
        }
            ),
            "Should get allowed date time ranges"
        );
    }
Esempio n. 10
0
    public void ShouldGetDatesInRange()
    {
        var dateRange = DateRange.Between(new DateTime(2021, 9, 29), new DateTime(2021, 10, 2));
        var dates     = dateRange.Dates();

        Assert.That
        (
            dates,
            Is.EqualTo
            (
                new[]
        {
            new DateTime(2021, 9, 29),
            new DateTime(2021, 9, 30),
            new DateTime(2021, 10, 1),
            new DateTime(2021, 10, 2)
        }
            )
        );
    }
        public IActionResult Search(RepoCheckerModel repoChecker)
        {
            if (!string.IsNullOrWhiteSpace(repoChecker.SingleRepoUri))
            {
                repoChecker.Uris.Add(new Uri(repoChecker.SingleRepoUri));
            }
            else
            {
                _searchRepositoriesRequest.SortField = (RepoSearchSort)repoChecker.SearchSort;
                _searchRepositoriesRequest.Order     = (SortDirection)repoChecker.SortAscDsc;

                if (repoChecker.MinStar.HasValue && repoChecker.MinStar >= 0)
                {
                    _searchRepositoriesRequest.Stars = Octokit.Range.GreaterThanOrEquals(repoChecker.MinStar.Value);
                }
                else
                {
                    _searchRepositoriesRequest.Stars = Octokit.Range.GreaterThanOrEquals(0);
                }

                if (repoChecker.UpdatedAfter.HasValue && repoChecker.UpdatedAfter < DateTime.UtcNow)
                {
                    _searchRepositoriesRequest.Updated = DateRange.Between(repoChecker.UpdatedAfter.Value.ToUniversalTime(), DateTimeOffset.UtcNow);
                }

                _searchRepositoriesRequest.User = repoChecker.User;

                int maxRepos = repoChecker.NumberOfReposToSearchFor ?? 5;
                // prevent to many repos to search
                if (maxRepos > 25)
                {
                    maxRepos = 2;
                }

                IEnumerable <Uri> uris = _gitHubActiveReposFinder.GetUris(maxRepos, _searchRepositoriesRequest);
                repoChecker.Uris.AddRange(uris);
            }

            return(View("Index", repoChecker));
        }
    public void ShouldGetAllowedDates()
    {
        var schedule = Schedule
                       .Every(3).Months().Starting(new DateTime(2021, 10, 5))
                       .At(TimeRange.From(19, 35).ForOneHour());
        var allowedDateTimeRanges = schedule.DateTimeRanges
                                    (
            DateRange.Between
            (
                new DateTime(2021, 10, 1),
                new DateTime(2022, 4, 6)
            )
                                    );

        Assert.That
        (
            allowedDateTimeRanges,
            Is.EqualTo
            (
                new[]
        {
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 5, 19, 35, 0),
                new DateTime(2021, 10, 5, 20, 35, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2022, 1, 5, 19, 35, 0),
                new DateTime(2022, 1, 5, 20, 35, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2022, 4, 5, 19, 35, 0),
                new DateTime(2022, 4, 5, 20, 35, 0)
            )
        }
            )
        );
    }
Esempio n. 13
0
    public void ShouldGetDateTimeRanges()
    {
        var schedule = Schedule
                       .On(new MonthDay(1), new MonthDay(12), new MonthDay(15))
                       .At(TimeRange.From(22, 0).ForOneHour());
        var ranges = schedule.DateTimeRanges
                     (
            DateRange.Between
            (
                new DateTime(2021, 10, 2),
                new DateTime(2021, 10, 20)
            )
                     );

        Assert.That
        (
            ranges,
            Is.EqualTo
            (
                new[]
        {
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 12, 22, 0, 0),
                new DateTime(2021, 10, 12, 23, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 15, 22, 0, 0),
                new DateTime(2021, 10, 15, 23, 0, 0)
            )
        }
            ),
            "Should be in range when date is on an allowed day of the month"
        );
    }
Esempio n. 14
0
        public override void Execute()
        {
            _log.LogInformation($"Started function execution: {DateTime.Now}");

            var storageConnString   = Environment.GetEnvironmentVariable("AzureWebJobsStorage");
            BlobServiceClient   bsc = new BlobServiceClient(storageConnString);
            BlobContainerClient bcc = bsc.GetBlobContainerClient(ContainerName);

            // create the container
            bcc.CreateIfNotExists();

            _log.LogInformation("Storage account accessed");

            DateTime to = DateTime.UtcNow;
            DateTime fromTwoDaysBack = DateTime.UtcNow.AddDays(-2);

            foreach (var repositoryConfig in _cmdLine.RepositoriesList)
            {
                // retrieve the last accessed time for this repository
                BlobClient bc          = bcc.GetBlobClient($"{repositoryConfig.Owner}_{repositoryConfig.Repo}");
                DateTime   lastDateRun = DateTime.UtcNow.AddDays(-1);

                try
                {
                    string content = StreamHelpers.GetContentAsString(bc.Download().Value.Content);
                    lastDateRun = DateTime.Parse(content);
                }
                catch
                {
                }

                _log.LogInformation("Last processed date for {0} is {1}", repositoryConfig, lastDateRun);

                string owner = repositoryConfig.Owner;
                string repo  = repositoryConfig.Repo;

                _log.LogInformation("Processing repository {0}\\{1}", owner, repo);

                HtmlPageCreator emailBody = new HtmlPageCreator($"New items in {repo}");

                SearchIssuesRequest requestOptions = new SearchIssuesRequest()
                {
#pragma warning disable CS0618 // Type or member is obsolete
                    Created = DateRange.Between(fromTwoDaysBack, to),
#pragma warning restore CS0618 // Type or member is obsolete
                    Order = SortDirection.Descending,
                    Repos = new RepositoryCollection()
                };

                requestOptions.Repos.Add(owner, repo);

                // get the issues
                requestOptions.Is = new[] { IssueIsQualifier.Open, IssueIsQualifier.Issue };
                RetrieveItemsFromGitHub(requestOptions, lastDateRun, emailBody, "New issues");

                // get the PRs
                requestOptions.Is = new[] { IssueIsQualifier.Open, IssueIsQualifier.PullRequest };
                RetrieveItemsFromGitHub(requestOptions, lastDateRun, emailBody, "New PRs");

                emailBody.AddContent($"<p>Last checked range: {lastDateRun} -> {to} </p>");

                _log.LogInformation("Sending email...");
                // send the email
                EmailSender.SendEmail(_cmdLine.EmailToken, _cmdLine.FromEmail, emailBody.GetContent(), repositoryConfig.ToEmail, repositoryConfig.CcEmail, $"New issues in the {repo} repo as of {to.ToShortDateString()}", _log);

                _log.LogInformation("Email sent...");

                bc.Upload(StreamHelpers.GetStreamForString(to.ToUniversalTime().ToString()), overwrite: true);
                _log.LogInformation($"Persisted last event time for {repositoryConfig.Owner}\\{repositoryConfig.Repo} as {to}");
            }
        }
Esempio n. 15
0
    public void ShouldDeserializeSchedule()
    {
        var schedule = new AggregateSchedule
                       (
            Schedule.On(DayOfWeek.Monday)
            .At(TimeRange.From(10, 0).ForOneHour()),
            Schedule.On(new MonthDay(15))
            .At(TimeRange.From(11, 0).ForOneHour()),
            Schedule.First(DayOfWeek.Monday).OfEveryMonth()
            .At(TimeRange.From(12, 0).ForOneHour()),
            Schedule.On(new YearDay(10, 13))
            .At(TimeRange.From(13, 0).ForOneHour()),
            Schedule.First(DayOfWeek.Tuesday).Of(Months.October)
            .At(TimeRange.From(14, 0).ForOneHour()),
            Schedule.Every(2).Weeks().Starting(new DateTime(2021, 10, 12))
            .At(TimeRange.From(15, 0).ForOneHour())
                       );
        var serialized   = schedule.Serialize();
        var deserialized = AggregateSchedule.Deserialize(serialized);

        Assert.That
        (
            deserialized.DateTimeRanges
            (
                DateRange.Between(new DateTime(2021, 10, 1), new DateTime(2021, 10, 31))
            ),
            Is.EqualTo
            (
                new[]
        {
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 4, 10, 0, 0),
                new DateTime(2021, 10, 4, 11, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 4, 12, 0, 0),
                new DateTime(2021, 10, 4, 13, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 5, 14, 0, 0),
                new DateTime(2021, 10, 5, 15, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 11, 10, 0, 0),
                new DateTime(2021, 10, 11, 11, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 12, 15, 0, 0),
                new DateTime(2021, 10, 12, 16, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 13, 13, 0, 0),
                new DateTime(2021, 10, 13, 14, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 15, 11, 0, 0),
                new DateTime(2021, 10, 15, 12, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 18, 10, 0, 0),
                new DateTime(2021, 10, 18, 11, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 25, 10, 0, 0),
                new DateTime(2021, 10, 25, 11, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 26, 15, 0, 0),
                new DateTime(2021, 10, 26, 16, 0, 0)
            )
        }
            )
        );
    }