private async Task QueryGitLab() { GitLabClient client; if (string.IsNullOrEmpty(username.Text)) { client = new GitLabClient(host.Text, password.Text); } else { client = new GitLabClient(host.Text); var session = await client.LoginAsync(username.Text, password.Text); } var list = await client.Projects.GetAsync(); repositories.Items.Clear(); foreach (var project in list) { if (ssh.Checked) { repositories.Items.Add(project.SshUrlToRepo); } else { repositories.Items.Add(project.HttpUrlToRepo); } } }
private async Task QueryGitLab() { string baseUrl = GetOrSetHost("https://gitlab.com"); GitLabClient client; if (string.IsNullOrWhiteSpace(password.Text)) { MessageBox.Show("Please specify password or access token."); return; } if (string.IsNullOrEmpty(username.Text)) { client = new GitLabClient(baseUrl, password.Text); } else { client = new GitLabClient(baseUrl); try { var session = await client.LoginAsync(username.Text, password.Text); } catch (GitLabException) { MessageBox.Show("Login failed."); return; } } IList <GitLabApiClient.Models.Projects.Responses.Project> list; try { list = await client.Projects.GetAsync((o) => { o.Owned = true; }); } catch (HttpRequestException) { MessageBox.Show($"Failed to query GitLab instance at {baseUrl}."); return; } repositories.Items.Clear(); foreach (var project in list) { if (ssh.Checked) { repositories.Items.Add(project.SshUrlToRepo); } else { repositories.Items.Add(project.HttpUrlToRepo); } } }
private async void CreateClient() { if (string.IsNullOrEmpty(username.Text)) { client = new GitLabClient(host.Text, password.Text); } else { client = new GitLabClient(host.Text); var session = await client.LoginAsync(username.Text, password.Text); } }
public async void CanLogin() { var sut = new GitLabClient(GitLabContainerFixture.GitlabHost); var accessTokenResponse = await sut.LoginAsync(GitLabApiHelper.TestUserName, GitLabApiHelper.TestUserPassword); accessTokenResponse.Scope.Should().Be("api"); accessTokenResponse.CreatedAt.Should().NotBeNull(); accessTokenResponse.AccessToken.Should().HaveLength(64); accessTokenResponse.RefreshToken.Should().HaveLength(64); accessTokenResponse.TokenType.Should().Be("bearer"); var currentSessionAsync = await sut.Users.GetCurrentSessionAsync(); currentSessionAsync.Username.Should().Be(GitLabApiHelper.TestUserName); sut = new GitLabClient(GitLabContainerFixture.GitlabHost, accessTokenResponse.AccessToken); currentSessionAsync = await sut.Users.GetCurrentSessionAsync(); currentSessionAsync.Username.Should().Be(GitLabApiHelper.TestUserName); var facadeSut = new GitLabHttpFacade(GitLabContainerFixture.GitlabHost, new RequestsJsonSerializer(), GitLabContainerFixture.Token); currentSessionAsync = await facadeSut.Get <Session>("user"); currentSessionAsync.Username.Should().Be(GitLabApiHelper.TestUserName); accessTokenResponse = await facadeSut.LoginAsync(new AccessTokenRequest { GrantType = "password", Scope = "api", Username = GitLabApiHelper.TestUserName, Password = GitLabApiHelper.TestUserPassword }); currentSessionAsync = await facadeSut.Get <Session>("user"); currentSessionAsync.Username.Should().Be(GitLabApiHelper.TestUserName); facadeSut = new GitLabHttpFacade(GitLabContainerFixture.GitlabHost, new RequestsJsonSerializer(), accessTokenResponse.AccessToken); currentSessionAsync = await facadeSut.Get <Session>("user"); currentSessionAsync.Username.Should().Be(GitLabApiHelper.TestUserName); }