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

Don't close forks, don't close PRs for child/parent commands #142

Merged
merged 24 commits into from
May 18, 2020

Conversation

justinharringa
Copy link
Contributor

@justinharringa justinharringa commented Apr 17, 2020

It has proven wasteful and confusing to remove forks.

This changes the parent and child commands to use branches with a name based on the new image-tag combination.

This will have the following benefits:

  • Stop closing forks and creating new ones
    • This will keep PRs for other image-tag combos open
  • Use filename:Dockerfile instead of language:Dockerfile which picks up more results
  • Create a branch specific to the image-tag combo we're updating to (which provides more context for the PR)
    • A benefit here is that it is also easier to locate DFIU PRs without requiring the usage of a specific PR body (PULL_REQ_ID will no longer be necessary and we can provide more context in the PR body).

Parent and Child are covered by #72 - All will keep the current strategy.

@justinharringa justinharringa requested a review from afalko as a code owner April 17, 2020 04:20
@codecov
Copy link

codecov bot commented Apr 17, 2020

Codecov Report

Merging #142 into master will increase coverage by 0.46%.
The diff coverage is 62.89%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #142      +/-   ##
============================================
+ Coverage     68.82%   69.28%   +0.46%     
- Complexity      140      176      +36     
============================================
  Files             7       13       +6     
  Lines           603      687      +84     
  Branches         93       99       +6     
============================================
+ Hits            415      476      +61     
- Misses          168      191      +23     
  Partials         20       20              
Impacted Files Coverage Δ Complexity Δ
...ce/dockerfileimageupdate/subcommands/impl/All.java 57.85% <33.33%> (-3.26%) 16.00 <1.00> (-1.00)
...dockerfileimageupdate/subcommands/impl/Parent.java 52.83% <34.48%> (-13.84%) 8.00 <5.00> (-12.00)
...dockerfileimageupdate/storage/GitHubJsonStore.java 37.50% <37.50%> (ø) 5.00 <5.00> (?)
...sforce/dockerfileimageupdate/utils/GitHubUtil.java 69.51% <54.54%> (-0.86%) 17.00 <1.00> (ø)
...kerfileimageupdate/utils/DockerfileGitHubUtil.java 77.77% <64.28%> (+8.59%) 39.00 <11.00> (ø)
.../dockerfileimageupdate/utils/ResultsProcessor.java 83.33% <83.33%> (ø) 3.00 <3.00> (?)
...force/dockerfileimageupdate/repository/GitHub.java 85.71% <85.71%> (ø) 7.00 <7.00> (?)
...rce/dockerfileimageupdate/model/GitForkBranch.java 88.88% <88.88%> (ø) 16.00 <16.00> (?)
...leimageupdate/process/GitHubPullRequestSender.java 88.88% <88.88%> (ø) 13.00 <13.00> (?)
.../salesforce/dockerfileimageupdate/CommandLine.java 53.26% <100.00%> (ø) 11.00 <1.00> (ø)
... and 8 more

@justinharringa
Copy link
Contributor Author

Note: There's likely a need for fork cleanup that should either be a part of this process or separate (to reduce specific time of this process). For example, the original parent repo could be deleted or moved which would put the fork in the bot org in a weird state (the deletion can make the fork in the bot org a non-fork).

It has proven wasteful and confusing to remove forks. Start marching
towards using branches within a fork.

Refactor out duplication to repository/GitHub class
This yields more results for other Dockerfile names
* Added slight logging improvement after PR created
* Shift away from deprecated JsonParser methods
This is a steel thread approach. Needs a bit more refactoring and tests.
@justinharringa justinharringa linked an issue May 16, 2020 that may be closed by this pull request
* Also improve unreachable code block in
GitForkBranch.isSameBranchOrHasImageNamePrefis(branchName)
* JSON processing can move to specific GitHubJsonStore (theoretically we
could support more stores and more than just GitHub)
* DockerfileGitHubUtil could potentially start migrating to an
interface to provide a dry run mode (but it has far too many
responsibilities at the moment)
* Pull generic algorithm out of Parent into GitHubPullRequestSender
return false;
}

private String getBranchWithoutTag(String branchName) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we documenting branch name conventions anywhere?

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, I kinda put it up top but this should be nearer to the function. Adding.

}
}
String jsonOutput = getAndModifyJsonString(json, img, tag);
content.update(jsonOutput,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doe this include retries?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nah, it doesn't currently. I haven't observed many issues where retries set this in a bad spot. That is something that could be considered for sure. I would have a similar concern about determining when to retry to help reduce rate limit pressure.

}
// TODO: This may loop forever in the event of constant -1 pullRequestExitCodes...
Copy link
Collaborator

Choose a reason for hiding this comment

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

Give it a configurable timeout?

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, right now focusing on solidifying the move to stop forking and branch instead. This needs to be done at some point or another though.

if (contentsWithImage.getTotalCount() > 0) {
break;
} else {
Thread.sleep(1000);
Copy link
Collaborator

Choose a reason for hiding this comment

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

TimeUnit.SECONDS.sleep(1);

Copy link
Collaborator

Choose a reason for hiding this comment

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

Change still not made?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bah... There were a bunch... Corrected that crust

"provided has access to deleting repositories.");
if (!repo.queryPullRequests().state(GHIssueState.OPEN).list().iterator().hasNext()) {
try {
repo.delete();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Need to retry on failure a few times?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In which scenario would you expect that? Are you thinking of a network blip or momentary server unavailability? A potential issue with that would be to potentially put pressure on GitHub rate limits.

One thing that I'm considering to open up as an issue is to avoid forking at all if a repo doesn't need a change. We should be able to detect that off of the primary repo and then just skip forking it at the beginning.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeh, network blips or errors

Also remove invalid test for Child subcommand
@justinharringa
Copy link
Contributor Author

This PR already involves a fairly significant amount of change. Talked a bit with @afalko. Will let parent and child get these new changes and then all will kind of operate as it did before (though not a complete fork delete). Next PR will involve completely aligning all with parent.

@justinharringa justinharringa changed the title Don't close forks Don't close forks, don't close PRs for child/parent commands May 18, 2020
}
}
private Optional<GHPullRequest> commentAndCloseExistingPullRequestsForBranch(GHRepository parentRepo, GitForkBranch gitForkBranch) {
Optional<GHPullRequest> specifiedBranchPullRequest = dockerfileGitHubUtil.getPullRequestForImageBranch(parentRepo, gitForkBranch);
// GHPullRequest pullRequest = specifiedBranchPullRequest.get();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Need to keep this commented?

if (contentsWithImage.getTotalCount() > 0) {
break;
} else {
Thread.sleep(1000);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Change still not made?

@afalko afalko merged commit a542537 into master May 18, 2020
@afalko afalko deleted the dont-close-forks branch May 18, 2020 05:43
@justinharringa justinharringa added the improvement New features and improvements label Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement New features and improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants