Ejemplo n.º 1
0
        public void QueueRequest(MergeRequest mergeRequest)
        {
            // initially update the merge request with information from the POST request (or wherever it came from).
            // we might do another update later to make sure the data is still relevant.
            UpdateIssueDetails(mergeRequest, mergeRequest.IssueDetails);
            if (!ShouldTryToMerge(mergeRequest))
            {
                return;
            }

            Task.Run(() =>
            {
                bool shouldMerge;
                if (mergeRequest.IssueDetails == null)
                {
                    Logger.Info(m => m("Got a merge request without associated Jira issue. Guess we should merge that one either way."));
                    shouldMerge = true;
                }
                else
                {
                    Logger.Debug(m => m("Waiting a bit before queuing merge request for '{0}'", mergeRequest.IssueDetails.Key));
                    // wait a bit before actually queuing the request; someone might have accidentally closed the Jira issue
                    Thread.Sleep(_gitSettings.MergeDelay);

                    var issueDetails = _jira.GetIssueDetails(mergeRequest.IssueDetails.Key);
                    if (issueDetails == null)
                    {
                        Logger.Warn(m => m("Jira didn't return any issue information while trying to check if we should still merge '{0}'; not doing a merge.", mergeRequest.IssueDetails.Key));
                        shouldMerge = false;
                    }
                    else if (!_jiraSettings.ClosedStatus.Contains(issueDetails.Status))
                    {
                        Logger.Info(m => m("Related Jira issue is NOT closed; not doing a merge."));
                        shouldMerge = false;
                    }
                    else
                    {
                        shouldMerge = !ShouldPreventAutomerge(issueDetails);
                        Logger.Info(m => m("Related Jira issue indicates it should {0}be merged, {0}preceding with merge.", shouldMerge ? "" : "not "));
                        if (shouldMerge)
                        {
                            UpdateIssueDetails(mergeRequest, issueDetails);
                        }
                    }
                }

                if (shouldMerge)
                {
                    // HandleMergeRequests should only get valid ones, so check if the request is still valid
                    _mergeRequests.Add(mergeRequest);
                }
            });
        }
Ejemplo n.º 2
0
        public IHttpActionResult Post([FromBody] JiraCommentRequest request)
        {
            string issueKey = request.IssueKey;
            string comment  = request.Comment;
            var    issue    = _jira.GetIssueDetails(issueKey);

            if (issue == null)
            {
                return(BadRequest($"No issue with key '{issueKey}' exists."));
            }
            _jira.PostComment(issueKey, comment);
            return(Ok());
        }