public static bool Equals(object value1, string value2) { return(value1 != null && value1 switch { string actualStringValue => string.Equals(actualStringValue, value2, StringComparison.InvariantCultureIgnoreCase), DateTime actualDateValue => actualDateValue == FilterParseHelpers.ParseJiraDate(value2), int actualIntValue => actualIntValue == int.Parse(value2, CultureInfo.InvariantCulture), decimal actualDecimalValue => actualDecimalValue == decimal.Parse(value2, CultureInfo.InvariantCulture), float actualFloatValue => Math.Abs(actualFloatValue - float.Parse(value2, CultureInfo.InvariantCulture)) < 0.0001, double actualDoubleValue => Math.Abs(actualDoubleValue - double.Parse(value2, CultureInfo.InvariantCulture)) < 0.0001, long actualLongValue => actualLongValue == long.Parse(value2), JiraStatus actualStatusValue => actualStatusValue == value2, JiraIssueReference actualIssueReferenceValue => actualIssueReferenceValue == value2, JiraCustomFieldOption actualOptionValue => actualOptionValue == value2, JiraPriority actualPriorityValue => actualPriorityValue == value2, JiraProject actualProjectValue => actualProjectValue == value2, JiraUser actualUserValue => actualUserValue == value2, JiraIssueType actualIssueJiraType => actualIssueJiraType == value2, IEnumerable actualEnumerableValue => actualEnumerableValue.Cast <object>().Any(x => Equals(x, value2)), _ => false });
public Workflow(JiraIssueType issueType, JiraStatus defaultStatus, Dictionary <string, JiraTransition[]> transitions, Dictionary <string, Func <JiraIssue, bool> > conditions) { this.transitions = transitions; this.conditions = conditions; IssueType = issueType; DefaultStatus = defaultStatus; }
public void On(Event <LogEventData> @event) { var client = new RestClient(JiraApiUrl) { Authenticator = new HttpBasicAuthenticator(JiraUsername, JiraPassword), }; var response = CreateIssue(client, JiraProjectKey.Trim(), JiraIssueType.Trim(), @event); if (!response.IsSuccessful) { throw new Exception(response.ErrorMessage); } JToken issueKey; var responseContent = JsonConvert.DeserializeObject <JObject>(response.Content); if (responseContent.TryGetValue("key", out issueKey)) { AddEventAttachment(client, issueKey.ToString(), @event); } }
public async Task <IList <JiraIssueType> > GetJiraIssueTypesAsync() { var jiraItemList = new List <JiraIssueType>(); var jira = GetJiraClient(); var jiraItems = await jira.IssueTypes.GetIssueTypesForProjectAsync(_jiraOptions.Value.projectKey); foreach (var item in jiraItems.ToList()) { var jiraItem = new JiraIssueType() { Id = item.Id, Name = item.Name, Description = item.Description, IconUrl = item.IconUrl }; jiraItemList.Add(jiraItem); } return(jiraItemList); }
public static JiraIssue ToJiraIssue(this SdpApi sdpIncident, string projectKey, string sdpBaseUrl, JiraIssueType issueType) { var jiraIssue = new JiraIssue(); jiraIssue.Fields = new Fields() { Project = new Project() { Key = projectKey }, Description = sdpIncident.Response.Operation.Details.Parameters.First(p => p.Name == SdpParaNames.ShortDescription) .Value, IssueType = new IssueType() { Name = issueType.ToString() }, Summary = sdpIncident.Response.Operation.Details.Parameters.First(p => p.Name == SdpParaNames.Subject) .Value }; var incidentId = sdpIncident.Response.Operation.Details.Parameters.First(p => p.Name == SdpParaNames.WorkOrderId) .Value; jiraIssue.Fields.Description = jiraIssue.Fields.Description + Environment.NewLine + Environment.NewLine; jiraIssue.Fields.Description = jiraIssue.Fields.Description + "Click below link to view in SDP" + Environment.NewLine; jiraIssue.Fields.Description = jiraIssue.Fields.Description + string.Format(sdpBaseUrl, incidentId); return(jiraIssue); }
public async Task <bool> CreateIssue(Event <LogEventData> evt) { if (evt == null) { return(false); } if ((LogEventLevelList?.Count ?? 0) > 0 && !LogEventLevelList.Contains(evt.Data.Level)) { return(false); } var description = evt.Data.Exception ?? evt.Data.RenderedMessage; var messageId = ComputeId(description); var summary = evt.Data.RenderedMessage.CleanCRLF().TruncateWithEllipsis(255); var client = new JsonRestClient(JiraApiUrl) { Username = Username, Password = Password }; // Try to match if (SeqEventField.HasValue) { var searchUrl = GiveMeTheSearchDuplicateIssueUrl(messageId); var searchResult = await client.GetAsync <JiraIssueSearchResult>(searchUrl).ConfigureAwait(false); if ((searchResult?.total ?? 0) > 0) { return(false); } } var fields = new Dictionary <string, object> { { "project", new { key = ProjectKey.Trim() } }, { "issuetype", new { name = JiraIssueType.Trim() } }, { "summary", summary }, { "description", RenderDescription(evt) }, }; // Process components var components = ComponentsAsArray; if ((components?.Count ?? 0) > 0) { fields.Add("components", components); } // Process labels var labels = Labels.IsNullOrEmpty() ? null : Labels.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if ((labels?.Length ?? 0) > 0) { fields.Add("labels", labels.TrimAll()); } if (SeqEventField.HasValue) { fields.Add($"customfield_{SeqEventField}", messageId); } var payload = new { fields }; //var payloadJson = JsonConvert.SerializeObject(payload); // Create the issue _step = "Will create issue"; var result = await client.PostAsync <JiraCreateIssueResponse, object>("issue", payload) .ConfigureAwait(false); if ((result?.Errors?.Count ?? 0) > 0) { var e = new ApplicationException("Jira errors are " + JsonConvert.SerializeObject(result.Errors)); Log.Error(e, "Can not crate issue on Jira"); return(false); } _step = "Issue created"; // Add details as comment if (!FullDetailsInDescription) { _step = "Will add details as comment"; var commentBody = $"{{noformat}}{evt.Data.RenderedMessage}{{noformat}}"; if (commentBody.HasValue()) { await CommentAsync(result, commentBody).ConfigureAwait(false); } _step = "Added details as comment"; } // Properties as comment if (PropertiesAsComment) { _step = "Will add properties as comment"; var commentBody = RenderProperties(evt, "Structured Event Properties"); if (commentBody.HasValue()) { await CommentAsync(result, commentBody).ConfigureAwait(false); } _step = "Added properties as comment"; } return(true); }
/// <summary> /// Get all the Jira items for the specified project with the specified status /// </summary> /// <param name="project">The project to query</param> /// <param name="status">The status to search for</param> /// <param name="type">The type of the issue</param> /// <returns>SearchResult with the requested issues</returns> public SearchResult GetIssues(string project, List<JiraItemStatus> status, JiraIssueType type) { string statusMsg = "status%20in%20("; for (int i = 0; i < status.Count; i++) { if (i < (status.Count - 1)) { statusMsg += JiraJQLConverter(status[i]) + "%2C%20"; } else { statusMsg += JiraJQLConverter(status[i]) + ")"; } } string query = String.Format("search?jql={0}%20AND%20issuetype%3D{1}%20AND%20project%20%3D{2}+order+by+priority", statusMsg, (int)type, project); string response = RunQuery(query); DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(SearchResult)); MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(response)); SearchResult res = (SearchResult)jsonSerializer.ReadObject(stream); // Fill-up extra stuff foreach (Issue issue in res.Issues) { issue.URL = Config.BrowserUrl + issue.Key; issue.Field.Severity = ParseSeverityFromTheme(issue.Field.Labels); //AppendCommentsForIssue(issue); //Attachment[] a = AppendAttachmentForIssue(issue); } return res; }
public IWorkflowBuilder <TIssue> Type(JiraIssueType type) { issueType = type; return(this); }