Beispiel #1
0
        /// <summary>
        /// Creates a new instance of the GitLab API v4 client pointing to the specified hostUrl.
        /// </summary>
        /// <param name="hostUrl">Host address of GitLab instance. For example https://gitlab.example.com or https://gitlab.example.com/api/v4/ </param>
        /// <param name="authenticationToken">Personal access token. Obtained from GitLab profile settings.</param>
        public GitLabClient(string hostUrl, string authenticationToken = "")
        {
            Guard.NotEmpty(hostUrl, nameof(hostUrl));
            Guard.NotNull(authenticationToken, nameof(authenticationToken));
            HostUrl = hostUrl;

            var jsonSerializer = new RequestsJsonSerializer();

            _httpFacade = new GitLabHttpFacade(
                FixBaseUrl(hostUrl),
                jsonSerializer,
                authenticationToken);

            var projectQueryBuilder              = new ProjectsQueryBuilder();
            var projectIssuesQueryBuilder        = new ProjectIssuesQueryBuilder();
            var projectIssueNotesQueryBuilder    = new ProjectIssueNotesQueryBuilder();
            var issuesQueryBuilder               = new IssuesQueryBuilder();
            var mergeRequestsQueryBuilder        = new MergeRequestsQueryBuilder();
            var projectMilestonesQueryBuilder    = new MilestonesQueryBuilder();
            var projectMergeRequestsQueryBuilder = new ProjectMergeRequestsQueryBuilder();
            var groupsQueryBuilder               = new GroupsQueryBuilder();
            var projectsGroupsQueryBuilder       = new ProjectsGroupQueryBuilder();

            Issues        = new IssuesClient(_httpFacade, issuesQueryBuilder, projectIssuesQueryBuilder, projectIssueNotesQueryBuilder);
            MergeRequests = new MergeRequestsClient(_httpFacade, mergeRequestsQueryBuilder, projectMergeRequestsQueryBuilder);
            Projects      = new ProjectsClient(_httpFacade, projectQueryBuilder, projectMilestonesQueryBuilder);
            Users         = new UsersClient(_httpFacade);
            Groups        = new GroupsClient(_httpFacade, groupsQueryBuilder, projectsGroupsQueryBuilder, projectMilestonesQueryBuilder);
        }
        public void NonDefaultQueryBuilt()
        {
            var sut = new IssuesQueryBuilder();

            string query = sut.Build(
                "https://gitlab.com/api/v4/issues",
                new IssuesQueryOptions
            {
                State          = IssueState.Opened,
                Labels         = { "label1", "label2" },
                MilestoneTitle = "milestone1",
                Scope          = Scope.All,
                AuthorId       = 1,
                AssigneeId     = 2,
                IssueIds       = { 3, 4 },
                Order          = IssuesOrder.UpdatedAt,
                SortOrder      = SortOrder.Ascending,
                Filter         = "filter"
            });

            query.Should().Be("https://gitlab.com/api/v4/issues?" +
                              "state=opened&" +
                              "labels=label1%2clabel2&" +
                              "milestone=milestone1&" +
                              "scope=all&" +
                              "author_id=1&" +
                              "assignee_id=2&" +
                              "iids%5b%5d=3&iids%5b%5d=4&" +
                              "order_by=updated_at&" +
                              "sort=asc&" +
                              "search=filter");
        }
Beispiel #3
0
 internal EpicsClient(GitLabHttpFacade httpFacade, EpicsGroupQueryBuilder queryBuilder, NotesQueryBuilder notesQueryBuilder, IssuesQueryBuilder issuesQueryBuilder)
 {
     _httpFacade         = httpFacade;
     _queryBuilder       = queryBuilder;
     _notesQueryBuilder  = notesQueryBuilder;
     _issuesQueryBuilder = issuesQueryBuilder;
 }
 internal IssuesClient(
     GitLabHttpFacade httpFacade,
     IssuesQueryBuilder queryBuilder,
     ProjectIssueNotesQueryBuilder projectIssueNotesQueryBuilder)
 {
     _httpFacade   = httpFacade;
     _queryBuilder = queryBuilder;
     _projectIssueNotesQueryBuilder = projectIssueNotesQueryBuilder;
 }
