A utility class for communicating with a JIRA server using the REST API. See https://docs.atlassian.com/jira/REST/latest/ for the full JIRA REST API.
예제 #1
0
        /// <summary>
        /// Creates a new JIRA issue (a bug).
        /// </summary>
        /// <param name="projectKey">The projects key e.g. TSCB.</param>
        /// <param name="bugTitle">The title of the bug.</param>
        /// <param name="bugDescription">The detailed description of the bug.</param>
        /// <param name="bugPriority">The priority of the bug.</param>
        /// <param name="bugCreatedDate">The date the bug was created.</param>
        /// <param name="bugAuthor">The author of the bug.</param>
        /// <param name="bugAssignedTo">The person/group the bug is assigned to.</param>
        /// <param name="bugAttachments">List of files to attach to the bug.</param>
        /// <param name="error">Any errors during bug creation are written here.</param>
        /// <returns>The key of the bug e.g. TSCB-14</returns>
        public string SubmitBug(string projectKey, string bugTitle, string bugDescription, int bugPriority, DateTime bugCreatedDate,
                                string bugAuthor, string bugAssignedTo, List <IBugAttachment> bugAttachments, out string error)
        {
            JiraIssue jiraIssue = new JiraIssue();

            jiraIssue.fields.issuetype.name = "Bug";
            jiraIssue.fields.project.key    = projectKey;
            jiraIssue.fields.summary        = bugTitle;
            jiraIssue.fields.description    = bugDescription;
            //jiraIssue.Fields.Priority.Id = 1;

            JToken result = JiraComm.PostJson(this.Server, "/rest/api/2/issue/", this.User, this.Password, JsonConvert.SerializeObject(jiraIssue), out error);

            // Make sure the issue was successfully created before attaching files
            if (null != result)
            {
                JiraIssueCreated createdIssue = new JiraIssueCreated();
                JsonConvert.PopulateObject(result.ToString(), createdIssue);

                foreach (IBugAttachment attachment in bugAttachments)
                {
                    AttachFile(this.Server, this.User, this.Password, createdIssue.key, attachment, out error);
                    // Break if there was an error attaching this file
                    if (null != error)
                    {
                        break;
                    }
                }

                return(createdIssue.key);
            }
            return(null);
        }
예제 #2
0
        /// <summary>
        /// Worker thread that fetches the list projects from JIRA.
        /// </summary>
        private void WorkerMethod()
        {
            string   error;
            JiraComm jiraComm = new JiraComm(this.JiraSettings.ServerName, this.JiraSettings.User, this.JiraSettings.Password);

            this.JiraSettings.ErrorMessage = string.Empty;
            List <JiraProject> jiraProjects = jiraComm.GetProjects(out error);

            this.JiraSettings.ErrorMessage = error;
            this.JiraSettings.ProjectsList = jiraProjects;
            if (null == error)
            {
                this.JiraSettings.AddServer(this.JiraSettings.ServerName);
            }
        }
예제 #3
0
        public string SubmitBug(IBug bug)
#endif
        {
            string error;

            JiraComm jiraComm = new JiraComm(activeJiraConnection.ServerName, activeJiraConnection.User, activeJiraConnection.Password);
            string   bugID    = jiraComm.SubmitBug(activeJiraConnection.SelectedProject.key, bug.Title, bug.Description, bug.Priority,
                                                   bug.CreatedDate, bug.Author, bug.AssignedTo, bug.Attachments, out error);

            this.ErrorMessage = error;
#if Use2014_1_421
            // JIRA returns something like TSCB-14.
            // Return only the integer portion (until Test Studio is changed to take a string).
            return(int.Parse(bugID.Substring(bugID.IndexOf('-'))));
#else
            return(bugID);
#endif
        }
예제 #4
0
        /// <summary>
        /// Get a list of all projects the current user has visibility of.
        /// </summary>
        /// <returns>A JArray of the projects.</returns>
        /// <see cref="https://docs.atlassian.com/jira/REST/latest/#idp2300240"/>
        public List <JiraProject> GetProjects(out string error)
        {
            JToken result = JiraComm.GetJson(this.Server, "/rest/api/2/project", this.User, this.Password, out error);

            if (null != result)
            {
                if (result.GetType() == typeof(JArray))
                {
                    JArray             jsonProjects = result as JArray;
                    List <JiraProject> projects     = new List <JiraProject>(jsonProjects.Count);
                    foreach (JToken jsonProject in jsonProjects)
                    {
                        JiraProject project = new JiraProject();
                        JsonConvert.PopulateObject(jsonProject.ToString(), project);
                        projects.Add(project);
                    }
                    return(projects);
                }
            }
            return(null);
        }
        /// <summary>
        /// Worker thread that fetches the list projects from JIRA.
        /// </summary>
        private void WorkerMethod()
        {
            string error;
            JiraComm jiraComm = new JiraComm(this.JiraSettings.ServerName, this.JiraSettings.User, this.JiraSettings.Password);

            this.JiraSettings.ErrorMessage = string.Empty;
            List<JiraProject> jiraProjects = jiraComm.GetProjects(out error);
            this.JiraSettings.ErrorMessage = error;
            this.JiraSettings.ProjectsList = jiraProjects;
            if (null == error)
            {
                this.JiraSettings.AddServer(this.JiraSettings.ServerName);
            }
        }
        public string SubmitBug(IBug bug)
#endif
        {
            string error;

            JiraComm jiraComm = new JiraComm(activeJiraConnection.ServerName, activeJiraConnection.User, activeJiraConnection.Password);
            string bugID = jiraComm.SubmitBug(activeJiraConnection.SelectedProject.key, bug.Title, bug.Description, bug.Priority,
                bug.CreatedDate, bug.Author, bug.AssignedTo, bug.Attachments, out error);
            this.ErrorMessage = error;
#if Use2014_1_421
            // JIRA returns something like TSCB-14.
            // Return only the integer portion (until Test Studio is changed to take a string).
            return int.Parse(bugID.Substring(bugID.IndexOf('-')));
#else
            return bugID;
#endif
        }