Exemplo n.º 1
0
 /// <summary>
 ///     Search for issues, with a JQL (e.g. from a filter)
 ///     See: https://docs.atlassian.com/jira/REST/latest/#d2e2713
 /// </summary>
 /// <param name="jiraClient">IIssueDomain to bind the extension method to</param>
 /// <param name="jql">Jira Query Language, like SQL, for the search. Use Where builder</param>
 /// <param name="startAt">Start of the results to return, used for paging. Default is 0</param>
 /// <param name="maxResults">Maximum number of results returned, default is 20</param>
 /// <param name="fields">Jira fields to include, if null the defaults from the JiraConfig.SearchFields are taken</param>
 /// <param name="expand">
 ///     Additional fields to includes in the results, if null the defaults from the
 ///     JiraConfig.ExpandSearch are taken
 /// </param>
 /// <param name="cancellationToken">CancellationToken</param>
 /// <returns>SearchResults</returns>
 public static Task <SearchIssuesResult <Issue, JqlIssueSearch> > SearchAsync(this IIssueDomain jiraClient, IFinalClause jql, int maxResults = 20, int startAt = 0,
                                                                              IEnumerable <string> fields = null, IEnumerable <string> expand = null, CancellationToken cancellationToken = default)
 {
     return(jiraClient.SearchAsync(jql.ToString(), new Page {
         MaxResults = maxResults, StartAt = startAt
     }, fields, expand, cancellationToken));
 }
