Пример #1
0
        public void Post([FromBody] JiraEvent jiraEvent, [FromQuery(Name = "user_id")] string userId)
        {
            try
            {
                //string test = jiraEvent.Content.ReadAsStringAsync().Result;
                _logger.LogDebug("JiraWebhookEvent key: " + jiraEvent.Issue.Key);

                if (!userId.ToLower().Equals(ApiUser))
                {
                    string origin = GetOrigin(jiraEvent);

                    if (isCreated(jiraEvent))
                    {
                        _publisher.OnInstanceCreatedAsync(jiraEvent.Issue.Key, userId);
                    }
                    else if (isUpdated(jiraEvent))
                    {
                        _publisher.OnInstanceUpdatedAsync(jiraEvent.Issue.Key, userId);
                    }
                    else if (isDeleted(jiraEvent))
                    {
                        _publisher.OnInstanceDeletedAsync(jiraEvent.Issue.Key, userId);
                    }
                }
            } catch (ProjectNotPresentException e)
            {
                _logger.LogDebug(e.Message);
                _logger.LogError(e.StackTrace);
            }
            catch (Exception e)
            {
                _logger.LogError("Unknown error occured", e.StackTrace);
            }
        }
Пример #2
0
        /// <summary>
        /// This method will update details, like the title, and send an event to registed listeners of the JiraEvent
        /// </summary>
        /// <param name="jiraDetails">Contains the jira key to retrieve the title (XYZ-1234)</param>
        /// <returns>Task</returns>
        private async Task DetectedNewJiraIssueAsync(JiraDetails jiraDetails)
        {
            try
            {
                IJiraClient jiraClient;
                if (_projectJiraClientMap.TryGetValue(jiraDetails.ProjectKey, out jiraClient))
                {
                    var issue = await jiraClient.Issue.GetAsync(jiraDetails.JiraKey).ConfigureAwait(false);

                    jiraDetails.JiraIssue = issue;
                }
                // Send event
                JiraEvent?.Invoke(this, new JiraEventArgs {
                    Details = jiraDetails, EventType = JiraEventTypes.DetectedNewJiraIssue
                });
            }
            catch (Exception ex)
            {
                Log.Warn().WriteLine("Couldn't retrieve JIRA title: {0}", ex.Message);
            }
        }
Пример #3
0
        /// <summary>
        /// Handle title changes, check for JIRA
        /// </summary>
        /// <param name="eventArgs"></param>
        private void MonitorTitleChangeEvent(TitleChangeEventArgs eventArgs)
        {
            string windowTitle = eventArgs.Title;

            if (string.IsNullOrEmpty(windowTitle))
            {
                return;
            }
            var jiraKeyMatch = _jiraKeyPattern.Match(windowTitle);

            if (!jiraKeyMatch.Success)
            {
                return;
            }
            // Found a possible JIRA title
            var jiraKey      = jiraKeyMatch.Value;
            var jiraKeyParts = jiraKey.Split('-');
            var projectKey   = jiraKeyParts[0];
            var jiraId       = jiraKeyParts[1];

            IJiraClient jiraClient;

            // Check if we have a JIRA instance with a project for this key
            if (_projectJiraClientMap.TryGetValue(projectKey, out jiraClient))
            {
                // We have found a project for this _jira key, so it must be a valid & known JIRA
                JiraDetails currentJiraDetails;
                if (_recentJiras.TryGetValue(jiraKey, out currentJiraDetails))
                {
                    // update
                    currentJiraDetails.SeenAt = DateTimeOffset.Now;

                    // Notify the order change
                    JiraEvent?.Invoke(this, new JiraEventArgs {
                        Details = currentJiraDetails, EventType = JiraEventTypes.OrderChanged
                    });
                    // Nothing else to do

                    return;
                }
                // We detected an unknown JIRA, so add it to our list
                currentJiraDetails = new JiraDetails
                {
                    Id         = jiraId,
                    ProjectKey = projectKey
                };
                _recentJiras.Add(currentJiraDetails.JiraKey, currentJiraDetails);

                // Make sure we don't collect _jira's until the memory is full
                if (_recentJiras.Count > _maxEntries)
                {
                    // Add it to the list of recent Jiras
                    _recentJiras = (from jiraDetails in _recentJiras.Values.ToList()
                                    orderby jiraDetails.SeenAt descending
                                    select jiraDetails).Take(_maxEntries).ToDictionary(jd => jd.JiraKey, jd => jd);
                }
                // Now we can get the title from JIRA itself
                // ReSharper disable once UnusedVariable
                var updateTitleTask = DetectedNewJiraIssueAsync(currentJiraDetails);
            }
            else
            {
                Log.Info().WriteLine("Couldn't match possible JIRA key {0} to projects in a configured JIRA instance, ignoring", projectKey);
            }
        }
Пример #4
0
 private string GetOrigin(JiraEvent jiraEvent)
 {
     return(jiraEvent.Issue.Self.Split("rest")[0]);
 }
Пример #5
0
 private bool isDeleted(JiraEvent jiraEvent)
 {
     return(jiraEvent.issue_event_type_name.Contains(IssueDeleted));
 }
Пример #6
0
 private bool isUpdated(JiraEvent jiraEvent)
 {
     return(jiraEvent.WebHookEvent.Contains(IssueUpdated) && !jiraEvent.issue_event_type_name.Contains("comment"));
 }
Пример #7
0
 private bool isCreated(JiraEvent jiraEvent)
 {
     return(jiraEvent.WebHookEvent.Contains(IssueCreated));
 }