Beispiel #1
0
        async internal Task AddSpanAsync(bool add, TimeSpan span, MergeRequestDescriptor mrd)
        {
            GitLabClient client = new GitLabClient(mrd.HostName, Tools.Tools.GetAccessToken(mrd.HostName, Settings));

            try
            {
                await client.RunAsync(async (gitlab) =>
                                      await gitlab.Projects.Get(mrd.ProjectName).MergeRequests.Get(mrd.IId).AddSpentTimeAsync(
                                          new AddSpentTimeParameters
                {
                    Add  = add,
                    Span = span
                }));
            }
            catch (Exception ex)
            {
                Debug.Assert(!(ex is GitLabClientCancelled));
                if (ex is GitLabSharpException || ex is GitLabRequestException)
                {
                    ExceptionHandlers.Handle(ex, "Cannot send tracked time to GitLab");
                    throw new OperatorException(ex);
                }
                throw;
            }
        }
Beispiel #2
0
        async internal Task ModifyNoteBodyAsync(MergeRequestDescriptor mrd, string discussionId, int noteId, string body)
        {
            GitLabClient client = new GitLabClient(mrd.HostName, Tools.Tools.GetAccessToken(mrd.HostName, Settings));

            try
            {
                await client.RunAsync(async (gitlab) =>
                                      await gitlab.Projects.Get(mrd.ProjectName).MergeRequests.Get(mrd.IId).
                                      Discussions.Get(discussionId).ModifyNoteTaskAsync(noteId,
                                                                                        new ModifyDiscussionNoteParameters
                {
                    Type = ModifyDiscussionNoteParameters.ModificationType.Body,
                    Body = body
                }));
            }
            catch (Exception ex)
            {
                Debug.Assert(!(ex is GitLabClientCancelled));
                if (ex is GitLabSharpException || ex is GitLabRequestException)
                {
                    ExceptionHandlers.Handle(ex, "Cannot update discussion text");
                    throw new OperatorException(ex);
                }
                throw;
            }
        }
Beispiel #3
0
        async internal Task ReplyAsync(MergeRequestDescriptor mrd, string discussionId, string body)
        {
            GitLabClient client = new GitLabClient(mrd.HostName, Tools.Tools.GetAccessToken(mrd.HostName, Settings));

            try
            {
                await client.RunAsync(async (gitlab) =>
                                      await gitlab.Projects.Get(mrd.ProjectName).MergeRequests.Get(mrd.IId).
                                      Discussions.Get(discussionId).CreateNewNoteTaskAsync(
                                          new CreateNewNoteParameters
                {
                    Body = body
                }));
            }
            catch (Exception ex)
            {
                Debug.Assert(!(ex is GitLabClientCancelled));
                if (ex is GitLabSharpException || ex is GitLabRequestException)
                {
                    ExceptionHandlers.Handle(ex, "Cannot create a reply to discussion");
                    throw new OperatorException(ex);
                }
                throw;
            }
        }
Beispiel #4
0
        async internal Task ResolveDiscussionAsync(MergeRequestDescriptor mrd, string discussionId, bool resolved)
        {
            GitLabClient client = new GitLabClient(mrd.HostName, Tools.Tools.GetAccessToken(mrd.HostName, Settings));

            try
            {
                await client.RunAsync(async (gitlab) =>
                                      await gitlab.Projects.Get(mrd.ProjectName).MergeRequests.Get(mrd.IId).
                                      Discussions.Get(discussionId).ResolveTaskAsync(
                                          new ResolveThreadParameters
                {
                    Resolve = resolved
                }));
            }
            catch (Exception ex)
            {
                Debug.Assert(!(ex is GitLabClientCancelled));
                if (ex is GitLabSharpException || ex is GitLabRequestException)
                {
                    ExceptionHandlers.Handle(ex, "Cannot toggle 'Resolved' state of a discussion");
                    throw new OperatorException(ex);
                }
                throw;
            }
        }
