From ec098727615ecce8bb9cd6f724d978b5ab8d645a Mon Sep 17 00:00:00 2001 From: Joshua Liebowitz Date: Fri, 1 Jun 2018 10:14:53 -0700 Subject: [PATCH] Specifically handle situation where there's nothing to commit but we tried anyway (#952) * Specify exactly what files should be added to a commit - Fixes #847 - WIP * Specifically handle situation where there's nothing to commit but we tried anyway * Delete cloudbuild.yaml * Delete quickstart.sh --- app/features/build_runner/build_runner.rb | 2 +- app/services/project_service.rb | 4 ++-- app/shared/models/git_repo.rb | 22 ++++++++++++++++++---- app/shared/models/notification.rb | 1 + 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/app/features/build_runner/build_runner.rb b/app/features/build_runner/build_runner.rb index f1406ca7..ec265033 100644 --- a/app/features/build_runner/build_runner.rb +++ b/app/features/build_runner/build_runner.rb @@ -403,7 +403,7 @@ def prepare_build_object(trigger:) private def save_build_status_locally! - # Create or update the local build file in the config directory + # Create local build file in the config directory Services.build_service.add_build!( project: project, build: current_build diff --git a/app/services/project_service.rb b/app/services/project_service.rb index 48b5ee08..cd6aa044 100644 --- a/app/services/project_service.rb +++ b/app/services/project_service.rb @@ -103,8 +103,8 @@ def delete_project!(project: nil) end # Not sure if this must be here or not, but we can open a discussion on this. - def commit_repo_changes!(message: nil, file_to_commit: nil) - Services.configuration_git_repo.commit_changes!(commit_message: message, file_to_commit: file_to_commit) + def commit_repo_changes!(message: nil, files_to_commit: []) + Services.configuration_git_repo.commit_changes!(commit_message: message, files_to_commit: files_to_commit) end def push_configuration_repo_changes! diff --git a/app/shared/models/git_repo.rb b/app/shared/models/git_repo.rb index 078c47bb..41ea581d 100644 --- a/app/shared/models/git_repo.rb +++ b/app/shared/models/git_repo.rb @@ -197,6 +197,17 @@ def handle_exception(ex, console_message: nil, exception_context: {}) details: user_unfriendly_message ) + # Sometimes a repo is told to do something like commit when nothing is added to the change set + # It's weird, and indicative of a race condition somewhere, so let's log it and move on + elsif user_unfriendly_message.include?("Your branch is up to date with") + priority = Notification::PRIORITIES[:warn] + notification_service.create_notification!( + priority: priority, + name: "Up to date repo error", + message: "Unable to perform action, the repo is already up to date #{git_config.git_url}", + details: user_unfriendly_message + ) + # Merge conflict, maybe somebody force-pushed something? elsif user_unfriendly_message.include?("Merge conflict") priority = Notification::PRIORITIES[:urgent] @@ -527,17 +538,20 @@ def reset_hard!(use_global_git_mutex: true) end # This method commits and pushes all changes - # if `file_to_commit` is `nil`, all files will be added + # if `files_to_commit` is empty or nil, all files will be added # TODO: this method isn't actually tested yet - def commit_changes!(commit_message: nil, push_after_commit: true, file_to_commit: nil, repo_auth: self.repo_auth) + def commit_changes!(commit_message: nil, push_after_commit: true, files_to_commit: [], repo_auth: self.repo_auth) git_action_with_queue do logger.debug("Starting commit_changes! #{git_config.git_url} for #{repo_auth.username}") - raise "file_to_commit not yet implemented" if file_to_commit commit_message ||= "Automatic commit by fastlane.ci" setup_author(full_name: repo_auth.full_name, username: repo_auth.username) - git.add(all: true) # TODO: for now we only add all files + if files_to_commit.nil? || files_to_commit.empty? + git.add(all: true) + else + git.add(files_to_commit) + end changed = git.status.changed added = git.status.added deleted = git.status.deleted diff --git a/app/shared/models/notification.rb b/app/shared/models/notification.rb index f5bb20a3..27ab6abb 100644 --- a/app/shared/models/notification.rb +++ b/app/shared/models/notification.rb @@ -7,6 +7,7 @@ class Notification # # @return [Hash] PRIORITIES = { + warn: "warn", urgent: "urgent", normal: "normal", success: "success"