/// <summary>
        /// Creates an issue for the specified repository. Any user with pull access to a repository can create an
        /// issue.
        /// </summary>
        /// <remarks>http://developer.github.com/v3/issues/#create-an-issue</remarks>
        /// <param name="owner">The owner of the repository</param>
        /// <param name="name">The name of the repository</param>
        /// <param name="number">The issue number</param>
        /// <param name="issueUpdate">An <see cref="IssueUpdate"/> instance describing the changes to make to the issue
        /// </param>
        public IObservable <Issue> Update(string owner, string name, int number, IssueUpdate issueUpdate)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNull(issueUpdate, "issueUpdate");

            return(_client.Update(owner, name, number, issueUpdate).ToObservable());
        }
    public async Task CanCreateRetrieveAndCloseIssue()
    {
        var newIssue = new NewIssue("a test issue")
        {
            Body = "A new unassigned issue"
        };
        var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);

        try
        {
            Assert.NotNull(issue);

            var retrieved = await _issuesClient.Get(_context.RepositoryOwner, _context.RepositoryName, issue.Number);

            var all = await _issuesClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName);

            Assert.NotNull(retrieved);
            Assert.True(all.Any(i => i.Number == retrieved.Number));
        }
        finally
        {
            var closed = _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number,
                                              new IssueUpdate {
                State = ItemState.Closed
            })
                         .Result;
            Assert.NotNull(closed);
        }
    }
        private Task UpdateLabelsAndStateAsync(Issue issue, bool closeIssue)
        {
            IssueUpdate issueUpdate = issue.ToUpdate();

            issueUpdate.Labels.Remove(GitHubLabels.CodePlexMigrationInitiated);
            issueUpdate.Labels.Add(GitHubLabels.CodePlexMigrated);

            if (closeIssue)
            {
                issueUpdate.State = ItemState.Closed;
            }

            return(issues.Update(owner: repoOwner, name: repo, number: issue.Number, issueUpdate: issueUpdate));
        }
Beispiel #4
0
    public async Task CanListLabelsForAnIssue()
    {
        var newIssue = new NewIssue("A test issue")
        {
            Body = "A new unassigned issue"
        };
        var newLabel = new NewLabel("test label", "FFFFFF");

        var label = await _issuesLabelsClient.Create(_repositoryOwner, _repository.Name, newLabel);

        var issue = await _issuesClient.Create(_repositoryOwner, _repositoryName, newIssue);

        var issueLabelsInfo = await _issuesLabelsClient.GetForIssue(_repositoryOwner, _repositoryName, issue.Number);

        Assert.Empty(issueLabelsInfo);

        var issueUpdate = new IssueUpdate();

        issueUpdate.Labels.Add(label.Name);
        var updated = await _issuesClient.Update(_repositoryOwner, _repository.Name, issue.Number, issueUpdate);

        Assert.NotNull(updated);
        issueLabelsInfo = await _issuesLabelsClient.GetForIssue(_repositoryOwner, _repositoryName, issue.Number);

        Assert.Equal(1, issueLabelsInfo.Count);
        Assert.Equal(newLabel.Color, issueLabelsInfo[0].Color);
    }
        public async Task CanDeserializeRenameEvent()
        {
            var newIssue = new NewIssue("a test issue")
            {
                Body = "A new unassigned issue"
            };
            var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);

            var renamed = await _issuesClient.Update(_context.Repository.Id, issue.Number, new IssueUpdate { Title = "A test issue" });

            Assert.NotNull(renamed);
            Assert.Equal("A test issue", renamed.Title);

            var timelineEventInfos = await _issueTimelineClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number);

            Assert.Equal(1, timelineEventInfos.Count);
            Assert.Equal("a test issue", timelineEventInfos[0].Rename.From);
            Assert.Equal("A test issue", timelineEventInfos[0].Rename.To);
        }
