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

Skip DFIU PRs for repos onboarded to Renovate Enterprise #1128

Merged
merged 11 commits into from
Feb 8, 2024
Merged

Skip DFIU PRs for repos onboarded to Renovate Enterprise #1128

merged 11 commits into from
Feb 8, 2024

Conversation

avimanyum
Copy link
Contributor

@avimanyum avimanyum commented Feb 7, 2024

Renovate enterprise is another solution that can be used to receive remediation PRs. This change disables sending DFIU PRs for those repositories that have been onboarded to Renovate Enterprise.

@avimanyum avimanyum added the feature New features and improvements label Feb 7, 2024
@github-actions github-actions bot added chore Chores such as updates to CI processes and other maintenance tests Improvements / maintenance to tests labels Feb 7, 2024
Copy link

codecov bot commented Feb 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (a21d7b6) 85.69% compared to head (7fd7521) 85.91%.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #1128      +/-   ##
============================================
+ Coverage     85.69%   85.91%   +0.22%     
- Complexity      385      390       +5     
============================================
  Files            27       27              
  Lines          1272     1292      +20     
  Branches        165      167       +2     
============================================
+ Hits           1090     1110      +20     
  Misses          146      146              
  Partials         36       36              
Files Coverage Δ
.../salesforce/dockerfileimageupdate/CommandLine.java 76.47% <100.00%> (+0.71%) ⬆️
...esforce/dockerfileimageupdate/utils/Constants.java 100.00% <100.00%> (ø)
...orce/dockerfileimageupdate/utils/PullRequests.java 100.00% <100.00%> (ø)

@avimanyum avimanyum removed chore Chores such as updates to CI processes and other maintenance tests Improvements / maintenance to tests labels Feb 8, 2024
@github-actions github-actions bot added chore Chores such as updates to CI processes and other maintenance tests Improvements / maintenance to tests labels Feb 8, 2024
@@ -51,4 +51,6 @@ private Constants() {
public static final Duration DEFAULT_TOKEN_ADDING_RATE = Duration.ofMinutes(DEFAULT_CONSUMING_TOKEN_RATE);
public static final String FILENAME_DOCKERFILE = "dockerfile";
public static final String FILENAME_DOCKER_COMPOSE = "docker-compose";
public static final String CHECK_FOR_RENOVATE = "checkforrenovate";
public static final String RENOVATE_CONFIG_FILEPATH = "renovate.json";
Copy link
Contributor

Choose a reason for hiding this comment

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

While we will using renovate.json internally there are actually 9 different potential renovate configuration files, see https://docs.renovatebot.com/configuration-options/ . We might want to check for all of these paths.

Comment on lines 64 to 65
InputStream is = fileContent.read();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these should be closed after use.

Comment on lines 69 to 71
if (json.has("enabled") && json.getBoolean("enabled") == false) {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can replace this if statement with

return json.optBoolean("enabled", true)

If the file exists and enabled is not set it is assumed to be true, otherwise return the value of the enabled field.

Comment on lines 74 to 76
return false;
}
return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can remove the return inside of the catch and change the last return to return false. If the file isn't found should be only way the last return is executed so we should assume that renovate is not enabled.

@@ -65,6 +65,10 @@ static ArgumentParser getArgumentParser() {
ArgumentParsers.newFor("dockerfile-image-update").addHelp(true).build()
.description("Image Updates through Pull Request Automator");

parser.addArgument("-re", "--" + CHECK_FOR_RENOVATE)
Copy link
Contributor

Choose a reason for hiding this comment

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

What about -R instead for the short opt?

Comment on lines 69 to 70
is.close();
bufferedReader.close();
Copy link
Contributor

Choose a reason for hiding this comment

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

You might want to do this in a try-with-resources statement, see https://stackoverflow.com/a/56151320 . If is.close throws an exception then the close on buffered reader won't happen.

Comment on lines 66 to 67
try (InputStream is = fileContent.read();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the input stream is closed when the buffered reader is closed so I think you can inline fileContent.read() in the InputStreamReader constructor.

cjneasbi
cjneasbi previously approved these changes Feb 8, 2024
@@ -69,6 +69,11 @@


<dependencies>
<dependency>
<groupId>org.json</groupId>
Copy link
Member

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?

Copy link
Contributor Author

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

* @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 {
Copy link
Member

Choose a reason for hiding this comment

The 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
private JSONObject readJsonFromContent(GHContent content) throws IOException {
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(content.read()))) {
JSONTokener tokener = new JSONTokener(bufferedReader);
return new JSONObject(tokener);
}
}

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);
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

@avimanyum avimanyum Feb 8, 2024

Choose a reason for hiding this comment

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

Here are the scenarios

  • Renovate config file not found - Send DFIU PR
  • Renovate config file found and file does not have key enabled - Skip DFIU PR
  • Renovate config file found and file has the key enabled - return the boolean value for that key. If set to true, skip DFIU PR, if set to false, send DFIU PR

This key is usually used when a repo onboards to Renovate but then decides to off board by adding the key enabled: false.

Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Member

@jeetchoudhary jeetchoudhary Feb 8, 2024

Choose a reason for hiding this comment

The 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
The method will return true if the file doesn't have the key enabled and we'll skip the PR

Copy link
Member

Choose a reason for hiding this comment

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

or am I overlooking something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Yes, it does mean it is enabled. So we will skip DFIU because we expect to receive PRs from Renovate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The method will return true if the file doesn't have the key enabled and we'll skip the PR

Yes, it will return true. We will assume that Renovate is enabled

Copy link
Member

Choose a reason for hiding this comment

The 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.
//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.

@jeetchoudhary jeetchoudhary merged commit e604ebb into salesforce:main Feb 8, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Chores such as updates to CI processes and other maintenance feature New features and improvements tests Improvements / maintenance to tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants