Ejemplo n.º 1
0
        public async Task <ActionResult <IssueMoveResult> > MoveIssue(
            string toOwnerName, string toRepoName,
            [FromBody] IssueMoveRequest issueMoveRequest)
        {
            var accessToken = await HttpContext.GetTokenAsync("access_token");

            var gitHub = GitHubUtils.GetGitHubClient(accessToken);

            var destinationMilestones = await gitHub.Issue.Milestone.GetAllForRepository(toOwnerName, toRepoName);

            try
            {
                // Create new issue
                var newIssueDetails = new NewIssue(issueMoveRequest.Title)
                {
                    Body = issueMoveRequest.Body,
                };
                if (issueMoveRequest.Milestone != null)
                {
                    // Set the milestone to the ID that matches the one in the destination repo, if it exists
                    var destinationMilestone = destinationMilestones.SingleOrDefault(m => string.Equals(m.Title, issueMoveRequest.Milestone, StringComparison.OrdinalIgnoreCase));
                    newIssueDetails.Milestone = destinationMilestone?.Number;
                }
                if (issueMoveRequest.Assignees != null)
                {
                    foreach (var assignee in issueMoveRequest.Assignees)
                    {
                        newIssueDetails.Assignees.Add(assignee);
                    }
                }
                if (issueMoveRequest.Labels != null)
                {
                    foreach (var label in issueMoveRequest.Labels)
                    {
                        newIssueDetails.Labels.Add(label);
                    }
                }

                var newIssueCreated = await gitHub.Issue.Create(toOwnerName, toRepoName, newIssueDetails);

                return(Ok(
                           new IssueMoveResult
                {
                    IssueNumber = newIssueCreated.Number,
                    HtmlUrl = newIssueCreated.HtmlUrl,
                }));
            }
            catch (Exception ex)
            {
                return(BadRequest(
                           new IssueMoveResult
                {
                    Exception = ex,
                }));
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <IssueMoveResult> > MoveIssue(
            string toOwnerName, string toRepoName,
            [FromBody] IssueMoveRequest issueMoveRequest)
        {
            try
            {
                var issueMoveresult = await IssueMoverService.MoveIssue(toOwnerName, toRepoName, issueMoveRequest);

                return(Ok(issueMoveresult));
            }
            catch (Exception ex)
            {
                return(BadRequest(
                           new IssueMoveResult
                {
                    ExceptionMessage = ex.Message,
                    ExceptionStackTrace = ex.StackTrace,
                }));
            }
        }
Ejemplo n.º 3
0
        public async Task <IssueMoveResult> MoveIssue(string destinationOwner, string destinationRepo, IssueMoveRequest issueMoveRequest)
        {
            var gitHub = await GitHubAccessor.GetGitHubClient();

            var destinationMilestones = await gitHub.Issue.Milestone.GetAllForRepository(destinationOwner, destinationRepo);

            // Create new issue
            var newIssueDetails = new NewIssue(issueMoveRequest.Title)
            {
                Body = issueMoveRequest.Body,
            };

            if (issueMoveRequest.Milestone != null)
            {
                // Set the milestone to the ID that matches the one in the destination repo, if it exists
                var destinationMilestone = destinationMilestones.SingleOrDefault(m => string.Equals(m.Title, issueMoveRequest.Milestone, StringComparison.OrdinalIgnoreCase));
                newIssueDetails.Milestone = destinationMilestone?.Number;
            }
            if (issueMoveRequest.Assignees != null)
            {
                foreach (var assignee in issueMoveRequest.Assignees)
                {
                    newIssueDetails.Assignees.Add(assignee);
                }
            }
            if (issueMoveRequest.Labels != null)
            {
                foreach (var label in issueMoveRequest.Labels)
                {
                    newIssueDetails.Labels.Add(label);
                }
            }

            var newIssueCreated = await gitHub.Issue.Create(destinationOwner, destinationRepo, newIssueDetails);

            return(new IssueMoveResult
            {
                IssueNumber = newIssueCreated.Number,
                HtmlUrl = newIssueCreated.HtmlUrl,
            });
        }
Ejemplo n.º 4
0
 public async Task <IssueMoveResult> MoveIssue(string destinationOwner, string destinationRepo, IssueMoveRequest issueMoveRequest)
 {
     return(await Http.PostJsonAsync <IssueMoveResult>($"https://localhost:44347/api/moveissue/{destinationOwner}/{destinationRepo}", issueMoveRequest));
 }