Exemplo n.º 2
0
        /// <summary>
        ///     Get issue information
        ///     See: https://docs.atlassian.com/jira/REST/latest/#d2e4539
        /// </summary>
        /// <param name="jiraClient">IIssueDomain to bind the extension method to</param>
        /// <param name="issueKey">the issue key</param>
        /// <param name="fields">IEnumerable of string A list of fields to return for the issue. Use it to retrieve a subset of fields.</param>
        /// <param name="expand">IEnumerable of string Use expand to include additional information about the issues in the response.</param>
        /// <param name="cancellationToken">CancellationToken</param>
        /// <returns>Issue</returns>
        public static async Task <TIssue> GetAsync <TIssue, TFields>(this IIssueDomain jiraClient, string issueKey, IEnumerable <string> fields = null,
                                                                     IEnumerable <string> expand = null, CancellationToken cancellationToken = default)
            where TIssue : IssueWithFields <TFields>
            where TFields : IssueFields
        {
            if (issueKey == null)
            {
                throw new ArgumentNullException(nameof(issueKey));
            }

            Log.Debug().WriteLine("Retrieving issue information for {0}", issueKey);
            var issueUri = jiraClient.JiraRestUri.AppendSegments("issue", issueKey);

            if (fields != null)
            {
                issueUri = issueUri.ExtendQuery("fields", string.Join(",", fields));
            }

            // Add the configurable expand values, if the value is not null or empty
            expand ??= JiraConfig.ExpandGetIssue;
            if (expand != null)
            {
                issueUri = issueUri.ExtendQuery("expand", string.Join(",", expand));
            }

            jiraClient.Behaviour.MakeCurrent();

            var response = await issueUri.GetAsAsync <HttpResponse <TIssue, Error> >(cancellationToken).ConfigureAwait(false);

            return(response.HandleErrors().WithClient(jiraClient) as TIssue);
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Add comment to the specified issue
        ///     See: https://docs.atlassian.com/jira/REST/latest/#d2e1139
        /// </summary>
        /// <param name="jiraClient">IIssueDomain to bind the extension method to</param>
        /// <param name="issueKey">key for the issue</param>
        /// <param name="body">the body of the comment</param>
        /// <param name="visibility">optional visibility role</param>
        /// <param name="cancellationToken">CancellationToken</param>
        /// <returns>Comment</returns>
        public static async Task <Comment> AddCommentAsync(this IIssueDomain jiraClient, string issueKey, string body, string visibility = null,
                                                           CancellationToken cancellationToken = default)
        {
            if (issueKey == null)
            {
                throw new ArgumentNullException(nameof(issueKey));
            }
            Log.Debug().WriteLine("Adding comment to {0}", issueKey);
            var comment = new Comment
            {
                Body       = body,
                Visibility = visibility == null
                                        ? null
                                        : new Visibility
                {
                    Type  = "role",
                    Value = visibility
                }
            };

            jiraClient.Behaviour.MakeCurrent();
            var attachUri = jiraClient.JiraRestUri.AppendSegments("issue", issueKey, "comment");
            var response  = await attachUri.PostAsync <HttpResponse <Comment, Error> >(comment, cancellationToken).ConfigureAwait(false);

            return(response.HandleErrors(HttpStatusCode.Created));
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Search for issues, with a JQL (e.g. from a filter)
        ///     See: https://docs.atlassian.com/jira/REST/latest/#d2e2713
        /// </summary>
        /// <param name="jiraClient">IIssueDomain to bind the extension method to</param>
        /// <param name="jql">Jira Query Language, like SQL, for the search</param>
        /// <param name="maxResults">Maximum number of results returned, default is 20</param>
        /// <param name="fields">Jira fields to include, if null the defaults from the JiraConfig.SearchFields are taken</param>
        /// <param name="cancellationToken">CancellationToken</param>
        /// <returns>SearchResult</returns>
        public static async Task <SearchResult <Issue> > SearchAsync(this IIssueDomain jiraClient, string jql, int maxResults = 20, IEnumerable <string> fields = null,
                                                                     CancellationToken cancellationToken = default(CancellationToken))
        {
            if (jql == null)
            {
                throw new ArgumentNullException(nameof(jql));
            }

            Log.Debug().WriteLine("Searching via JQL: {0}", jql);

            jiraClient.Behaviour.MakeCurrent();
            var search = new Search
            {
                Jql           = jql,
                ValidateQuery = true,
                MaxResults    = maxResults,
                Fields        = fields ?? new List <string>(JiraConfig.SearchFields)
            };
            var searchUri = jiraClient.JiraRestUri.AppendSegments("search");

            // Add the configurable expand values, if the value is not null or empty
            if (JiraConfig.ExpandSearch?.Length > 0)
            {
                searchUri = searchUri.ExtendQuery("expand", string.Join(",", JiraConfig.ExpandSearch));
            }

            var response = await searchUri.PostAsync <HttpResponse <SearchResult <Issue>, Error> >(search, cancellationToken).ConfigureAwait(false);

            return(response.HandleErrors());
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Update an issue
        /// </summary>
        /// <typeparam name="TFields">The type of the issue</typeparam>
        /// <param name="jiraClient">IIssueDomain to bind the extension method to</param>
        /// <param name="issue">the issue to update</param>
        /// <param name="notifyUsers">
        ///     send the email with notification that the issue was updated to users that watch it. Admin or
        ///     project admin permissions are required to disable the notification. default = true
        /// </param>
        /// <param name="overrideScreenSecurity">
        ///     allows to update fields that are not on the screen. Only connect add-on users with
        ///     admin scope permission are allowed to use this flag. default = false
        /// </param>
        /// <param name="overrideEditableFlag">
        ///     Updates the issue even if the issue is not editable due to being in a status with
        ///     jira.issue.editable set to false or missing. Only connect add-on users with admin scope permission are allowed to
        ///     use this flag. default = false
        /// </param>
        /// <param name="cancellationToken">CancellationToken</param>
        /// <returns>TIssue</returns>
        public static async Task UpdateAsync <TFields>(this IIssueDomain jiraClient, IssueWithFields <TFields> issue, bool notifyUsers = true, bool overrideScreenSecurity = false, bool overrideEditableFlag = false, CancellationToken cancellationToken = default)
            where TFields : IssueFields
        {
            if (issue == null)
            {
                throw new ArgumentNullException(nameof(issue));
            }
            Log.Debug().WriteLine("Updating issue {0}", issue.Key);
            jiraClient.Behaviour.MakeCurrent();
            var issueToUpdate = new IssueWithFields <TFields>
            {
                Fields = issue.Fields,
                Update = issue.Update
            };
            var issueUri = jiraClient.JiraRestUri.AppendSegments("issue", issue.Key).ExtendQuery(new Dictionary <string, bool>
            {
                { "notifyUsers", notifyUsers },
                { "overrideScreenSecurity", overrideScreenSecurity },
                { "overrideEditableFlag", overrideEditableFlag }
            });
            var response = await issueUri.PutAsync <HttpResponseWithError <Error> >(issueToUpdate, cancellationToken).ConfigureAwait(false);

            // Expect HttpStatusCode.NoContent throw error if not
            response.HandleStatusCode(HttpStatusCode.NoContent);
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Performs an issue transition and, if the transition has a screen, updates the fields from the transition screen.
        ///     See: https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-rest-api-3-issue-issueIdOrKey-transitions-post
        /// </summary>
        /// <param name="jiraClient">IIssueDomain to bind the extension method to</param>
        /// <param name="issueKey">key for the issue</param>
        /// <param name="to"></param>
        /// <param name="assignee"></param>
        /// <param name="cancellationToken">CancellationToken</param>
        /// <returns>no-content</returns>
        public static async Task <object> TransitionAsync(this IIssueDomain jiraClient, string issueKey, Status to, User assignee,
                                                          CancellationToken cancellationToken = default)
        {
            if (issueKey == null)
            {
                throw new ArgumentNullException(nameof(issueKey));
            }
            Log.Debug().WriteLine("Performs an issue transition for {0}", issueKey);
            var request = new
            {
                transition = new
                {
                    id = to.Id
                },
                fields = new
                {
                    assignee = new
                    {
                        name = assignee.Name
                    }
                }
            };

            jiraClient.Behaviour.MakeCurrent();
            var attachUri = jiraClient.JiraRestUri.AppendSegments("issue", issueKey, "transitions");

            attachUri.ExtendQuery("expand", "transitions.fields");

            var response = await attachUri.PostAsync <HttpResponse <object, Error> >(request, cancellationToken).ConfigureAwait(false);

            return(response.HandleErrors(HttpStatusCode.NoContent));
        }
Exemplo n.º 7
0
        /// <summary>
        ///     Delete an issue link
        /// </summary>
        /// <param name="jiraClient">IIssueDomain to bind the extension method to</param>
        /// <param name="issueLinkId">string with the ID of the issue link</param>
        /// <param name="cancellationToken">CancellationToken</param>
        public static async Task DeleteIssueLinkAsync(this IIssueDomain jiraClient, string issueLinkId, CancellationToken cancellationToken = new CancellationToken())
        {
            var issueLinkUri = jiraClient.JiraRestUri.AppendSegments("issueLink", issueLinkId);

            jiraClient.Behaviour.MakeCurrent();
            var response = await issueLinkUri.DeleteAsync <HttpResponse>(cancellationToken).ConfigureAwait(false);

            response.HandleStatusCode(HttpStatusCode.NoContent);
        }
Exemplo n.º 8
0
        /// <summary>
        ///     Create an issue link
        /// </summary>
        /// <param name="jiraClient">IIssueDomain to bind the extension method to</param>
        /// <param name="issueLink">IssueLink</param>
        /// <param name="cancellationToken">CancellationToken</param>
        public static async Task CreateIssueLinkAsync(this IIssueDomain jiraClient, IssueLink issueLink, CancellationToken cancellationToken = new CancellationToken())
        {
            var issueLinkUri = jiraClient.JiraRestUri.AppendSegments("issueLink");

            jiraClient.Behaviour.MakeCurrent();
            var response = await issueLinkUri.PostAsync <HttpResponse>(issueLink, cancellationToken).ConfigureAwait(false);

            response.HandleStatusCode(HttpStatusCode.Created);
        }
Exemplo n.º 9
0
        /// <summary>
        ///     Change the state of the issue (make a transition)
        /// </summary>
        /// <param name="jiraClient">IIssueDomain to bind the extension method to</param>
        /// <param name="issueKey">string with the key for the issue to update</param>
        /// <param name="transition">Transition</param>
        /// <param name="cancellationToken">CancellationToken</param>
        public static Task TransitionAsync(this IIssueDomain jiraClient, string issueKey, Transition transition, CancellationToken cancellationToken = default)
        {
            var issueEdit = new IssueEdit
            {
                Transition = transition
            };

            return(TransitionAsync(jiraClient, issueKey, issueEdit, cancellationToken));
        }
Exemplo n.º 10
0
    /// <summary>
    ///     Get an issue link
    /// </summary>
    /// <param name="jiraClient">IIssueDomain to bind the extension method to</param>
    /// <param name="linkId">string</param>
    /// <param name="cancellationToken">CancellationToken</param>
    /// <returns>Issue </returns>
    public static async Task <IssueLink> GetIssueLinkAsync(this IIssueDomain jiraClient, string linkId, CancellationToken cancellationToken = default)
    {
        var issueLinkUri = jiraClient.JiraRestUri.AppendSegments("issueLink", linkId);

        jiraClient.Behaviour.MakeCurrent();
        var response = await issueLinkUri.GetAsAsync <HttpResponse <IssueLink, Error> >(cancellationToken).ConfigureAwait(false);

        return(response.HandleErrors());
    }
Exemplo n.º 11
0
        /// <summary>
        ///     Get a list of all possible issue types
        /// </summary>
        /// <param name="jiraClient">IIssueDomain to bind the extension method to</param>
        /// <param name="cancellationToken">CancellationToken</param>
        /// <returns>List with IssueType elements</returns>
        public static async Task <IList <IssueType> > GetIssueTypesAsync(this IIssueDomain jiraClient, CancellationToken cancellationToken = new CancellationToken())
        {
            var issueTypesUri = jiraClient.JiraRestUri.AppendSegments("issuetype");

            jiraClient.Behaviour.MakeCurrent();
            var response = await issueTypesUri.GetAsAsync <HttpResponse <IList <IssueType>, Error> >(cancellationToken).ConfigureAwait(false);

            return(response.HandleErrors());
        }
Exemplo n.º 12
0
        /// <summary>
        ///     Assign an issue to a user
        /// </summary>
        /// <param name="jiraClient">IIssueDomain to bind the extension method to</param>
        /// <param name="issueKey">Key for the issue to assign</param>
        /// <param name="user">User to assign to, use User.Nobody to remove the assignee or User.Default to automaticly assign</param>
        /// <param name="cancellationToken">CancellationToken</param>
        public static async Task AssignAsync(this IIssueDomain jiraClient, string issueKey, User user, CancellationToken cancellationToken = default)
        {
            if (user == null)
            {
                user = User.Nobody;
            }

            jiraClient.Behaviour.MakeCurrent();
            var issueUri = jiraClient.JiraRestUri.AppendSegments("issue", issueKey, "assignee");
            var response = await issueUri.PutAsync <HttpResponse>(user, cancellationToken).ConfigureAwait(false);

            response.HandleStatusCode(HttpStatusCode.NoContent, HttpStatusCode.OK);
        }
Exemplo n.º 13
0
        /// <summary>
        ///     Create an issue
        /// </summary>
        /// <typeparam name="TFields">The type of the issue fields</typeparam>
        /// <param name="jiraClient">IIssueDomain to bind the extension method to</param>
        /// <param name="issue">the issue to create</param>
        /// <param name="cancellationToken">CancellationToken</param>
        /// <returns>Issue</returns>
        public static async Task <IssueWithFields <TFields> > CreateAsync <TFields>(this IIssueDomain jiraClient, IssueWithFields <TFields> issue, CancellationToken cancellationToken = default)
            where TFields : IssueFields
        {
            if (issue == null)
            {
                throw new ArgumentNullException(nameof(issue));
            }
            Log.Debug().WriteLine("Creating issue {0}", issue);
            jiraClient.Behaviour.MakeCurrent();
            var issueUri = jiraClient.JiraRestUri.AppendSegments("issue");
            var response = await issueUri.PostAsync <HttpResponse <IssueWithFields <TFields>, Error> >(issue, cancellationToken).ConfigureAwait(false);

            return(response.HandleErrors(HttpStatusCode.Created));
        }
Exemplo n.º 14
0
        /// <summary>
        ///     Search for issues, with a JQL (e.g. from a filter)
        ///     See: https://docs.atlassian.com/jira/REST/latest/#d2e2713
        /// </summary>
        /// <param name="jiraClient">IIssueDomain to bind the extension method to</param>
        /// <param name="search">Search information, with Jira Query Language, like SQL, for the search</param>
        /// <param name="page">Page with paging information, overwriting the page info in the search.</param>
        /// <param name="fields">Jira fields to include, if null the defaults from the JiraConfig.SearchFields are taken</param>
        /// <param name="cancellationToken">CancellationToken</param>
        /// <returns>SearchIssuesResult</returns>
        public static Task <SearchIssuesResult <Issue, JqlIssueSearch> > SearchAsync(this IIssueDomain jiraClient, JqlIssueSearch search, Page page = null, IEnumerable <string> fields = null,
                                                                                     CancellationToken cancellationToken = default)
        {
            if (search == null)
            {
                throw new ArgumentNullException(nameof(search));
            }

            if (page != null)
            {
                search.MaxResults = page.MaxResults ?? 20;
                search.StartAt    = page.StartAt ?? 0;
            }
            return(jiraClient.SearchAsync(search, cancellationToken));
        }
Exemplo n.º 15
0
        /// <summary>
        ///     Change the state of the issue (make a transition)
        /// </summary>
        /// <param name="jiraClient">IIssueDomain to bind the extension method to</param>
        /// <param name="issueKey">string with the key for the issue to update</param>
        /// <param name="issueEdit">IssueEdit which describes what to edit</param>
        /// <param name="cancellationToken">CancellationToken</param>
        public static async Task TransitionAsync(this IIssueDomain jiraClient, string issueKey, IssueEdit issueEdit, CancellationToken cancellationToken = default)
        {
            if (issueEdit?.Transition == null)
            {
                throw new ArgumentNullException(nameof(issueEdit));
            }

            Log.Debug().WriteLine("Transitioning issue {0} to {1}", issueKey, issueEdit.Transition.Name);
            jiraClient.Behaviour.MakeCurrent();
            var issueUri = jiraClient.JiraRestUri.AppendSegments("issue", issueKey, "transitions");
            var response = await issueUri.PostAsync <HttpResponseWithError <Error> >(issueEdit, cancellationToken).ConfigureAwait(false);

            // Expect HttpStatusCode.NoContent throw error if not
            response.HandleStatusCode(HttpStatusCode.NoContent);
        }
Exemplo n.º 16
0
        /// <summary>
        ///     Update comment
        ///     See: https://docs.atlassian.com/jira/REST/latest/#d2e1139
        /// </summary>
        /// <param name="jiraClient">IIssueDomain to bind the extension method to</param>
        /// <param name="issueKey">jira key to which the comment belongs</param>
        /// <param name="comment">Comment to update</param>
        /// <param name="cancellationToken">CancellationToken</param>
        /// <returns>Comment</returns>
        public static async Task <Comment> UpdateCommentAsync(this IIssueDomain jiraClient, string issueKey, Comment comment, CancellationToken cancellationToken = default)
        {
            if (issueKey == null)
            {
                throw new ArgumentNullException(nameof(issueKey));
            }

            Log.Debug().WriteLine("Updating comment {0} for issue {1}", comment.Id, issueKey);

            jiraClient.Behaviour.MakeCurrent();

            var attachUri = jiraClient.JiraRestUri.AppendSegments("issue", issueKey, "comment", comment.Id);
            var response  = await attachUri.PutAsync <HttpResponse <Comment, Error> >(comment, cancellationToken).ConfigureAwait(false);

            return(response.HandleErrors());
        }
Exemplo n.º 17
0
        /// <summary>
        ///     Delete an issue
        /// </summary>
        /// <param name="jiraClient">IIssueDomain to bind the extension method to</param>
        /// <param name="issueKey">the key of the issue to delete</param>
        /// <param name="deleteSubtasks">
        ///     true or false (default) indicating that any subtasks should also be deleted.
        ///     If the issue has no subtasks this parameter is ignored. If the issue has subtasks and this parameter is missing or
        ///     false, then the issue will not be deleted and an error will be returned
        /// </param>
        /// <param name="cancellationToken">CancellationToken</param>
        public static async Task DeleteAsync(this IIssueDomain jiraClient, string issueKey, bool deleteSubtasks = false,
                                             CancellationToken cancellationToken = default)
        {
            if (issueKey == null)
            {
                throw new ArgumentNullException(nameof(issueKey));
            }
            jiraClient.Behaviour.MakeCurrent();
            var issueUri = jiraClient.JiraRestUri.AppendSegments("issue", issueKey);

            if (deleteSubtasks)
            {
                issueUri = issueUri.ExtendQuery("deleteSubtasks", true);
            }
            var response = await issueUri.DeleteAsync <HttpResponse>(cancellationToken).ConfigureAwait(false);

            response.HandleStatusCode(HttpStatusCode.NoContent);
        }
Exemplo n.º 18
0
        /// <summary>
        ///     Get possible transitions for the specified issue
        ///     See: https://docs.atlassian.com/jira/REST/latest/#d2e1289
        /// </summary>
        /// <param name="jiraClient">IIssueDomain to bind the extension method to</param>
        /// <param name="issueKey">the issue key</param>
        /// <param name="cancellationToken">CancellationToken</param>
        /// <returns>List of Transition</returns>
        public static async Task <IList <Transition> > GetPossibleTransitionsAsync(this IIssueDomain jiraClient, string issueKey, CancellationToken cancellationToken = default)
        {
            if (issueKey == null)
            {
                throw new ArgumentNullException(nameof(issueKey));
            }
            Log.Debug().WriteLine("Retrieving transition information for {0}", issueKey);
            var transitionsUri = jiraClient.JiraRestUri.AppendSegments("issue", issueKey, "transitions");

            if (JiraConfig.ExpandGetTransitions?.Length > 0)
            {
                transitionsUri = transitionsUri.ExtendQuery("expand", string.Join(",", JiraConfig.ExpandGetTransitions));
            }
            jiraClient.Behaviour.MakeCurrent();
            var response = await transitionsUri.GetAsAsync <HttpResponse <Transitions, Error> >(cancellationToken).ConfigureAwait(false);

            return(response.HandleErrors().Items);
        }
Exemplo n.º 19
0
        /// <summary>
        ///     Search for issues, with a JQL (e.g. from a filter)
        ///     See: https://docs.atlassian.com/jira/REST/latest/#d2e2713
        /// </summary>
        /// <param name="jiraClient">IIssueDomain to bind the extension method to</param>
        /// <param name="jql">Jira Query Language, like SQL, for the search</param>
        /// <param name="page">Page with paging information, default this starts at the beginning with a maxResults of 20</param>
        /// <param name="fields">Jira fields to include, if null the defaults from the JiraConfig.SearchFields are taken</param>
        /// <param name="cancellationToken">CancellationToken</param>
        /// <returns>SearchIssuesResult</returns>
        public static Task <SearchIssuesResult <Issue, JqlIssueSearch> > SearchAsync(this IIssueDomain jiraClient, string jql, Page page = null, IEnumerable <string> fields = null,
                                                                                     CancellationToken cancellationToken = default(CancellationToken))
        {
            if (jql == null)
            {
                throw new ArgumentNullException(nameof(jql));
            }

            var search = new JqlIssueSearch
            {
                Jql           = jql,
                ValidateQuery = true,
                MaxResults    = page?.MaxResults ?? 20,
                StartAt       = page?.StartAt ?? 0,
                Fields        = fields ?? new List <string>(JiraConfig.SearchFields)
            };

            return(jiraClient.SearchAsync(search, cancellationToken));
        }
Exemplo n.º 20
0
 /// <summary>
 ///     Get issue information
 ///     See: https://docs.atlassian.com/jira/REST/latest/#d2e4539
 /// </summary>
 /// <param name="jiraClient">IIssueDomain to bind the extension method to</param>
 /// <param name="issueKey">the issue key</param>
 /// <param name="cancellationToken">CancellationToken</param>
 /// <returns>Issue</returns>
 public static Task <Issue> GetAsync(this IIssueDomain jiraClient, string issueKey, CancellationToken cancellationToken = default)
 {
     return(jiraClient.GetAsync <Issue, IssueFields>(issueKey, cancellationToken));
 }
Exemplo n.º 21
0
 /// <summary>
 ///     Get issue information
 ///     See: https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-issueidorkey-get
 /// </summary>
 /// <param name="jiraClient">IIssueDomain to bind the extension method to</param>
 /// <param name="issueKey">the issue key</param>
 /// <param name="fields">IEnumerable of string A list of fields to return for the issue. Use it to retrieve a subset of fields.</param>
 /// <param name="expand">IEnumerable of string to specified which fields to expand</param>
 /// <param name="cancellationToken">CancellationToken</param>
 /// <returns>Issue</returns>
 public static Task <Issue> GetAsync(this IIssueDomain jiraClient, string issueKey, IEnumerable <string> fields = null, IEnumerable <string> expand = null,
                                     CancellationToken cancellationToken = default)
 {
     return(jiraClient.GetAsync <Issue, IssueFields>(issueKey, fields, expand, cancellationToken));
 }
Exemplo n.º 22
0
 /// <summary>
 ///     Retrieve the users who this issue can be assigned to
 /// </summary>
 /// <param name="jiraClient">IProjectDomain</param>
 /// <param name="issueKey">string with the key of the issue</param>
 /// <param name="userpattern">optional string with a pattern to match the user to</param>
 /// <param name="startAt">optional int with the start, used for paging</param>
 /// <param name="maxResults">optional int with the maximum number of results, default is 50</param>
 /// <param name="cancellationToken">CancellationToken</param>
 /// <returns>IEnumerable with User</returns>
 public static Task <IEnumerable <User> > GetAssignableUsersAsync(this IIssueDomain jiraClient, string issueKey, string userpattern = null, int?startAt = null, int?maxResults = null, CancellationToken cancellationToken = default)
 {
     return(jiraClient.User.GetAssignableUsersAsync(issueKey: issueKey, username: userpattern, startAt: startAt, maxResults: maxResults, cancellationToken: cancellationToken));
 }
Exemplo n.º 23
0
        /// <summary>
        ///     Search for issues, with a JQL (e.g. from a filter)
        ///     See: https://docs.atlassian.com/jira/REST/latest/#d2e2713
        /// </summary>
        /// <param name="jiraClient">IIssueDomain to bind the extension method to</param>
        /// <param name="search">The search arguments</param>
        /// <param name="cancellationToken">CancellationToken</param>
        /// <returns>SearchIssuesResult</returns>
        public static async Task <SearchIssuesResult <Issue, JqlIssueSearch> > SearchAsync(this IIssueDomain jiraClient, JqlIssueSearch search, CancellationToken cancellationToken = default)
        {
            if (search == null)
            {
                throw new ArgumentNullException(nameof(search));
            }

            Log.Debug().WriteLine("Searching via JQL: {0}", search.Jql);

            jiraClient.Behaviour.MakeCurrent();
            var searchUri = jiraClient.JiraRestUri.AppendSegments("search");

            var response = await searchUri
                           .PostAsync <HttpResponse <SearchIssuesResult <Issue, JqlIssueSearch>, Error> >(search, cancellationToken)
                           .ConfigureAwait(false);

            var result = response.HandleErrors();

            // Store the original search parameter
            result.SearchParameter = search;
            return(result);
        }
Exemplo n.º 24
0
 /// <summary>
 ///     Search for issues, with a JQL (e.g. from a filter)
 ///     See: https://docs.atlassian.com/jira/REST/latest/#d2e2713
 /// </summary>
 /// <param name="jiraClient">IIssueDomain to bind the extension method to</param>
 /// <param name="jql">Jira Query Language, like SQL, for the search. Use Where builder</param>
 /// <param name="maxResults">Maximum number of results returned, default is 20</param>
 /// <param name="fields">Jira fields to include, if null the defaults from the JiraConfig.SearchFields are taken</param>
 /// <param name="cancellationToken">CancellationToken</param>
 /// <returns>SearchResult</returns>
 public static async Task <SearchResult <Issue> > SearchAsync(this IIssueDomain jiraClient, IFinalClause jql, int maxResults = 20, IEnumerable <string> fields = null,
                                                              CancellationToken cancellationToken = default(CancellationToken))
 {
     return(await jiraClient.SearchAsync(jql.ToString(), maxResults, fields, cancellationToken).ConfigureAwait(false));
 }
Exemplo n.º 25
0
        /// <summary>
        ///     Search for issues, with a JQL (e.g. from a filter)
        ///     See: https://docs.atlassian.com/jira/REST/latest/#d2e2713
        /// </summary>
        /// <param name="jiraClient">IIssueDomain to bind the extension method to</param>
        /// <param name="search">The search arguments</param>
        /// <param name="cancellationToken">CancellationToken</param>
        /// <returns>SearchIssuesResult</returns>
        public static async Task <SearchIssuesResult <Issue, JqlIssueSearch> > SearchAsync(this IIssueDomain jiraClient, JqlIssueSearch search, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (search == null)
            {
                throw new ArgumentNullException(nameof(search));
            }

            Log.Debug().WriteLine("Searching via JQL: {0}", search.Jql);

            jiraClient.Behaviour.MakeCurrent();
            var searchUri = jiraClient.JiraRestUri.AppendSegments("search");

            // Add the configurable expand values, if the value is not null or empty
            if (JiraConfig.ExpandSearch?.Length > 0)
            {
                searchUri = searchUri.ExtendQuery("expand", string.Join(",", JiraConfig.ExpandSearch));
            }

            var response = await searchUri.PostAsync <HttpResponse <SearchIssuesResult <Issue, JqlIssueSearch>, Error> >(search, cancellationToken).ConfigureAwait(false);

            var result = response.HandleErrors();

            // Store the original search parameter
            result.SearchParameter = search;
            return(result);
        }