Beispiel #5
0
 async public Task Run()
 {
     GitLabClient client = new GitLabClient(_callback.GetCurrentHostName(), _callback.GetCurrentAccessToken());
     await client.RunAsync(async (gitlab) =>
                           await gitlab.Projects.Get(_callback.GetCurrentProjectName()).MergeRequests.
                           Get(_callback.GetCurrentMergeRequestIId()).
                           Notes.CreateNewTaskAsync(new CreateNewNoteParameters
     {
         Body = _body
     }));
 }
Beispiel #6
0
        async internal Task <List <MergeRequest> > GetMergeRequestsAsync(string host, string project)
        {
            GitLabClient client = new GitLabClient(host, Tools.Tools.GetAccessToken(host, Settings));

            try
            {
                return((List <MergeRequest>)(await client.RunAsync(async(gitlab) =>
                                                                   await gitlab.Projects.Get(project).MergeRequests.LoadAllTaskAsync(new MergeRequestsFilter()))));
            }
            catch (Exception ex)
            {
                Debug.Assert(!(ex is GitLabClientCancelled));
                if (ex is GitLabSharpException || ex is GitLabRequestException)
                {
                    ExceptionHandlers.Handle(ex, "Cannot load merge requests from GitLab");
                    throw new OperatorException(ex);
                }
                throw;
            }
        }
Beispiel #7
0
        async internal Task <Discussion> GetDiscussionAsync(MergeRequestDescriptor mrd, string discussionId)
        {
            GitLabClient client = new GitLabClient(mrd.HostName, Tools.Tools.GetAccessToken(mrd.HostName, Settings));

            try
            {
                return((Discussion)(await client.RunAsync(async(gitlab) =>
                                                          await gitlab.Projects.Get(mrd.ProjectName).MergeRequests.Get(mrd.IId).
                                                          Discussions.Get(discussionId).LoadTaskAsync())));
            }
            catch (Exception ex)
            {
                Debug.Assert(!(ex is GitLabClientCancelled));
                if (ex is GitLabSharpException || ex is GitLabRequestException)
                {
                    ExceptionHandlers.Handle(ex, "Cannot load discussion from GitLab");
                    throw new OperatorException(ex);
                }
                throw;
            }
        }
Beispiel #8
0
        async internal Task CreateNoteAsync(MergeRequestDescriptor mrd, CreateNewNoteParameters parameters)
        {
            GitLabClient client = new GitLabClient(mrd.HostName, Tools.Tools.GetAccessToken(mrd.HostName, Settings));

            try
            {
                await client.RunAsync(async (gitlab) =>
                                      await gitlab.Projects.Get(mrd.ProjectName).MergeRequests.Get(mrd.IId).
                                      Notes.CreateNewTaskAsync(parameters));
            }
            catch (Exception ex)
            {
                Debug.Assert(!(ex is GitLabClientCancelled));
                if (ex is GitLabSharpException || ex is GitLabRequestException)
                {
                    ExceptionHandlers.Handle(ex, "Cannot create a note");
                    throw new OperatorException(ex);
                }
                throw;
            }
        }
Beispiel #9
0
        async internal Task <Version> GetLatestVersionAsync(MergeRequestDescriptor mrd)
        {
            GitLabClient client = new GitLabClient(mrd.HostName, Tools.Tools.GetAccessToken(mrd.HostName, Settings));

            try
            {
                List <Version> versions = (List <Version>)(await client.RunAsync(async(gitlab) =>
                                                                                 await gitlab.Projects.Get(mrd.ProjectName).MergeRequests.Get(mrd.IId).
                                                                                 Versions.LoadTaskAsync(new PageFilter {
                    PerPage = 1, PageNumber = 1
                })));
                return(versions.Count > 0 ? versions[0] : new Version());
            }
            catch (Exception ex)
            {
                Debug.Assert(!(ex is GitLabClientCancelled));
                if (ex is GitLabSharpException || ex is GitLabRequestException)
                {
                    ExceptionHandlers.Handle(ex, "Cannot load the latest version from GitLab");
                    throw new OperatorException(ex);
                }
                throw;
            }
        }