async public Task <ConnectionCheckStatus> CheckConnection(string hostname, string token) { using (GitLabTaskRunner client = new GitLabTaskRunner(hostname, token)) { try { await CommonOperator.SearchCurrentUserAsync(client); return(ConnectionCheckStatus.OK); } catch (OperatorException ox) { if (ox.InnerException is GitLabRequestException rx) { if (rx.InnerException is System.Net.WebException wx) { if (wx.Response is System.Net.HttpWebResponse response && response.StatusCode == System.Net.HttpStatusCode.Unauthorized) { return(ConnectionCheckStatus.BadAccessToken); } } } } return(ConnectionCheckStatus.BadHostname); } }
async public Task Run() { string hostname = _callback.GetCurrentHostName(); string accessToken = _callback.GetCurrentAccessToken(); string projectName = _callback.GetCurrentProjectName(); int iid = _callback.GetCurrentMergeRequestIId(); GitLabTaskRunner client = new GitLabTaskRunner(hostname, accessToken); await client.RunAsync(async (gitlab) => { if (_label == Common.Constants.Constants.HighPriorityLabel) { SingleMergeRequestAccessor accessor = gitlab.Projects.Get(projectName).MergeRequests.Get(iid); GitLabSharp.Entities.MergeRequest mergeRequest = await accessor.LoadTaskAsync(); bool wasHighPriority = mergeRequest.Labels? .Contains(Common.Constants.Constants.HighPriorityLabel) ?? false; if (!wasHighPriority) { string[] labels = mergeRequest.Labels .Concat(new string[] { Common.Constants.Constants.HighPriorityLabel }).ToArray(); UpdateMergeRequestParameters updateMergeRequestParameters = new UpdateMergeRequestParameters( null, null, null, null, null, null, null, labels); await accessor.UpdateMergeRequestTaskAsync(updateMergeRequestParameters); } } return(null); }); }
async static public Task <ConnectionCheckStatus> CheckConnectionAsync(string hostname, string token) { using (GitLabTaskRunner client = new GitLabTaskRunner(hostname, token)) { try { await client.RunAsync(async (gl) => await gl.CurrentUser.LoadTaskAsync()); return(ConnectionCheckStatus.OK); } catch (Exception ex) // Any exception from GitLabSharp API { if (ex.InnerException is GitLabRequestException rx) { if (rx.InnerException is System.Net.WebException wx) { if (wx.Response is System.Net.HttpWebResponse response && response.StatusCode == System.Net.HttpStatusCode.Unauthorized) { return(ConnectionCheckStatus.BadAccessToken); } } } } return(ConnectionCheckStatus.BadHostname); } }
internal static Task <Project> SearchProjectAsync(GitLabTaskRunner client, string projectname) { return(OperatorCallWrapper.Call( async() => (Project)await client.RunAsync( async(gl) => await gl.Projects.Get(projectname).LoadTaskAsync()))); }
internal static Task <User> SearchCurrentUserAsync(GitLabTaskRunner client) { return(OperatorCallWrapper.Call( async() => (User)await client.RunAsync( async(gl) => await gl.CurrentUser.LoadTaskAsync()))); }
internal BaseOperator(string hostname, IHostProperties hostProperties, INetworkOperationStatusListener networkOperationStatusListener) { _settings = hostProperties; Hostname = hostname; _client = new GitLabTaskRunner(hostname, _settings.GetAccessToken(hostname)); _networkOperationStatusListener = networkOperationStatusListener; }
async public Task Run() { string hostname = _callback.GetCurrentHostName(); string accessToken = _callback.GetCurrentAccessToken(); string projectName = _callback.GetCurrentProjectName(); int iid = _callback.GetCurrentMergeRequestIId(); GitLabTaskRunner client = new GitLabTaskRunner(hostname, accessToken); await client.RunAsync(async (gitlab) => await gitlab.Projects.Get(projectName).MergeRequests. Get(iid).Notes.CreateNewTaskAsync(new CreateNewNoteParameters(_body))); }
async internal static Task <IEnumerable <MergeRequest> > SearchMergeRequestsAsync( GitLabTaskRunner client, SearchCriteria searchCriteria, int?maxResults, bool onlyOpen) { List <MergeRequest> mergeRequests = new List <MergeRequest>(); foreach (object search in searchCriteria.Criteria) { mergeRequests.AddRange( await OperatorCallWrapper.Call( async() => (IEnumerable <MergeRequest>)(await client.RunAsync( async(gl) => await MergeRequestSearchProcessorFactory.Create(search, onlyOpen).Process(gl, maxResults))))); } return(mergeRequests); }
async public Task Run() { string hostname = _callback.GetCurrentHostName(); string accessToken = _callback.GetCurrentAccessToken(); string projectName = _callback.GetCurrentProjectName(); int iid = _callback.GetCurrentMergeRequestIId(); GitLabTaskRunner client = new GitLabTaskRunner(hostname, accessToken); await client.RunAsync(async (gitlab) => { SingleMergeRequestAccessor accessor = gitlab.Projects.Get(projectName).MergeRequests.Get(iid); if (_endpoint == "approve") { return(await accessor.ApproveTaskAsync()); } else if (_endpoint == "unapprove") { return(await accessor.UnapproveTaskAsync()); } return(null); }); }
async private Task <GitLabVersion> getVersionAsync() { string token = HostProperties.GetAccessToken(HostName); using (GitLabTaskRunner client = new GitLabTaskRunner(HostName, token)) { try { return((GitLabVersion)(await client.RunAsync(async(gl) => await gl.Version.LoadTaskAsync()))); } catch (GitLabSharpException ex) { ExceptionHandlers.Handle("Cannot obtain GitLab server version", ex); } catch (GitLabRequestException ex) { ExceptionHandlers.Handle("Cannot obtain GitLab server version", ex); } catch (GitLabTaskRunnerCancelled) { } return(null); } }
internal BaseOperator(string hostname, IHostProperties hostProperties) { _settings = hostProperties; Hostname = hostname; _client = new GitLabTaskRunner(hostname, _settings.GetAccessToken(hostname)); }