Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update multiple Dockerfiles of the same repo #25

Merged
merged 8 commits into from
Jul 26, 2018

Conversation

jdoshi1
Copy link
Contributor

@jdoshi1 jdoshi1 commented Jul 18, 2018

Updates multiple Dockerfile present in the same repo at root level and under different folders.
This change does not support custom Dockerfile names.

@salesforce-cla
Copy link

Thanks for the contribution! Unfortunately we can't verify the commit author(s): Jinesh Doshi <j***@s***.com>. One possible solution is to add that email to your GitHub account. Alternatively you can change your commits to another email and force push the change. After getting your commits associated with your GitHub account, refresh the status of this Pull Request.

@coveralls
Copy link

coveralls commented Jul 18, 2018

Coverage Status

Coverage increased (+3.2%) to 68.26% when pulling 156a64a on update-multiple-dockerfiles into cc7da78 on master.

@jdoshi1 jdoshi1 requested a review from npwolf July 18, 2018 01:29
@@ -57,32 +61,43 @@ public void execute(final Namespace ns, final DockerfileGitHubUtil dockerfileGit
}

log.info("Retrieving all the forks...");
PagedIterable<GHRepository> repos = dockerfileGitHubUtil.getGHRepositories(parentToPath, currentUser);
PagedIterable<GHRepository> listOfcurrUserRepos =
Copy link
Collaborator

Choose a reason for hiding this comment

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

You want listOfCurrUserRepos to maintain camelCase

} catch (IOException e) {
exceptions.add(e);
}
}

if (exceptions.size() > 0) {
if (!exceptions.isEmpty()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Positive conditions are generally more readable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep agreed but in this case, isn't isEmpty() more readable/preferred than size() > 0?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'll leave it alone; not going to block things on nitpicks :)

log.info("There were {} errors with changing Dockerfiles.", exceptions.size());
throw exceptions.get(0);
}

if (!skippedRepos.isEmpty()) {
log.info("List of repos skipped: {}", skippedRepos.toArray());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does slf4j need the toArray?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope. Good catch, will fix it.

Iterator<String> pathToDockerfileInParentRepoIterator = pathToDockerfilesInParentRepo.get(parentName).iterator();
Iterator<String> imagesFoundInParentRepoIterator = imagesFoundInParentRepo.get(parentName).iterator();

while (pathToDockerfileInParentRepoIterator.hasNext() && imagesFoundInParentRepoIterator.hasNext()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are pathToDockerfileInParentRepoIterator and imagesFoundInParentRepoIterator supposed to be the same number of elements?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes they store the same number of elements - All.java#115 and All.java#116.

Copy link
Collaborator

@afalko afalko Jul 18, 2018

Choose a reason for hiding this comment

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

Why not iterate on only one of them then? You can make the objects immutable after they are created, to make sure no one break this property later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm.. Now iterating over only one of them but I think ideally it should be a class that stores repoName with pathToDockerfiles and corresponding images in those Dockerfiles.


if (isContentModified) {
dockerfileGitHubUtil.createPullReq(parent, branch, forkedRepo, ns.get("m"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

You might want to create identifying constants for things getting checked in ns.get. E.g. ns.get(Constants.GIT_REPO)

GHContent content = dockerfileGitHubUtil.tryRetrievingContent(forkedRepo, pathToDockerfile, branch);
log.info("content: {}", content);
if (content != null) {
dockerfileGitHubUtil.modifyOnGithub(content, branch, ns.get(Constants.IMG), ns.get(Constants.TAG), ns.get("c"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Constant for "c" as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will create a constant for it 👍

@@ -68,10 +73,10 @@ public GHRepository getRepo(String repoName) throws IOException {
throw new IOException("Invalid image name.");
}
search.q("\"FROM " + query + "\"");
log.debug("Searching for {}", query);
log.info("Searching for {}", query);
Copy link
Collaborator

Choose a reason for hiding this comment

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

change change this to info?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops.. I forgot to switch it back to debug.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe there is a --verbose/--debug flag that auto-gives you more output.

@@ -488,7 +548,7 @@ public void testCreatePullReq_Delete() throws Exception {
when(gitHubUtil.createPullReq(any(), anyString(), any(), anyString(), eq(Constants.PULL_REQ_ID))).thenReturn(1);
doCallRealMethod().when(gitHubUtil).safeDeleteRepo(forkRepo);
dockerfileGitHubUtil = new DockerfileGitHubUtil(gitHubUtil);
dockerfileGitHubUtil.createPullReq(new GHRepository(), "branch", forkRepo, "Automatic Dockerfile Image Updater");
dockerfileGitHubUtil.createPullReq(new GHRepository(), "branch", forkRepo, null);
Copy link
Collaborator

Choose a reason for hiding this comment

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

why set to null?

Copy link
Contributor Author

@jdoshi1 jdoshi1 Jul 18, 2018

Choose a reason for hiding this comment

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

Just to test the null scenario. We have a test that already provides a non-null message.

if (pr != null) {
// close the pull-request since the fork is out of date
log.info("closing existing pr: {}", pr.getUrl());
pr.close();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be better to close this in a try-finally?

Copy link
Contributor Author

@jdoshi1 jdoshi1 Jul 18, 2018

Choose a reason for hiding this comment

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

Good point. I think I can use try catch to log about not able to close PR..and move ahead.

for (String pathToDockerfile : pathToDockerfilesInParentRepo.get(parentName)) {
GHContent content = dockerfileGitHubUtil.tryRetrievingContent(forkedRepo, pathToDockerfile, branch);
log.info("content: {}", content);
if (content != null) {
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 can flip this if else to make condition positive

@@ -71,7 +80,7 @@ public GHRepository getRepo(String repoName) throws IOException {
log.debug("Searching for {}", query);
PagedSearchIterable<GHContent> files = search.list();
int totalCount = files.getTotalCount();
log.debug("Number of files found for {}: {}", query, totalCount);
log.info("Number of files found for {}:{}", query, totalCount);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Forgot to flip this back to debug?

} else {
log.info("Forking {}...", parent.getFullName());
Copy link
Contributor

Choose a reason for hiding this comment

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

Did this move?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Uh oops... /Runs away

Thanks! 😆

@jdoshi1
Copy link
Contributor Author

jdoshi1 commented Jul 25, 2018

@afalko, Seems like integration tests are broken. Created a new issue to fix it - #29

@jdoshi1
Copy link
Contributor Author

jdoshi1 commented Jul 26, 2018

@afalko had missed addressing 2 comments. It should be good to merge if everything looks good.

@afalko
Copy link
Collaborator

afalko commented Jul 26, 2018

@jdoshi1 Itests passed locally. Coveralls is showing a light decrease between your commits, so it is red.

Copy link
Collaborator

@afalko afalko left a comment

Choose a reason for hiding this comment

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

Local itests pass

@afalko afalko merged commit 5304960 into master Jul 26, 2018
@afalko afalko deleted the update-multiple-dockerfiles branch July 26, 2018 22:25
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.

None yet

4 participants