test_class.file: dockerfile-image-update/src/test/java/com/salesforce/dockerfileimageupdate/subcommands/impl/AllTest.java
test_class.identifier: AllTest
test_case.body: @Test
      public void testForkRepositoriesFound() throws Exception {
          DockerfileGitHubUtil dockerfileGitHubUtil = mock(DockerfileGitHubUtil.class);
  
          GHRepository contentRepo1 = mock(GHRepository.class);
          GHRepository contentRepo2 = mock(GHRepository.class);
          GHRepository contentRepo3 = mock(GHRepository.class);
  
          GHContent content1 = mock(GHContent.class);
          when(content1.getOwner()).thenReturn(contentRepo1);
          GHContent content2 = mock(GHContent.class);
          when(content2.getOwner()).thenReturn(contentRepo2);
          GHContent content3 = mock(GHContent.class);
          when(content3.getOwner()).thenReturn(contentRepo3);
  
          PagedSearchIterable<GHContent> contentsWithImage = mock(PagedSearchIterable.class);
  
          PagedIterator<GHContent> contentsWithImageIterator = mock(PagedIterator.class);
          when(contentsWithImageIterator.hasNext()).thenReturn(true, true, true, false);
          when(contentsWithImageIterator.next()).thenReturn(content1, content2, content3, null);
          when(contentsWithImage.iterator()).thenReturn(contentsWithImageIterator);
  
          All all = new All();
          all.loadDockerfileGithubUtil(dockerfileGitHubUtil);
          all.forkRepositoriesFound(ArrayListMultimap.create(), ArrayListMultimap.create(), contentsWithImage, "image");
  
          Mockito.verify(dockerfileGitHubUtil, times(3)).getOrCreateFork(any());
      }
