private async Task <Key> SaveToCloud(DatastoreService datastore, string projectId, Entity entity) { var trxbody = new BeginTransactionRequest(); var beginTrxRequest = datastore.Projects.BeginTransaction(trxbody, projectId); var res = await beginTrxRequest.ExecuteAsync(); var trxid = res.Transaction; var commitRequest = new CommitRequest(); commitRequest.Mutations = new List <Mutation>() { new Mutation() { Upsert = entity } }; commitRequest.Transaction = trxid; var commmitReq = datastore.Projects.Commit(commitRequest, projectId); var commitExec = await commmitReq.ExecuteAsync(); var res1 = commitExec.MutationResults.FirstOrDefault(); return(res1.Key); }
/// <summary> /// This method is called when a transaction that requested CommitStats is committed. /// The default implementation logs the commit stats at log level Info. Derived classes /// can override this method to log the statistics at a different level, or to a different /// destination. /// </summary> /// <param name="request">The commit request that requested commit statistics</param> /// <param name="response">The response with commit statistics</param> public virtual void LogCommitStats(CommitRequest request, CommitResponse response) { if (response.CommitStats != null) { Info(() => $"Transaction {request.TransactionId?.ToBase64() ?? ""} mutation count: {response.CommitStats.MutationCount}"); } }
/// <summary> /// Gets all commits for a given repository /// </summary> /// <param name="repositoryId">The Id of the repository</param> /// <param name="request">Used to filter list of commits returned</param> /// <param name="options">Options for changing the API response</param> public IObservable <GitHubCommit> GetAll(int repositoryId, CommitRequest request, ApiOptions options) { Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); return(_connection.GetAndFlattenAllPages <GitHubCommit>(ApiUrls.RepositoryCommits(repositoryId), request.ToParametersDictionary(), options)); }
/// <summary> /// Gets all commits for a given file path /// </summary> /// <param name="repoId">Repository Id</param> /// <param name="path">file path</param> /// <returns></returns> public static async Task <ObservableCollection <GitHubCommit> > GetAllCommitsForFile(long repoId, string path) { try { GitHubClient client = await UserUtility.GetAuthenticatedClient(); CommitRequest request = new CommitRequest { Path = path }; var list = await client.Repository.Commit.GetAll(repoId, request); ObservableCollection <GitHubCommit> commitList = new ObservableCollection <GitHubCommit>(); foreach (GitHubCommit c in list) { commitList.Add(c); } return(commitList); } catch { return(null); } }
public async Task CommitAsync2() { Mock <Datastore.DatastoreClient> mockGrpcClient = new Mock <Datastore.DatastoreClient>(MockBehavior.Strict); CommitRequest expectedRequest = new CommitRequest { ProjectId = "projectId-1969970175", Mode = CommitRequest.Types.Mode.Unspecified, Mutations = { }, }; CommitResponse expectedResponse = new CommitResponse { IndexUpdates = 1425228195, }; mockGrpcClient.Setup(x => x.CommitAsync(expectedRequest, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <CommitResponse>(Task.FromResult(expectedResponse), null, null, null, null)); DatastoreClient client = new DatastoreClientImpl(mockGrpcClient.Object, null); string projectId = "projectId-1969970175"; CommitRequest.Types.Mode mode = CommitRequest.Types.Mode.Unspecified; IEnumerable <Mutation> mutations = new List <Mutation>(); CommitResponse response = await client.CommitAsync(projectId, mode, mutations); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public override async Task FindFromSourceControl() { var folder = PathFile.Substring(0, PathFile.LastIndexOf("/")); string fileJSON = PathFile.Substring(PathFile.LastIndexOf("/") + 1); var requestJSON = new CommitRequest { Path = PathFile }; FileCommits = (await client.Repository.Commit.GetAll( idRepository, requestJSON)) .Select(translate) .ToArray(); var dateJSON = FileCommits.Max(it => it.CommitedDate); var requestFolder = new CommitRequest { Since = dateJSON.AddTicks(1), Path = folder }; FolderCommits = (await client.Repository.Commit.GetAll( idRepository, requestFolder)) .Where(it => it.Commit.Committer.Date > dateJSON) .Select(translate) .ToArray(); File = (await client.Repository.Content.GetAllContents(idRepository, PathFile)).First().Content; }
public void Commit() { Mock <Datastore.DatastoreClient> mockGrpcClient = new Mock <Datastore.DatastoreClient>(MockBehavior.Strict); CommitRequest expectedRequest = new CommitRequest { ProjectId = "projectId-1969970175", Mode = CommitRequest.Types.Mode.Unspecified, Transaction = ByteString.CopyFromUtf8("-34"), Mutations = { }, }; CommitResponse expectedResponse = new CommitResponse { IndexUpdates = 1425228195, }; mockGrpcClient.Setup(x => x.Commit(expectedRequest, It.IsAny <CallOptions>())) .Returns(expectedResponse); DatastoreClient client = new DatastoreClientImpl(mockGrpcClient.Object, null); string projectId = "projectId-1969970175"; CommitRequest.Types.Mode mode = CommitRequest.Types.Mode.Unspecified; ByteString transaction = ByteString.CopyFromUtf8("-34"); IEnumerable <Mutation> mutations = new List <Mutation>(); CommitResponse response = client.Commit(projectId, mode, transaction, mutations); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public void Commit2() { moq::Mock <Datastore.DatastoreClient> mockGrpcClient = new moq::Mock <Datastore.DatastoreClient>(moq::MockBehavior.Strict); CommitRequest request = new CommitRequest { Mode = CommitRequest.Types.Mode.Unspecified, Mutations = { new Mutation(), }, ProjectId = "project_id43ad98b0", }; CommitResponse expectedResponse = new CommitResponse { MutationResults = { new MutationResult(), }, IndexUpdates = 1466771529, }; mockGrpcClient.Setup(x => x.Commit(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse); DatastoreClient client = new DatastoreClientImpl(mockGrpcClient.Object, null); CommitResponse response = client.Commit(request.ProjectId, request.Mode, request.Mutations); xunit::Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public void RequestsCorrectUrlWithRepositoryIdWithApiOptionsParameterized() { var gitHubClient = Substitute.For <IGitHubClient>(); var client = new ObservableRepositoryCommitsClient(gitHubClient); var commitRequest = new CommitRequest { Author = "author", Sha = "sha", Path = "path", Since = null, Until = null }; var options = new ApiOptions { PageCount = 1, StartPage = 1, PageSize = 1 }; client.GetAll(1, commitRequest, options); gitHubClient.Received().Repository.Commit.GetAll(1, commitRequest, options); }
public async stt::Task Commit2Async() { moq::Mock <Datastore.DatastoreClient> mockGrpcClient = new moq::Mock <Datastore.DatastoreClient>(moq::MockBehavior.Strict); CommitRequest request = new CommitRequest { Mode = CommitRequest.Types.Mode.Unspecified, Mutations = { new Mutation(), }, ProjectId = "project_id43ad98b0", }; CommitResponse expectedResponse = new CommitResponse { MutationResults = { new MutationResult(), }, IndexUpdates = 1466771529, }; mockGrpcClient.Setup(x => x.CommitAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <CommitResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null)); DatastoreClient client = new DatastoreClientImpl(mockGrpcClient.Object, null); CommitResponse responseCallSettings = await client.CommitAsync(request.ProjectId, request.Mode, request.Mutations, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); CommitResponse responseCancellationToken = await client.CommitAsync(request.ProjectId, request.Mode, request.Mutations, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
public async Task InitiateCommitForMoveResourcesAsync() { using (var context = MockContext.Start(this.GetType())) { this.TestHelper.Initialize(context); var client = this.TestHelper.ResourceMoverServiceClient; var commitRequest = new CommitRequest() { MoveResources = new List <string>() { VirtualMachineId, NetworkInterfaceId, PublicIpId, LoadBalancerId, VirtualNetworkId, NetworkSecurityGroupId }, MoveResourceInputType = MoveResourceInputType.MoveResourceSourceId }; var operationStatus = (await client.MoveCollections.CommitWithHttpMessagesAsync( MoveCollectionResourceGroup, MoveCollectionName, commitRequest)).Body; Assert.True(OperationStatusSucceeded.Equals( operationStatus.Status, StringComparison.OrdinalIgnoreCase), "Commit operation should have succeeded."); } }
public async Task RequestsCorrectUrlWithRepositoryIdWithApiOptionsParameterized() { var connection = Substitute.For <IApiConnection>(); var client = new RepositoryCommitsClient(connection); var commitRequest = new CommitRequest { Author = "author", Sha = "sha", Path = "path", Since = null, Until = null }; var options = new ApiOptions { PageCount = 1, StartPage = 1, PageSize = 1 }; await client.GetAll(1, commitRequest, options); connection.Received().GetAll <GitHubCommit>(Arg.Is <Uri>(u => u.ToString() == "repositories/1/commits"), Arg.Is <IDictionary <string, string> >(d => d["author"] == "author" && d["sha"] == "sha" && d["path"] == "path" && !d.ContainsKey("since") && !d.ContainsKey("until")), options); }
public async stt::Task CommitRequestObjectAsync() { moq::Mock <Firestore.FirestoreClient> mockGrpcClient = new moq::Mock <Firestore.FirestoreClient>(moq::MockBehavior.Strict); CommitRequest request = new CommitRequest { Database = "projects/test/databases/databased8eee011", Writes = { new Write(), }, Transaction = proto::ByteString.CopyFromUtf8("transaction6ab7d5f4"), }; CommitResponse expectedResponse = new CommitResponse { WriteResults = { new WriteResult(), }, CommitTime = new wkt::Timestamp(), }; mockGrpcClient.Setup(x => x.CommitAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <CommitResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null)); FirestoreClient client = new FirestoreClientImpl(mockGrpcClient.Object, null); CommitResponse responseCallSettings = await client.CommitAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); CommitResponse responseCancellationToken = await client.CommitAsync(request, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
public async Task<IReadOnlyList<GitHubCommit>> GetFileCommitsAsync(string name, string repositoryName, string version, string filename, string token) { var client = GetGitHubClient(name, token); var repo = await client.Repository.Get(name, repositoryName); var request = new CommitRequest { Path = filename, Sha = version }; return await client.Repository.Commit.GetAll(repo.Id, request); }
/// <summary> /// This request is used to issue a commit on the Connection in the Phoenix query server identified by the given ID. /// </summary> public async Task <CommitResponse> CommitRequestAsync(string connectionId, RequestOptions options) { CommitRequest req = new CommitRequest { ConnectionId = connectionId }; WireMessage msg = new WireMessage { Name = Constants.WireMessagePrefix + "CommitRequest", WrappedMessage = req.ToByteString() }; using (Response webResponse = await PostRequestAsync(msg.ToByteArray(), options)) { if (webResponse.WebResponse.StatusCode != HttpStatusCode.OK) { WireMessage output = WireMessage.Parser.ParseFrom(webResponse.WebResponse.GetResponseStream()); ErrorResponse res = ErrorResponse.Parser.ParseFrom(output.WrappedMessage); throw new WebException( string.Format( "CommitRequestAsync failed! connectionId: {0}, Response code was: {1}, Response body was: {2}", connectionId, webResponse.WebResponse.StatusCode, res.ToString())); } else { WireMessage output = WireMessage.Parser.ParseFrom(webResponse.WebResponse.GetResponseStream()); CommitResponse res = CommitResponse.Parser.ParseFrom(output.WrappedMessage); return(res); } } }
private async Task <Key> trainAriaStark(DatastoreService datastore, string projectId) { var trxbody = new BeginTransactionRequest(); var beginTrxRequest = datastore.Projects.BeginTransaction(trxbody, projectId); var res = await beginTrxRequest.ExecuteAsync(); var trxid = res.Transaction; var entity = new Entity() { Key = new Key() { PartitionId = new PartitionId() { NamespaceId = "", ProjectId = projectId }, Path = new List <PathElement>() { new PathElement() { Kind = "jhpsystems", Name = "A8CFCA9D-0B3C-43F7-B7AD-DA21AE79C92F" } } }, Properties = new Dictionary <string, Value>() { { "cardserial", new Value() { IntegerValue = 2022 } }, { "datablob", new Value() { StringValue = "I was once a blob" } }, { "registerno", new Value() { IntegerValue = 666 } } } }; var commitRequest = new CommitRequest(); commitRequest.Mutations = new List <Mutation>() { new Mutation() { Upsert = entity } }; commitRequest.Transaction = trxid; var commmitReq = datastore.Projects.Commit(commitRequest, projectId); var commitExec = await commmitReq.ExecuteAsync(); var res1 = commitExec.MutationResults.FirstOrDefault(); return(res1.Key); }
/// <summary> /// Gets all commits for a given repository /// </summary> /// <param name="owner">The owner of the repository</param> /// <param name="name">The name of the repository</param> /// <param name="request">Used to filter list of commits returned</param> /// <param name="options">Options for changing the API response</param> /// <returns></returns> public IObservable <GitHubCommit> GetAll(string owner, string name, CommitRequest request, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(request, "request"); return(_connection.GetAndFlattenAllPages <GitHubCommit>(ApiUrls.RepositoryCommits(owner, name), request.ToParametersDictionary(), options)); }
/// <summary> /// Gets all commits for a given repository /// </summary> /// <param name="owner">The owner of the repository</param> /// <param name="name">The name of the repository</param> /// <param name="request">Used to filter list of commits returned</param> /// <returns></returns> public IObservable<GitHubCommit> GetAll(string owner, string name, CommitRequest request) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(request, "request"); return GetAll(owner, name, request, ApiOptions.None); }
/// <summary> /// Gets all commits for a given repository /// </summary> /// <param name="owner">The owner of the repository</param> /// <param name="name">The name of the repository</param> /// <param name="request">Used to filter list of commits returned</param> public IObservable <GitHubCommit> GetAll(string owner, string name, CommitRequest request) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(request, "request"); return(GetAll(owner, name, request, ApiOptions.None)); }
public override async Task <CommitResponse> CommitAsync(CommitRequest request, CallSettings callSettings = null) { await Task.Yield(); return(new CommitResponse { CommitTimestamp = Timestamp.FromDateTime(DateTime.UtcNow) }); }
public async Task Pull() { var data = new Dictionary <string, HashSet <string> >(); void Add(Committer committer, string name) { if (committer?.Name != "Andrey Akinshin") { return; } var date = committer.Date; var key = date.ToString("yyyy-MM"); if (!data.ContainsKey(key)) { data[key] = new HashSet <string>(); } data[key].Add(name); } var provider = DataProvider.ReadOpenSource(); foreach (var repoGroup in provider.En) { foreach (var repo in repoGroup.Repos) { var sp = repo.Url.Split('/'); Console.WriteLine("## " + repo.Url); var commitRequest = new CommitRequest { Author = "AndreyAkinshin" }; var commits = await client.Repository.Commit.GetAll(sp[0], sp[1], commitRequest); foreach (var commit in commits) { Add(commit?.Commit?.Author, repo.Url); Add(commit?.Commit?.Committer, repo.Url); } } } var builder = new StringBuilder(); builder.AppendLine("activities:"); foreach (var key in data.Keys.OrderByDescending(it => it)) { builder.AppendLine(" - month: " + key); builder.AppendLine(" repos:"); foreach (var url in data[key].OrderBy(it => it)) { builder.AppendLine(" - url: " + url); } } File.WriteAllText("activities.yaml", builder.ToString()); }
public async Task CanGetListOfCommitsBySha() { var request = new CommitRequest { Sha = "21599cd93657eeb7bde31989da61bd046c2ecd9e" }; var list = await _fixture.GetAll("octokit", "octokit.net", request); Assert.NotEmpty(list); }
public async Task CanGetListOfCommitsByShaWithRepositoryId() { var request = new CommitRequest { Sha = "08b363d45d6ae8567b75dfa45c032a288584afd4" }; var list = await _fixture.GetAll(SniperNetRepositoryId, request); Assert.NotEmpty(list); }
public async Task CanGetListOfCommitsByAuthorWithRepositoryId() { var request = new CommitRequest { Author = "kzu" }; var list = await _fixture.GetAll(SniperNetRepositoryId, request); Assert.NotEmpty(list); }
public async Task CanGetListOfCommitsByUntilDate() { var request = new CommitRequest { Until = DateTimeOffset.Now }; var list = await _fixture.GetAll("octokit", "octokit.net", request); Assert.NotEmpty(list); }
public async Task CanGetListOfCommitsByPathWithRepositoryId() { var request = new CommitRequest { Path = "Sniper.Reactive/IObservableGitHubClient.cs" }; var list = await _fixture.GetAll(SniperNetRepositoryId, request); Assert.NotEmpty(list); }
public async Task CanGetListOfCommitsBySinceDate() { var request = new CommitRequest { Since = new DateTimeOffset(2014, 1, 1, 0, 0, 0, new TimeSpan(1, 0, 0)) }; var list = await _fixture.GetAll("octokit", "octokit.net", request); Assert.NotEmpty(list); }
/// <summary> /// Gets all commits for a given repository /// </summary> /// <param name="owner">The owner of the repository</param> /// <param name="name">The name of the repository</param> /// <param name="request">Used to filter list of commits returned</param> /// <returns></returns> public IObservable<GitHubCommit> GetAll(string owner, string name, CommitRequest request) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(request, "request"); return _connection.GetAndFlattenAllPages<GitHubCommit>(ApiUrls.RepositoryCommits(owner, name), request.ToParametersDictionary()); }
public async Task CanGetListOfCommitsByAuthor() { var request = new CommitRequest { Author = "kzu" }; var list = await _fixture.GetAll("octokit", "octokit.net", request); Assert.NotEmpty(list); }
public void CancelBooking(Booking booking) { CancelRequest cancelrequest = new CancelRequest(); cancelrequest.Signature = signature; CancelRequestData cancelrequestdata = new CancelRequestData(); cancelrequest.CancelRequestData = cancelrequestdata; cancelrequestdata.CancelBy = CancelBy.Journey; CancelJourney canceljourney = new CancelJourney(); cancelrequestdata.CancelJourney = canceljourney; CancelJourneyRequest canceljourneyrequest = new CancelJourneyRequest(); canceljourney.CancelJourneyRequest = canceljourneyrequest; //Journey[] journeys = new Journey[1]; //journeys[0] = new Journey(); //journeys[0].Segments = new Segment[1];//here i am assuming this is a direct journey with one segment //journeys[0].Segments[0] = new Segment(); //journeys[0].Segments[0].ActionStatusCode = booking.Journeys[0].Segments[0].ActionStatusCode; //journeys[0].Segments[0].DepartureStation = booking.Journeys[0].Segments[0].DepartureStation; //journeys[0].Segments[0].ArrivalStation = booking.Journeys[0].Segments[0].ArrivalStation; //journeys[0].Segments[0].STD = booking.Journeys[0].Segments[0].STD; //journeys[0].Segments[0].STA = booking.Journeys[0].Segments[0].STA; //journeys[0].Segments[0].FlightDesignator = booking.Journeys[0].Segments[0].FlightDesignator;//flight designator means carrier code canceljourneyrequest.Journeys = new Journey[1]; canceljourneyrequest.Journeys[0] = new Journey(); canceljourneyrequest.Journeys[0].Segments = new Segment[booking.Journeys[0].Segments.Length]; for (int i = 0; i < booking.Journeys[0].Segments.Length; i++) { canceljourneyrequest.Journeys[0].Segments[i] = new Segment(); canceljourneyrequest.Journeys[0].Segments[i].STA = booking.Journeys[0].Segments[i].STA; canceljourneyrequest.Journeys[0].Segments[i].STD = booking.Journeys[0].Segments[i].STD; canceljourneyrequest.Journeys[0].Segments[i].ArrivalStation = booking.Journeys[0].Segments[i].ArrivalStation; canceljourneyrequest.Journeys[0].Segments[i].DepartureStation = booking.Journeys[0].Segments[i].DepartureStation; canceljourneyrequest.Journeys[0].Segments[i].FlightDesignator = booking.Journeys[0].Segments[i].FlightDesignator; canceljourneyrequest.Journeys[0].Segments[i].Fares = new Fare[1]; canceljourneyrequest.Journeys[0].Segments[i].Fares[0] = new Fare(); canceljourneyrequest.Journeys[0].Segments[i].Fares[0].CarrierCode = booking.Journeys[0].Segments[i].Fares[0].CarrierCode; canceljourneyrequest.Journeys[0].Segments[i].PaxSSRs = new PaxSSR[0]; } canceljourneyrequest.Journeys = booking.Journeys; CancelResponse cancelresponse = clientapi.Cancel(cancelrequest); Console.WriteLine("Balance Due after cancellation: {0:C}", cancelresponse.BookingUpdateResponseData.Success.PNRAmount.BalanceDue); CommitRequest commitrequest = new CommitRequest(); commitrequest.BookingRequest = new CommitRequestData(); commitrequest.BookingRequest.Booking = new Booking(); commitrequest.BookingRequest.Booking.RecordLocator = booking.RecordLocator; commitrequest.BookingRequest.Booking.CurrencyCode = booking.CurrencyCode; commitrequest.BookingRequest.Booking.ReceivedBy = new ReceivedByInfo(); commitrequest.BookingRequest.Booking.ReceivedBy.ReceivedBy = "Michelle New"; commitrequest.Signature = signature; CommitResponse commitbookingresponse = clientapi.Commit(commitrequest); }
public async Task CanGetListOfCommitsBySha() { var request = new CommitRequest { Sha = "08b363d45d6ae8567b75dfa45c032a288584afd4" }; var list = await _fixture.GetAll("octokit", "octokit.net", request); Assert.NotEmpty(list); }
public async Task CanGetListOfCommitsByPath() { var request = new CommitRequest { Path = "Octokit.Reactive/IObservableGitHubClient.cs" }; var list = await _fixture.GetAll("octokit", "octokit.net", request); Assert.NotEmpty(list); }
public CommitResponse Commit(string token) { return(ExceptionHandler.Perform <CommitResponse, TransactionCommitException>(() => { var commitRequest = new CommitRequest(token); return _requestService.Perform <CommitResponse, TransactionCommitException>( commitRequest, Options); })); }
public void EnsuresNonEmptyArguments() { var connection = Substitute.For<IApiConnection>(); var client = new RepositoryCommitsClient(connection); var options = new ApiOptions(); var request = new CommitRequest(); Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("", "name", request, options)); Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("owner", "", request, options)); }
public void EnsuresNonEmptyArguments() { var githubClient = Substitute.For<IGitHubClient>(); var client = new ObservableRepositoryCommitsClient(githubClient); var options = new ApiOptions(); var request = new CommitRequest(); Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("", "name", request, options).ToTask()); Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("owner", "", request, options).ToTask()); }
public void GetsCorrectUrl() { var githubClient = Substitute.For<IGitHubClient>(); var client = new ObservableRepositoryCommitsClient(githubClient); var options = new ApiOptions(); var request = new CommitRequest(); client.GetAll("fake", "repo", request, options); githubClient.Received().Repository.Commit.GetAll("fake", "repo", request, options); }
public IQueryable<Commit> GetAll(CommitRequest request = null) { var query = this.commits.All(); if (request != null) { query = query.Where(c => c.SoftwareProjectId == request.Id); } if (!string.IsNullOrWhiteSpace(request.ByUser)) { query = query.Where(c => c.User.Email == request.ByUser); } return query .OrderByDescending(c => c.CreatedOn) .Skip((request.Page - 1) * request.PageSize) .Take(request.PageSize); }
/// <summary> /// Gets all commits for a given repository /// </summary> /// <param name="repositoryId">The Id of the repository</param> /// <param name="request">Used to filter list of commits returned</param> /// <param name="options">Options for changing the API response</param> public IObservable<GitHubCommit> GetAll(long repositoryId, CommitRequest request, ApiOptions options) { Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); return _connection.GetAndFlattenAllPages<GitHubCommit>(ApiUrls.RepositoryCommits(repositoryId), request.ToParametersDictionary(), options); }
/// <summary> /// Gets all commits for a given repository /// </summary> /// <param name="repositoryId">The Id of the repository</param> /// <param name="request">Used to filter list of commits returned</param> public IObservable<GitHubCommit> GetAll(long repositoryId, CommitRequest request) { Ensure.ArgumentNotNull(request, "request"); return GetAll(repositoryId, request, ApiOptions.None); }
/// <summary> /// A convenience function which commits a mutation to datastore. /// Use this function to avoid a lot of boilerplate. /// </summary> /// <param name="mutation">The change to make to datastore.</param> /// <returns>The result of commiting the change.</returns> // [START commitmutation] private CommitResponse CommitMutation(Mutation mutation) { var commitRequest = new CommitRequest() { Mode = "NON_TRANSACTIONAL", Mutation = mutation }; return _datastore.Datasets.Commit(commitRequest, _projectId) .Execute(); }
public void RequestsCorrectUrlWithRepositoryIdWithApiOptionsParameterized() { var gitHubClient = Substitute.For<IGitHubClient>(); var client = new ObservableRepositoryCommitsClient(gitHubClient); var commitRequest = new CommitRequest { Author = "author", Sha = "sha", Path = "path", Since = null, Until = null }; var options = new ApiOptions { PageCount = 1, StartPage = 1, PageSize = 1 }; client.GetAll(1, commitRequest, options); gitHubClient.Received().Repository.Commit.GetAll(1, commitRequest, options); }
public async Task<ActionResult> Create(Errorable<RefName> erefName, CommitRequest cmj) { if (erefName.HasErrors) return ErrorJson(erefName); if (cmj == null) return Json(new { success = false }); // First get the ref and its CommitID, if it exists: Ref rf; var erf = await cms.rfrepo.GetRefByName(erefName.Value); if (erf.HasErrors) { // Skip the RefNameDoesNotExistError error (should only be one - using All() makes sure that any other errors will fall out): if (!erf.Errors.All(err => err is RefNameDoesNotExistError)) return ErrorJson(erf); rf = null; } else rf = erf.Value; // Map from the JSON CommitModel: var ecb = cmj.FromJSON(); if (ecb.HasErrors) return ErrorJson(ecb); Commit.Builder cb = ecb.Value; // Add the ref's CommitID as the parent, if the ref exists: if ((rf != null) && (cb.Parents.Count == 0)) { cb.Parents.Add(rf.CommitID); } // Persist the commit: var epcm = await cms.cmrepo.PersistCommit(cb); if (epcm.HasErrors) return ErrorJson(epcm); Commit pcm = epcm.Value; // Persist the ref with this new CommitID: Ref.Builder rfb = new Ref.Builder(erefName.Value, pcm.ID); erf = await cms.rfrepo.PersistRef(rfb); if (erf.HasErrors) return ErrorJson(erf); rf = erf.Value; // Return the commit model as JSON again: return Json(new { @ref = rf.ToJSON(), commit = pcm.ToJSON() }, JsonRequestBehavior.AllowGet); }
/// <summary> /// This request is used to issue a commit on the Connection in the Phoenix query server identified by the given ID. /// </summary> public async Task<CommitResponse> CommitRequestAsync(string connectionId, RequestOptions options) { CommitRequest req = new CommitRequest { ConnectionId = connectionId }; WireMessage msg = new WireMessage { Name = Constants.WireMessagePrefix + "CommitRequest", WrappedMessage = req.ToByteString() }; using (Response webResponse = await PostRequestAsync(msg.ToByteArray(), options)) { if (webResponse.WebResponse.StatusCode != HttpStatusCode.OK) { WireMessage output = WireMessage.Parser.ParseFrom(webResponse.WebResponse.GetResponseStream()); ErrorResponse res = ErrorResponse.Parser.ParseFrom(output.WrappedMessage); throw new WebException( string.Format( "CommitRequestAsync failed! connectionId: {0}, Response code was: {1}, Response body was: {2}", connectionId, webResponse.WebResponse.StatusCode, res.ToString())); } else { WireMessage output = WireMessage.Parser.ParseFrom(webResponse.WebResponse.GetResponseStream()); CommitResponse res = CommitResponse.Parser.ParseFrom(output.WrappedMessage); return res; } } }
public void RequestsCorrectUrlWithRepositoryIdParameterized() { var gitHubClient = Substitute.For<IGitHubClient>(); var client = new ObservableRepositoryCommitsClient(gitHubClient); var commitRequest = new CommitRequest { Author = "author", Sha = "sha", Path = "path", Since = null, Until = null }; client.GetAll(1, commitRequest); gitHubClient.Received().Repository.Commit.GetAll(1, commitRequest); }
public async Task RequestsCorrectUrlParameterized() { var connection = Substitute.For<IApiConnection>(); var client = new RepositoryCommitsClient(connection); var commitRequest = new CommitRequest { Author = "author", Sha = "sha", Path = "path", Since = null, Until = null }; await client.GetAll("fake", "repo", commitRequest); connection.Received().GetAll<GitHubCommit>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/commits"), Arg.Is<IDictionary<string, string>>(d => d["author"] == "author" && d["sha"] == "sha" && d["path"] == "path" && !d.ContainsKey("since") && !d.ContainsKey("until")), Args.ApiOptions); }
public async Task RequestsCorrectUrlWithRepositoryIdWithApiOptionsParameterized() { var connection = Substitute.For<IApiConnection>(); var client = new RepositoryCommitsClient(connection); var commitRequest = new CommitRequest { Author = "author", Sha = "sha", Path = "path", Since = null, Until = null }; var options = new ApiOptions { PageCount = 1, StartPage = 1, PageSize = 1 }; await client.GetAll(1, commitRequest, options); connection.Received().GetAll<GitHubCommit>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/commits"), Arg.Is<IDictionary<string, string>>(d => d["author"] == "author" && d["sha"] == "sha" && d["path"] == "path" && !d.ContainsKey("since") && !d.ContainsKey("until")), options); }