Skip to content

27: Add pagination support (Elixir)#30

Open
murjax wants to merge 1 commit intoelixir-repos-in-folder-22from
elixir-pagination-27
Open

27: Add pagination support (Elixir)#30
murjax wants to merge 1 commit intoelixir-repos-in-folder-22from
elixir-pagination-27

Conversation

@murjax
Copy link
Owner

@murjax murjax commented Sep 17, 2023

Issue #27 for Elixir.

|> List.first
|> GithubRepoCloner.Cloner.clone
username = List.first(args)
PageIterator.repeat(&Cloner.clone_page/1, %{username: username, page: 1})
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to rethink the cloner logic here. I could have simply tossed the existing logic in a loop that runs until we reach an empty page. That increases the cyclomatic complexity, or in other words the number of scenarios the function handles. I decided it was better to isolate the logic for cloning one page of repos (Cloner) and extract the logic for handling pagination elsewhere (PageIterator).


defp run_command(command) do
@system.cmd("sh", ["-c", command])
{:ok, @system.cmd("sh", ["-c", command])}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return an ok tuple if the clone command is run.

end

defp run_command("") do
{:error, "No repositories found"}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return an error tuple if the command is not run. This includes scenarios where no repos are found for the username or page and if the username is invalid.

@@ -0,0 +1,12 @@
defmodule GithubRepoCloner.PageIterator do
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rules of the page iterator:

  1. Accept an anonymous function and an arguments map that will be passed to the function.
  2. The arguments map must include a page.
  3. Recursively call the function while it returns an ok tuple, increasing the page number on each call.
  4. Stop recursion whenever an error tuple is returned.
  5. Page iterator returns the last successful page reached in an ok tuple at the end.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

write these in as a comment in this code.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you felt the need to add it here just add it as a comment in the code.

Copy link
Collaborator

@MichaelDimmitt MichaelDimmitt Sep 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the very least leave a comment describing the base condition that terminates the repeat iterator.

@murjax murjax changed the title 27: Add pagination support 27: Add pagination support (Elixir) Sep 17, 2023
|> List.first
|> GithubRepoCloner.Cloner.clone
username = List.first(args)
PageIterator.repeat(&Cloner.clone_page/1, %{username: username, page: 1})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the name should change to clone_pages ?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might wrap this in a new Cloner.clone_pages function. CLI will use Cloner.clone_pages.

Copy link
Collaborator

@MichaelDimmitt MichaelDimmitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left some comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants