Guest User

Untitled

a guest
Jun 25th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. const GitHubApi = require("github");
  2. const Rx = require("rx");
  3.  
  4. const github = new GitHubApi();
  5.  
  6. const getCommitsAsync = (param) => github.repos.getCommits({
  7. owner: 'amowu',
  8. repo: 'test-semantic-release',
  9. ...param
  10. });
  11.  
  12. const checkNextPage = (response) =>
  13. github.hasNextPage(response)
  14. ? Rx.Observable.fromPromise(github.getNextPage(response))
  15. : Rx.Observable.empty();
  16.  
  17. const concatAllCommits = (acc, curr) => acc.concat(curr.data);
  18.  
  19. const getAllCommits$ = Rx.Observable
  20. .fromPromise(getCommitsAsync({ per_page: 100 }))
  21. .expand(checkNextPage)
  22. .reduce(concatAllCommits, []);
  23.  
  24. // getAllCommits$.subscribe(
  25. // (commits) => console.log(commits)
  26. // );
  27.  
  28. const commits = await getAllCommits$.toPromise();
Add Comment
Please, Sign In to add comment