-
Notifications
You must be signed in to change notification settings - Fork 45
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
Conversation
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. |
@@ -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 = |
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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")); |
There was a problem hiding this comment.
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")); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why set to null?
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did this move?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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! 😆
@afalko had missed addressing 2 comments. It should be good to merge if everything looks good. |
@jdoshi1 Itests passed locally. Coveralls is showing a light decrease between your commits, so it is red. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Local itests pass
Updates multiple Dockerfile present in the same repo at root level and under different folders.
This change does not support custom Dockerfile names.