Beispiel #5
0
        /// <summary>
        /// Creates a new instance of the GitLab API v4 client pointing to the specified hostUrl.
        /// </summary>
        /// <param name="hostUrl">Host address of GitLab instance. For example https://gitlab.example.com or https://gitlab.example.com/api/v4/ </param>
        /// <param name="authenticationToken">Personal access token. Obtained from GitLab profile settings.</param>
        /// <param name="httpMessageHandler">Optional handler for HTTP messages. Used for SSL pinning or canceling validation for example.</param>
        /// <param name="clientTimeout">Timespan with the HTTP client timeout if null default timeout is used. Sometimes required to upload files to a gitlab instance depending on filesize and networkspeed.</param>
        public GitLabClient(string hostUrl, string authenticationToken = "", HttpMessageHandler httpMessageHandler = null, TimeSpan?clientTimeout = null)
        {
            Guard.NotEmpty(hostUrl, nameof(hostUrl));
            Guard.NotNull(authenticationToken, nameof(authenticationToken));
            HostUrl = FixBaseUrl(hostUrl);

            var jsonSerializer = new RequestsJsonSerializer();

            _httpFacade = new GitLabHttpFacade(
                HostUrl,
                jsonSerializer,
                authenticationToken,
                httpMessageHandler,
                clientTimeout);

            var projectQueryBuilder              = new ProjectsQueryBuilder();
            var notesQueryBuilder                = new NotesQueryBuilder();
            var issuesQueryBuilder               = new IssuesQueryBuilder();
            var mergeRequestsQueryBuilder        = new MergeRequestsQueryBuilder();
            var projectMilestonesQueryBuilder    = new MilestonesQueryBuilder();
            var projectMergeRequestsQueryBuilder = new ProjectMergeRequestsQueryBuilder();
            var groupsQueryBuilder               = new GroupsQueryBuilder();
            var groupLabelsQueryBuilder          = new GroupLabelsQueryBuilder();
            var projectsGroupsQueryBuilder       = new ProjectsGroupQueryBuilder();
            var epicsGroupQueryBuilder           = new EpicsGroupQueryBuilder();
            var branchQueryBuilder               = new BranchQueryBuilder();
            var releaseQueryBuilder              = new ReleaseQueryBuilder();
            var tagQueryBuilder             = new TagQueryBuilder();
            var commitQueryBuilder          = new CommitQueryBuilder();
            var commitRefsQueryBuilder      = new CommitRefsQueryBuilder();
            var commitStatusesQueryBuilder  = new CommitStatusesQueryBuilder();
            var pipelineQueryBuilder        = new PipelineQueryBuilder();
            var treeQueryBuilder            = new TreeQueryBuilder();
            var jobQueryBuilder             = new JobQueryBuilder();
            var toDoListBuilder             = new ToDoListQueryBuilder();
            var groupIterationsQueryBuilder = new IterationsQueryBuilder();

            Issues        = new IssuesClient(_httpFacade, issuesQueryBuilder, notesQueryBuilder);
            Uploads       = new UploadsClient(_httpFacade);
            MergeRequests = new MergeRequestsClient(_httpFacade, mergeRequestsQueryBuilder, projectMergeRequestsQueryBuilder, notesQueryBuilder);
            Projects      = new ProjectsClient(_httpFacade, projectQueryBuilder, projectMilestonesQueryBuilder, jobQueryBuilder);
            Users         = new UsersClient(_httpFacade);
            Groups        = new GroupsClient(_httpFacade, groupsQueryBuilder, projectsGroupsQueryBuilder, projectMilestonesQueryBuilder, groupLabelsQueryBuilder, epicsGroupQueryBuilder, groupIterationsQueryBuilder);
            Epics         = new EpicsClient(_httpFacade, epicsGroupQueryBuilder, notesQueryBuilder, issuesQueryBuilder);
            Branches      = new BranchClient(_httpFacade, branchQueryBuilder);
            Releases      = new ReleaseClient(_httpFacade, releaseQueryBuilder);
            Tags          = new TagClient(_httpFacade, tagQueryBuilder);
            Webhooks      = new WebhookClient(_httpFacade);
            Commits       = new CommitsClient(_httpFacade, commitQueryBuilder, commitRefsQueryBuilder, commitStatusesQueryBuilder);
            Markdown      = new MarkdownClient(_httpFacade);
            Pipelines     = new PipelineClient(_httpFacade, pipelineQueryBuilder, jobQueryBuilder);
            Trees         = new TreesClient(_httpFacade, treeQueryBuilder);
            Files         = new FilesClient(_httpFacade);
            Runners       = new RunnersClient(_httpFacade);
            ToDoList      = new ToDoListClient(_httpFacade, toDoListBuilder);
            Connection    = new ConnectionClient(_httpFacade);
        }