test_case.class_method_signature: AllTest.testForkRepositoriesFound()
test_case.full_signature: @Test public void testForkRepositoriesFound()
test_case.identifier: testForkRepositoriesFound
test_case.invocations: mock mock mock mock mock thenReturn when getOwner mock thenReturn when getOwner mock thenReturn when getOwner mock mock thenReturn when hasNext thenReturn when next thenReturn when iterator loadDockerfileGithubUtil forkRepositoriesFound create create getOrCreateFork verify times any
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testForkRepositoriesFound()
focal_class.declarator: log = LoggerFactory.getLogger(All.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger log = LoggerFactory.getLogger(All.class);
focal_class.type: Logger
focal_class.var_name: log
focal_class.declarator: dockerfileGitHubUtil
focal_class.modifier: private
focal_class.original_string: private DockerfileGitHubUtil dockerfileGitHubUtil;
focal_class.type: DockerfileGitHubUtil
focal_class.var_name: dockerfileGitHubUtil
focal_class.file: dockerfile-image-update/src/main/java/com/salesforce/dockerfileimageupdate/subcommands/impl/All.java
focal_class.identifier: All
focal_class.interfaces: implements ExecutableWithNamespace
focal_class.class_method_signature: All.execute(final Namespace ns, final DockerfileGitHubUtil dockerfileGitHubUtil)
focal_class.full_signature: @Override public void execute(final Namespace ns, final DockerfileGitHubUtil dockerfileGitHubUtil)
focal_class.identifier: execute
focal_class.modifiers: @Override public
focal_class.parameters: (final Namespace ns, final DockerfileGitHubUtil dockerfileGitHubUtil)
focal_class.return: void
focal_class.signature: void execute(final Namespace ns, final DockerfileGitHubUtil dockerfileGitHubUtil)
focal_class.class_method_signature: All.loadDockerfileGithubUtil(DockerfileGitHubUtil _dockerfileGitHubUtil)
focal_class.full_signature: protected void loadDockerfileGithubUtil(DockerfileGitHubUtil _dockerfileGitHubUtil)
focal_class.identifier: loadDockerfileGithubUtil
focal_class.modifiers: protected
focal_class.parameters: (DockerfileGitHubUtil _dockerfileGitHubUtil)
focal_class.return: void
focal_class.signature: void loadDockerfileGithubUtil(DockerfileGitHubUtil _dockerfileGitHubUtil)
focal_class.class_method_signature: All.forkRepositoriesFound(Multimap<String, String> pathToDockerfilesInParentRepo,
                                           Multimap<String, String> imagesFoundInParentRepo,
                                           PagedSearchIterable<GHContent> contentsWithImage,
                                           String image)
focal_class.full_signature: protected void forkRepositoriesFound(Multimap<String, String> pathToDockerfilesInParentRepo,
                                           Multimap<String, String> imagesFoundInParentRepo,
                                           PagedSearchIterable<GHContent> contentsWithImage,
                                           String image)
focal_class.identifier: forkRepositoriesFound
focal_class.modifiers: protected
focal_class.parameters: (Multimap<String, String> pathToDockerfilesInParentRepo,
                                           Multimap<String, String> imagesFoundInParentRepo,
                                           PagedSearchIterable<GHContent> contentsWithImage,
                                           String image)
focal_class.return: void
focal_class.signature: void forkRepositoriesFound(Multimap<String, String> pathToDockerfilesInParentRepo,
                                           Multimap<String, String> imagesFoundInParentRepo,
                                           PagedSearchIterable<GHContent> contentsWithImage,
                                           String image)
focal_class.class_method_signature: All.parseStoreToImagesMap(String storeName)
focal_class.full_signature: protected Set<Map.Entry<String, JsonElement>> parseStoreToImagesMap(String storeName)
focal_class.identifier: parseStoreToImagesMap
focal_class.modifiers: protected
focal_class.parameters: (String storeName)
focal_class.return: Set<Map.Entry<String, JsonElement>>
focal_class.signature: Set<Map.Entry<String, JsonElement>> parseStoreToImagesMap(String storeName)
focal_class.class_method_signature: All.changeDockerfiles(Namespace ns,
                                       Multimap<String, String> pathToDockerfilesInParentRepo,
                                       Multimap<String, String> imagesFoundInParentRepo,
                                       Map<String, String> imageToTagMap,
                                       GHRepository currUserRepo,
                                       List<String> skippedRepos)
focal_class.full_signature: protected void changeDockerfiles(Namespace ns,
                                       Multimap<String, String> pathToDockerfilesInParentRepo,
                                       Multimap<String, String> imagesFoundInParentRepo,
                                       Map<String, String> imageToTagMap,
                                       GHRepository currUserRepo,
                                       List<String> skippedRepos)
focal_class.identifier: changeDockerfiles
focal_class.modifiers: protected
focal_class.parameters: (Namespace ns,
                                       Multimap<String, String> pathToDockerfilesInParentRepo,
                                       Multimap<String, String> imagesFoundInParentRepo,
                                       Map<String, String> imageToTagMap,
                                       GHRepository currUserRepo,
                                       List<String> skippedRepos)
focal_class.return: void
focal_class.signature: void changeDockerfiles(Namespace ns,
                                       Multimap<String, String> pathToDockerfilesInParentRepo,
                                       Multimap<String, String> imagesFoundInParentRepo,
                                       Map<String, String> imageToTagMap,
                                       GHRepository currUserRepo,
                                       List<String> skippedRepos)
focal_class.class_method_signature: All.getPullRequestWithPullReqIdentifier(GHRepository parent)
focal_class.full_signature: private GHPullRequest getPullRequestWithPullReqIdentifier(GHRepository parent)
focal_class.identifier: getPullRequestWithPullReqIdentifier
focal_class.modifiers: private
focal_class.parameters: (GHRepository parent)
focal_class.return: GHPullRequest
focal_class.signature: GHPullRequest getPullRequestWithPullReqIdentifier(GHRepository parent)
focal_method.body: protected void forkRepositoriesFound(Multimap<String, String> pathToDockerfilesInParentRepo,
                                           Multimap<String, String> imagesFoundInParentRepo,
                                           PagedSearchIterable<GHContent> contentsWithImage,
                                           String image) throws IOException {
          log.info("Forking {} repositories...", contentsWithImage.getTotalCount());
          List<String> parentReposForked = new ArrayList<>();
          GHRepository parent;
          String parentRepoName = null;
          for (GHContent c : contentsWithImage) {
              /* Kohsuke's GitHub API library, when retrieving the forked repository, looks at the name of the parent to
               * retrieve. The issue with that is: GitHub, when forking two or more repositories with the same name,
               * automatically fixes the names to be unique (by appending "-#" to the end). Because of this edge case, we
               * cannot save the forks and iterate over the repositories; else, we end up missing/not updating the
               * repositories that were automatically fixed by GitHub. Instead, we save the names of the parent repos
               * in the map above, find the list of repositories under the authorized user, and iterate through that list.
               */
              parent = c.getOwner();
              parentRepoName = parent.getFullName();
              if (parent.isFork()) {
                  log.warn("Skipping {} because it's a fork already. Sending a PR to a fork is unsupported at the moment.",
                          parentRepoName);
              } else {
                  // fork the parent if not already forked
                  if (!parentReposForked.contains(parentRepoName)) {
                      // TODO: Need to close PR!
                      GHRepository fork = dockerfileGitHubUtil.getOrCreateFork(parent);
                      GHPullRequest pr = getPullRequestWithPullReqIdentifier(parent);
                      // Only reason we close the existing PR, delete fork and re-fork, is because there is no way to
                      // determine if the existing fork is compatible with it's parent.
                      if (pr != null) {
                          // close the pull-request since the fork is out of date
                          log.info("closing existing pr: {}", pr.getUrl());
                          try {
                              pr.close();
                          } catch (IOException e) {
                              log.info("Issues closing the pull request '{}'. Moving ahead...", pr.getUrl());
                          }
                      }
  
                      if (fork == null) {
                          log.info("Could not fork {}", parentRepoName);
                      } else {
                          // Add repos to pathToDockerfilesInParentRepo and imagesFoundInParentRepo only if we forked it successfully.
                          pathToDockerfilesInParentRepo.put(parentRepoName, c.getPath());
                          imagesFoundInParentRepo.put(parentRepoName, image);
                          parentReposForked.add(parentRepoName);
                      }
                  }
              }
          }
  
          log.info("Path to Dockerfiles in repo '{}': {}", parentRepoName, pathToDockerfilesInParentRepo);
          log.info("All images found in repo '{}': {}", parentRepoName, imagesFoundInParentRepo);
      }
focal_method.class_method_signature: All.forkRepositoriesFound(Multimap<String, String> pathToDockerfilesInParentRepo,
                                           Multimap<String, String> imagesFoundInParentRepo,
                                           PagedSearchIterable<GHContent> contentsWithImage,
                                           String image)
focal_method.full_signature: protected void forkRepositoriesFound(Multimap<String, String> pathToDockerfilesInParentRepo,
                                           Multimap<String, String> imagesFoundInParentRepo,
                                           PagedSearchIterable<GHContent> contentsWithImage,
                                           String image)
focal_method.identifier: forkRepositoriesFound
focal_method.invocations: info getTotalCount getOwner getFullName isFork warn contains getOrCreateFork getPullRequestWithPullReqIdentifier info getUrl close info getUrl info put getPath put add info info
focal_method.modifiers: protected
focal_method.parameters: (Multimap<String, String> pathToDockerfilesInParentRepo,
                                           Multimap<String, String> imagesFoundInParentRepo,
                                           PagedSearchIterable<GHContent> contentsWithImage,
                                           String image)
focal_method.return: void
focal_method.signature: void forkRepositoriesFound(Multimap<String, String> pathToDockerfilesInParentRepo,
                                           Multimap<String, String> imagesFoundInParentRepo,
                                           PagedSearchIterable<GHContent> contentsWithImage,
                                           String image)