Beispiel #6
0
    public async Task CanListEventInfoForAnIssue()
    {
        var newIssue = new NewIssue("a test issue")
        {
            Body = "A new unassigned issue"
        };
        var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);

        var issueEventInfo = await _issuesEventsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number);

        Assert.Empty(issueEventInfo);

        var closed = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, new IssueUpdate { State = ItemState.Closed });

        Assert.NotNull(closed);
        issueEventInfo = await _issuesEventsClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number);

        Assert.Equal(1, issueEventInfo.Count);
        Assert.Equal(EventInfoState.Closed, issueEventInfo[0].Event);
    }
        public async Task CanRetrieveTimelineForIssue()
        {
            var newIssue = new NewIssue("a test issue")
            {
                Body = "A new unassigned issue"
            };
            var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);

            var timelineEventInfos = await _issueTimelineClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number);

            Assert.Empty(timelineEventInfos);

            var closed = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, new IssueUpdate()
            {
                State = ItemState.Closed
            });

            Assert.NotNull(closed);

            timelineEventInfos = await _issueTimelineClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number);

            Assert.Equal(1, timelineEventInfos.Count);
            Assert.Equal(EventInfoState.Closed, timelineEventInfos[0].Event);
        }
Beispiel #8
0
        private async Task UpdateIssueAsync(PortingInfo ruleToPort, Issue existingIssue)
        {
            int issueNumber = existingIssue.Number;

            IssueUpdate issueUpdate = CreateIssueUpdate(ruleToPort, existingIssue);

            if (_options.DryRun)
            {
                _log.Info(Resources.InfoDryRunIssueNotUpdated);
            }
            else
            {
                await _issuesClient.Update(_options.RepoOwner, _options.RepoName, issueNumber, issueUpdate);

                _log.InfoFormat(Resources.InfoIssueUpdated, issueNumber);
            }

            // The GitHub Issues API doesn't let you add or remove individual labels in the course of
            // an Update operation. Use the IssuesLabels API to do that.
            await UpdateIssueLabelsAsync(ruleToPort, existingIssue);
        }
        private async Task UpdateGitHubIssues(IEnumerable <Issue> gitHubIssuesCreated, IEnumerable <GoogleIssue> googleIssues)
        {
            const string gitHubIssueNotFoundStringFormatTemplate = "ERROR: Unable to retrieve Issue #{0} from GitHub.";

            //convert to list to avoid re-enumeration of IEnumerable
            googleIssues = googleIssues.ToList();

            //final step, update each issue to reflect correct status, etc.
            foreach (var gitHubIssue in gitHubIssuesCreated)
            {
                var correspondingGoogleIssue = googleIssues.Single(s => s.Id == gitHubIssue.Number);

                //santity-check: ensure that the target issue actually exists on GitHub, report error if not found
                try
                {
                    var gitHubIssueToUpdate = await _issuesClient.Get(_settings.GitHubRepositoryOwner, _settings.GitHubRepositoryName, gitHubIssue.Number);

                    if (null == gitHubIssueToUpdate)
                    {
                        //just throw in order to end up in the catch block...
                        throw new Exception();
                    }
                }
                catch (Exception)
                {
                    Logger.ErrorFormat(gitHubIssueNotFoundStringFormatTemplate, correspondingGoogleIssue.Id);

                    //TODO: reconsider this choice to continue on here...since we require all GitHub issue numbers
                    // to match their Google Code issue numbers, its not ENTIRELY correct to just log-and-ignore this error condition...
                    continue;
                }

                //assuming we got this far, process the update...
                Logger.InfoFormat("Processing Update to Issue #{0}", correspondingGoogleIssue.Id);

                var issueUpdate = ComposeIssueUpdate(correspondingGoogleIssue);

                await _issuesClient.Update(_settings.GitHubRepositoryOwner, _settings.GitHubRepositoryName, gitHubIssue.Number, issueUpdate);
            }
        }