Beispiel #6
0
 internal IssuesClient(
     GitLabHttpFacade httpFacade,
     IssuesQueryBuilder queryBuilder,
     NotesQueryBuilder notesQueryBuilder)
 {
     _httpFacade        = httpFacade;
     _queryBuilder      = queryBuilder;
     _notesQueryBuilder = notesQueryBuilder;
 }
        /// <summary>
        /// Creates a new instance of the GitLab API v4 client pointing to the specified hostUrl.
        /// </summary>
        /// <param name="hostUrl">Host address of GitLab instance. For example https://gitlab.example.com or https://gitlab.example.com/api/v4/ </param>
        /// <param name="authenticationToken">Personal access token. Obtained from GitLab profile settings.</param>
        public GitLabClient(string hostUrl, string authenticationToken = "")
        {
            Guard.NotEmpty(hostUrl, nameof(hostUrl));
            Guard.NotNull(authenticationToken, nameof(authenticationToken));
            HostUrl = FixBaseUrl(hostUrl);

            var jsonSerializer = new RequestsJsonSerializer();

            _httpFacade = new GitLabHttpFacade(
                HostUrl,
                jsonSerializer,
                authenticationToken);

            var projectQueryBuilder                   = new ProjectsQueryBuilder();
            var projectIssueNotesQueryBuilder         = new ProjectIssueNotesQueryBuilder();
            var projectMergeRequestsNotesQueryBuilder = new ProjectMergeRequestsNotesQueryBuilder();
            var issuesQueryBuilder               = new IssuesQueryBuilder();
            var mergeRequestsQueryBuilder        = new MergeRequestsQueryBuilder();
            var projectMilestonesQueryBuilder    = new MilestonesQueryBuilder();
            var projectMergeRequestsQueryBuilder = new ProjectMergeRequestsQueryBuilder();
            var groupsQueryBuilder               = new GroupsQueryBuilder();
            var groupLabelsQueryBuilder          = new GroupLabelsQueryBuilder();
            var projectsGroupsQueryBuilder       = new ProjectsGroupQueryBuilder();
            var branchQueryBuilder               = new BranchQueryBuilder();
            var releaseQueryBuilder              = new ReleaseQueryBuilder();
            var tagQueryBuilder        = new TagQueryBuilder();
            var commitQueryBuilder     = new CommitQueryBuilder();
            var commitRefsQueryBuilder = new CommitRefsQueryBuilder();
            var pipelineQueryBuilder   = new PipelineQueryBuilder();
            var treeQueryBuilder       = new TreeQueryBuilder();
            var jobQueryBuilder        = new JobQueryBuilder();

            Issues        = new IssuesClient(_httpFacade, issuesQueryBuilder, projectIssueNotesQueryBuilder);
            Uploads       = new UploadsClient(_httpFacade);
            MergeRequests = new MergeRequestsClient(_httpFacade, mergeRequestsQueryBuilder, projectMergeRequestsQueryBuilder, projectMergeRequestsNotesQueryBuilder);
            Projects      = new ProjectsClient(_httpFacade, projectQueryBuilder, projectMilestonesQueryBuilder, jobQueryBuilder);
            Users         = new UsersClient(_httpFacade);
            Groups        = new GroupsClient(_httpFacade, groupsQueryBuilder, projectsGroupsQueryBuilder, projectMilestonesQueryBuilder, groupLabelsQueryBuilder);
            Branches      = new BranchClient(_httpFacade, branchQueryBuilder);
            Releases      = new ReleaseClient(_httpFacade, releaseQueryBuilder);
            Tags          = new TagClient(_httpFacade, tagQueryBuilder);
            Webhooks      = new WebhookClient(_httpFacade);
            Commits       = new CommitsClient(_httpFacade, commitQueryBuilder, commitRefsQueryBuilder);
            Markdown      = new MarkdownClient(_httpFacade);
            Pipelines     = new PipelineClient(_httpFacade, pipelineQueryBuilder, jobQueryBuilder);
            Trees         = new TreesClient(_httpFacade, treeQueryBuilder);
            Files         = new FilesClient(_httpFacade);
            Runners       = new RunnersClient(_httpFacade);
        }
        public void NonDefaultQueryBuiltWithUserNames()
        {
            var sut = new IssuesQueryBuilder();

            string query = sut.Build(
                "https://gitlab.com/api/v4/issues",
                new IssuesQueryOptions
            {
                State            = EpicIssueState.Opened,
                Labels           = { "label1", "label2" },
                MilestoneTitle   = "milestone1",
                Scope            = Scope.All,
                AuthorId         = null,
                AssigneeId       = null,
                IssueIds         = { 3, 4 },
                Order            = EpicsIssuesOrder.UpdatedAt,
                SortOrder        = SortOrder.Ascending,
                Filter           = "filter",
                In               = SearchIn.Title,
                CreatedAfter     = new DateTime(1991, 11, 11, 1, 1, 1),
                CreatedBefore    = new DateTime(1991, 12, 12, 2, 2, 2),
                UpdatedAfter     = new DateTime(1991, 4, 4, 4, 4, 4),
                UpdatedBefore    = new DateTime(1991, 5, 5, 5, 5, 5),
                IsConfidential   = true,
                AuthorUsername   = "******",
                AssigneeUsername = new List <string> {
                    "user_1", "user_2"
                }
            });

            query.Should().BeEquivalentTo("https://gitlab.com/api/v4/issues?" +
                                          "state=opened&" +
                                          "labels=label1%2Clabel2&" +
                                          "milestone=milestone1&" +
                                          "scope=all&" +
                                          "author_username=user_1&" +
                                          "assignee_username=user_1%2Cuser_2&" +
                                          "iids%5B%5D=3&iids%5B%5D=4&" +
                                          "order_by=updated_at&" +
                                          "sort=asc&" +
                                          "search=filter&" +
                                          "in=title&" +
                                          "confidential=true&" +
                                          "created_before=1991-12-12T02%3a02%3a02.0000000&" +
                                          "created_after=1991-11-11T01%3a01%3a01.0000000&" +
                                          "updated_before=1991-05-05T05%3a05%3a05.0000000&" +
                                          "updated_after=1991-04-04T04%3a04%3a04.0000000");
        }