def resolve_project options
@config = load_config(options[:project_path])
ensure_config_is_up_to_date!
if has_project_slug?
quit_because_of("You already have a project slug refering to an existing project. Please remove this project slug from your configuration file.")
end
project_name = @config.project_name
project_branch = @config.project_branch || 'master'
projects = request("#{connection.api_path_for('projects')}")
candidates = projects.select do |project|
project['name'] == project_name && project['origin'] == 'offline' && project['branch'] == project_branch
end
criterias = "name `#{ project_name }` and branch `#{ project_branch }`"
if candidates.size == 0
quit_because_of("You have no off-line project matching #{ criterias }.")
elsif candidates.size > 1
quit_because_of("You have more than one off-line project matching #{ criterias }.")
end
project = candidates.first
project_slug = project['slug']
notify "Project slug is `#{ project_slug }`.", :green
if @config.writable?
@config.store_value!(:project_slug, project_slug, "This unique project slug has been set by `gemnasium resolve`.")
notify "Your configuration file has been updated."
else
notify "Configuration file cannot be updated. Please edit the file and update the project slug manually."
end
rescue => exception
quit_because_of(exception.message)
end