-
Notifications
You must be signed in to change notification settings - Fork 48
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
Skip DFIU PRs for repos onboarded to Renovate Enterprise #1128
Changes from 9 commits
50df365
bbb42f8
62b1d6b
50725f7
5bd598b
10a819a
e1c9a83
ac16208
77c660f
43a3454
7fd7521
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
*.ipr | ||
*.iws | ||
*.iml | ||
*.DS_Store | ||
|
||
# Vim files | ||
*.swp | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
import com.salesforce.dockerfileimageupdate.model.*; | ||
import com.salesforce.dockerfileimageupdate.process.*; | ||
import net.sourceforge.argparse4j.inf.*; | ||
import org.json.JSONObject; | ||
import org.json.JSONTokener; | ||
import org.kohsuke.github.*; | ||
import org.slf4j.*; | ||
|
||
|
@@ -27,10 +29,16 @@ public void prepareToCreate(final Namespace ns, | |
pathToDockerfilesInParentRepo.get(currUserRepo).stream().findFirst(); | ||
if (forkWithContentPaths.isPresent()) { | ||
try { | ||
dockerfileGitHubUtil.changeDockerfiles(ns, | ||
pathToDockerfilesInParentRepo, | ||
forkWithContentPaths.get(), skippedRepos, | ||
gitForkBranch, rateLimiter); | ||
//If the repository has been onboarded to renovate enterprise, skip sending the DFIU PR | ||
if(ns.getBoolean(Constants.CHECK_FOR_RENOVATE) | ||
&& (isRenovateEnabled(Constants.RENOVATE_CONFIG_FILEPATHS, forkWithContentPaths.get()))) { | ||
log.info("Found a renovate configuration file in the repo %s. Skip sending DFIU PRs to this repository.", forkWithContentPaths.get().getParent().getFullName()); | ||
} else { | ||
dockerfileGitHubUtil.changeDockerfiles(ns, | ||
pathToDockerfilesInParentRepo, | ||
forkWithContentPaths.get(), skippedRepos, | ||
gitForkBranch, rateLimiter); | ||
} | ||
} catch (IOException | InterruptedException e) { | ||
log.error(String.format("Error changing Dockerfile for %s", forkWithContentPaths.get().getParent().getFullName()), e); | ||
exceptions.add((IOException) e); | ||
|
@@ -41,5 +49,33 @@ public void prepareToCreate(final Namespace ns, | |
} | ||
ResultsProcessor.processResults(skippedRepos, exceptions, log); | ||
} | ||
|
||
/** | ||
* Check if the repository is onboarded to Renovate. The signal we are looking for are | ||
* (1) The presence of a file where renovate configurations are stored in the repository | ||
* (2) Ensuring that the file does not have the key "enabled" set to "false" | ||
* @param filePaths the list that contains all the names of the files that we are searching for in the repo | ||
* @param fork A GitHubContentToProcess object that contains the fork repository that is under process | ||
* @return true if the file is found in the path specified and is not disabled, false otherwise | ||
*/ | ||
protected boolean isRenovateEnabled(List<String> filePaths, GitHubContentToProcess fork) throws IOException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can also extract reading Json from GHContent, that way we can reuse this method if needed |
||
for (String filePath : filePaths) { | ||
try { | ||
GHContent fileContent = fork.getParent().getFileContent(filePath); | ||
JSONObject json; | ||
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileContent.read()))) { | ||
JSONTokener tokener = new JSONTokener(bufferedReader); | ||
json = new JSONObject(tokener); | ||
//If the file has the key 'enabled' set to false, it indicates that while the repo has been onboarded to renovate, it has been disabled for some reason | ||
return json.optBoolean("enabled", true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the users need to delete this key altogether to get DFIU PRs back? true/false both mean we skip DFIU PRs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here are the scenarios
This key is usually used when a repo onboards to Renovate but then decides to off board by adding the key There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Renovate config file found and file does not have key enabled - Skip DFIU PR" Should we do this? the config file doesn't have this key, doesn't that mean it's enabled? the default is set to true https://docs.renovatebot.com/configuration-options/#enabled There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://github.com/stleary/JSON-java/blob/master/src/main/java/org/json/JSONObject.java#L1143 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or am I overlooking something? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, it does mean it is enabled. So we will skip DFIU because we expect to receive PRs from Renovate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, it will return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. This comment confused me a little, I thought we wanted to skip sending the PR in this case. |
||
} catch (IOException e) { | ||
log.debug("Exception while trying to close a resource. Exception: %s", e.getMessage()); | ||
} | ||
} catch (FileNotFoundException e) { | ||
log.debug("The file with name %s not found in the repository. Exception: %s", filePath, e.getMessage()); | ||
} | ||
} | ||
return false; | ||
} | ||
} | ||
|
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.
is there something we can't go with gson dependency that we already have https://github.com/avimanyum/dockerfile-image-update/blob/master/dockerfile-image-update/pom.xml#L116. or you are brining it in for easy of use?
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.
Yeah its just a cleaner and easier way to convert to Json object