public async Task Update(Repository repository, Release release, List <GitHubCommit> commits)
        {
            var clients = await _gitHubClientFactory.Create();

            // Get the last registered formatter for the type.
            var formatter = _documentFormatters.LastOrDefault(x => x.Type.HasFlag(FormatterTypes.ChangeLog));

            if (formatter == null)
            {
                return;
            }

            var document = formatter.Format(release, commits);

            var changeLog =
                await clients.InstallationClient.Repository.Content.GetAllContentsOrNull(repository.Id,
                                                                                         _options.ChangeLogFileName);

            var repositoryContentChangeSet = changeLog != null
                ? await clients.InstallationClient.Repository.Content.UpdateFile(repository.Id,
                                                                                 _options.ChangeLogFileName,
                                                                                 new UpdateFileRequest($"Update {_options.ChangeLogFileName}",
                                                                                                       document.Content + ReleaseNotesConstants.VersionDivider + changeLog.Content, changeLog.Sha,
                                                                                                       true))
                : await clients.InstallationClient.Repository.Content.CreateFile(repository.Id,
                                                                                 _options.ChangeLogFileName,
                                                                                 new CreateFileRequest($"Create {_options.ChangeLogFileName}", document.Content, true));
        }
Beispiel #2
0
        public ChangeLogUpdaterTests()
        {
            _documentFormatters = new DocumentFormatterFaker().Generate(5);
            var test = Substitute.For <GitHubClients>();

            _gitHubClientFactory.Create().Returns(test);
            _sut = new ChangeLogUpdater(_gitHubClientFactory, _documentFormatters, _options);
        }
        public async Task Handle(WebHookEvent webHookEvent)
        {
            var clients = await _gitHubClientFactory.Create();

            var handlers = _webHookHandlerResolver.Resolve(webHookEvent.EventName,
                                                           webHookEvent.GenericPayload.Action, webHookEvent.IsBot);

            if (!handlers.Any())
            {
                return;
            }

            var context = new EventContext(_httpContextAccessor.HttpContext, webHookEvent, clients);

            handlers.ForEach(h => h.Handle(context));
        }
Beispiel #4
0
        public override async Task Execute()
        {
            _logger.LogDebug("Started job");
            _logger.LogTrace("Started job");
            _logger.LogInformation("Started job");
            _logger.LogWarning("Started job");
            _logger.LogError("Started job");
            _logger.LogCritical("Started job");

            var clients = await _gitHubClientFactory.Create();

            // var issue = await clients.InstallationClient.Issue.Create(RepositoryOwner, RepositoryName,
            //     new NewIssue($"Issue - {DateTime.Now}"));

            _logger.LogInformation("Completed job");
        }
Beispiel #5
0
        public async Task <List <GitHubCommit> > GetCommits(long repositoryId, int releaseId)
        {
            var clients = await _gitHubClientFactory.Create();

            var releases = await clients.InstallationClient.Repository.Release.GetAll(repositoryId);

            var newRelease      = releases.FirstOrDefault(r => r.Id == releaseId);
            var previousRelease = releases.FirstOrDefault(r => r.Id != releaseId);

            var commits = previousRelease != null
                ? await clients.InstallationClient.Repository.Commit.GetAll(repositoryId, new CommitRequest
            {
                Since = previousRelease.PublishedAt
            })
                : await clients.InstallationClient.Repository.Commit.GetAll(repositoryId);

            return(commits.ToList());
        }
        public async Task Update(Repository repository, Release release, List <GitHubCommit> commits)
        {
            var clients = await _gitHubClientFactory.Create();

            // Get the last registered formatter for the type.
            var formatter = _documentFormatters.LastOrDefault(x => x.Type.HasFlag(FormatterTypes.Release));

            if (formatter == null)
            {
                return;
            }

            var document = formatter.Format(release, commits);

            await clients.InstallationClient.Repository.Release.Edit(repository.Id, release.Id,
                                                                     new ReleaseUpdate
            {
                Name = document.Name,
                Body = document.Content
            });
        }
Beispiel #7
0
        public bool InitAccessToken(string accessToken)
        {
            _client = _clientFactory.Create(accessToken);

            return(_client != null);
        }