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

Refactor for clarity and consistency #154

Merged
merged 6 commits into from
May 24, 2019

Conversation

bitwiseman
Copy link
Contributor

@bitwiseman bitwiseman commented May 23, 2019

After #152 and #153, I decided to refactor this huge method.

This is almost pure refactor, but not quite because of minor bugs I found while refactoring.
I will call out the non refactor changes

It will be useful to view the diffs for each commit and also to set your diff settings to "Hide whitespace differences".

Depends on #153.

revisionActions
);
} else {
listener.getLogger().format("No automatic build triggered for %s%n", rawName);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed the wording here from "No automatic builds for ...".

* @param lastSeenRevision the last seen revision
* @return {@code true} if the head should be automatically built when discovered / modified.
*/
private boolean isAutomaticBuild(@NonNull SCMHead head,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved this method into the observer class. There is not advantage to it being on the project instance.

SCMRevision scmLastSeenRevision = getLastSeenRevision(project, scmLastBuiltRevision);
if (!revision.equals(scmLastBuiltRevision)) {

if (isChangesDetected(revision, project, scmLastBuiltRevision)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of running two almost identical blocks, the checks are handled by isChangesDetected and then the actual same code path is executed.

} else {
// get the previous revision
SCMRevision scmLastBuiltRevision = _factory.getRevision(project);

if (isChangesDetected(revision, project, scmLastBuiltRevision)) {
listener.getLogger()
.format("Changes detected: %s (%s → %s)%n", rawName, scmLastBuiltRevision, revision);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved this up to make it extra clear that is doesn't use scmLastSeenRevision .

try {
branch.setActions(source.fetchActions(head, event, listener));
headActionsFetched = true;
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 only reason headActionsFetched existed was so that we could try an alternative later.
Go ahead and do it in place.

if (isAutomaticBuild(head, revision, scmLastBuiltRevision, scmLastSeenRevision)) {
Action[] revisionActions = getRevisionActions(revision, rawName);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We only need revision actions when we're ready to schedule a build.

}
try {
_factory.setLastSeenRevisionHash(project, revision);
_factory.setLastSeenRevisionHash(project, scmLastBuiltRevision);
Copy link
Member

Choose a reason for hiding this comment

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

A getter that mutates data isn't very intuitive at first glance. It's a private method, so not a big deal. But maybe just call it lastSeenRevision(...) for a tiny bit ore clarity?

@bitwiseman bitwiseman merged commit db508c0 into jenkinsci:master May 24, 2019
@bitwiseman bitwiseman deleted the refactor-1 branch May 24, 2019 21:23
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.

2 participants