Skip to content

Commit 3cad143

Browse files
author
Honza Dvorsky
committed
more configs stuff
1 parent e091eb0 commit 3cad143

File tree

6 files changed

+196
-109
lines changed

6 files changed

+196
-109
lines changed

bin/xcskarel

+16-15
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,31 @@ class XCSKarelApplication
3636
# Managing local xcsconfig folder
3737

3838
command :'config list' do |c|
39-
c.syntax = 'xcskarel config [options]'
39+
c.syntax = 'xcskarel config list [options]'
4040
c.description = 'Lists the Xcode Bot configurations found in this folder'
41+
c.example 'lists all configurations stored in this folder', 'xcskarel config list'
4142
c.action do |args, options|
4243
config_folder = XCSKarel::XCSFile.get_config_folder
4344
return unless config_folder
44-
configs = XCSKarel::XCSFile.load_configs(config_folder)
45-
if configs.count == 0
46-
XCSKarel.log.info "Found no existing configs in #{config_folder}".yellow
47-
else
48-
out = "\n" + configs.map { |c| "#{File.basename(c.path)}".yellow + " - from " + "\"#{c.name}\"".yellow + ", created at #{c.created}" }.join("\n")
49-
XCSKarel.log.info "Found #{configs.count} configs in \"#{config_folder}\":"
50-
XCSKarel.log.info out
51-
end
45+
XCSKarel::Application.list_configs(config_folder)
46+
end
47+
end
48+
49+
command :'config show' do |c|
50+
c.syntax = 'xcskarel config show [options]'
51+
c.description = 'Opens the selected config for editing'
52+
c.example 'opens a config of choice', 'xcskarel config show'
53+
c.action do |args, options|
54+
config_folder = XCSKarel::XCSFile.get_config_folder
55+
return unless config_folder
56+
XCSKarel::Application.show_config(config_folder)
5257
end
5358
end
5459

5560
command :'config new' do |c|
5661
c.syntax = 'xcskarel config new [options]'
5762
c.description = 'Starts the interactive process of creating a new config from an existing Bot'
63+
c.example 'starts creating new config from server at 192.168.1.64', 'xcskarel config new --host 192.168.1.64'
5864
add_xcs_options(c)
5965
c.action do |args, options|
6066

@@ -67,12 +73,7 @@ class XCSKarelApplication
6773
return unless config_folder
6874

6975
# dump the bot into that config folder under a random name
70-
new_config_path = XCSKarel::XCSFile.new_config_name(config_folder)
71-
new_config = XCSKarel::Config.new(bot, server.api_version, new_config_path)
72-
new_config.save
73-
74-
XCSKarel.log.info "Saved Bot \"#{new_config.name}\" configuration to #{new_config_path}.".green
75-
system "open \"#{new_config_path}\""
76+
XCSKarel::Application.save_bot(config_folder, bot, server.api_version)
7677
end
7778
end
7879

lib/xcskarel/application.rb

+39
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,44 @@ def self.choose_bot(server)
99
XCSKarel.log.info "Chose Bot \"#{bot['name']}\""
1010
return bot
1111
end
12+
13+
def self.save_bot(config_folder, bot, api_version)
14+
rand_name = XCSKarel::XCSFile.random_name
15+
config_name = ask("Config name (hit Enter to accept generated name \"" + "#{rand_name}".yellow + "\"): ")
16+
config_name = rand_name if config_name.length == 0
17+
18+
# preprocess the config name first
19+
require 'uri'
20+
config_name = URI::escape(config_name.gsub(" ", "_"))
21+
22+
real_name = "botconfig_#{config_name}.json"
23+
new_config_path = XCSKarel::XCSFile.new_config_name(config_folder, real_name)
24+
new_config = XCSKarel::Config.new(bot, api_version, new_config_path)
25+
new_config.save
26+
27+
XCSKarel.log.info "Saved Bot \"#{new_config.name}\" configuration to #{new_config_path}. Check this into your repository.".green
28+
system "open \"#{new_config_path}\""
29+
end
30+
31+
def self.list_configs(config_folder)
32+
configs = XCSKarel::XCSFile.load_configs(config_folder)
33+
if configs.count == 0
34+
XCSKarel.log.info "Found no existing configs in #{config_folder}".yellow
35+
else
36+
out = "\n" + configs.map { |c| "\"#{c.name}\"".yellow + " [#{File.basename(c.path)}]".yellow + " - from Bot " + "#{c.original_bot_name}".yellow }.join("\n")
37+
XCSKarel.log.info "Found #{configs.count} configs in \"#{config_folder}\":"
38+
XCSKarel.log.info out
39+
end
40+
end
41+
42+
def self.show_config(config_folder)
43+
configs = XCSKarel::XCSFile.load_configs(config_folder)
44+
config_names = configs.map { |c| "Config " + "#{c.name}".yellow + " from Bot " + "#{c.original_bot_name}".yellow }
45+
puts "Which config?"
46+
choice = choose(*config_names)
47+
config = configs[config_names.index(choice)]
48+
XCSKarel.log.info "Editing config \"#{config.name}\""
49+
system "open \"#{config.path}\""
50+
end
1251
end
1352
end

lib/xcskarel/config.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ def initialize(json, api_version, path)
1111
end
1212

1313
def name
14-
@json['name'] || config_json['original_bot_name']
14+
(config_json['name'] || File.basename(@path).split('.').first).gsub("botconfig_", "")
1515
end
1616

17-
def created
18-
config_json['time_generated']
17+
def original_bot_name
18+
@json['name'] || config_json['original_bot_name']
1919
end
2020

2121
def config_json
22-
@json['xcsconfig']
22+
@json['xcsconfig'] || {}
2323
end
2424

2525
def key_paths_for_persistance
@@ -42,8 +42,8 @@ def json_for_persistence
4242
filtered["xcsconfig"] = {
4343
format_version: format_version,
4444
app_version: XCSKarel::VERSION,
45-
time_generated: Time.new.to_s,
4645
original_bot_name: @json['name'],
46+
name: name,
4747
api_version: @api_version
4848
}
4949
end
@@ -72,7 +72,7 @@ def validate_loaded
7272

7373
def to_file(file_path)
7474
abs_path = File.absolute_path(file_path)
75-
raise "File #{abs_path} already exists." if File.exist?(abs_path)
75+
raise "File #{abs_path} already exists. Choose a different name.".red if File.exist?(abs_path)
7676
FileUtils.mkdir_p(File.dirname(abs_path))
7777
File.open(abs_path, 'w') do |f|
7878
f.puts JSON.pretty_generate(json_for_persistence) + "\n"

lib/xcskarel/xcsfile.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,12 @@ def self.load_configs(folder)
5959

6060
def self.random_name
6161
require 'securerandom'
62-
"botconfig_#{SecureRandom.hex(6)}.json"
62+
"#{SecureRandom.hex(6)}"
6363
end
6464

65-
def self.new_config_name(folder)
66-
File.join(folder, self.random_name)
65+
def self.new_config_name(folder, name)
66+
name = name.split('.').first + ".json"
67+
File.join(folder, name)
6768
end
6869

6970
end

xcsconfig/botconfig_ad62fd9f0328.json

-85
This file was deleted.

xcsconfig/botconfig_test_bot.json

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
{
2+
"configuration": {
3+
"builtFromClean": 2,
4+
"periodicScheduleInterval": 2,
5+
"codeCoveragePreference": 2,
6+
"performsTestAction": true,
7+
"triggers": [
8+
{
9+
"phase": 1,
10+
"scriptBody": "cd XCSTutorialProject1\nfastlane prebuild",
11+
"type": 1,
12+
"name": "Run Script"
13+
},
14+
{
15+
"phase": 2,
16+
"scriptBody": "cd XCSTutorialProject1\nfastlane postbuild",
17+
"type": 1,
18+
"name": "Run Script",
19+
"conditions": {
20+
"status": 2,
21+
"onWarnings": true,
22+
"onBuildErrors": true,
23+
"onInternalErrors": true,
24+
"onAnalyzerWarnings": true,
25+
"onFailingTests": true,
26+
"onSuccess": true
27+
}
28+
},
29+
{
30+
"phase": 2,
31+
"scriptBody": "",
32+
"type": 2,
33+
"name": "Send Email Notification",
34+
"conditions": {
35+
"status": 2,
36+
"onWarnings": true,
37+
"onBuildErrors": true,
38+
"onInternalErrors": true,
39+
"onAnalyzerWarnings": true,
40+
"onFailingTests": true,
41+
"onSuccess": false
42+
},
43+
"emailConfiguration": {
44+
"includeCommitMessages": true,
45+
"additionalRecipients": [
46+
47+
],
48+
"emailCommitters": true,
49+
"scmOptions": {
50+
"43ABCED2B571DB1C2336479F8D53EBF39F6D1B5D": true
51+
},
52+
"includeIssueDetails": true
53+
}
54+
}
55+
],
56+
"performsAnalyzeAction": true,
57+
"schemeName": "XCSTutorialProject1",
58+
"exportsProductFromArchive": true,
59+
"testingDeviceIDs": [
60+
61+
],
62+
"deviceSpecification": {
63+
"filters": [
64+
{
65+
"platform": {
66+
"_id": "448946985304230369392c2e6b00226c",
67+
"displayName": "iOS",
68+
"_rev": "3-c50bae22b98a80c3919c7b5f1e7400a8",
69+
"simulatorIdentifier": "com.apple.platform.iphonesimulator",
70+
"identifier": "com.apple.platform.iphoneos",
71+
"buildNumber": "13A4325c",
72+
"version": "9.0"
73+
},
74+
"filterType": 3,
75+
"architectureType": 0
76+
}
77+
],
78+
"deviceIdentifiers": [
79+
"448946985304230369392c2e6b00731e",
80+
"448946985304230369392c2e6b008ae1"
81+
]
82+
},
83+
"weeklyScheduleDay": 0,
84+
"minutesAfterHourToIntegrate": 30,
85+
"scheduleType": 1,
86+
"hourOfIntegration": 19,
87+
"performsArchiveAction": true,
88+
"testingDestinationType": 0,
89+
"sourceControlBlueprint": {
90+
"DVTSourceControlWorkspaceBlueprintLocationsKey": {
91+
"43ABCED2B571DB1C2336479F8D53EBF39F6D1B5D": {
92+
"DVTSourceControlBranchIdentifierKey": "step4-sigh",
93+
"DVTSourceControlBranchOptionsKey": 4,
94+
"DVTSourceControlWorkspaceBlueprintLocationTypeKey": "DVTSourceControlBranch"
95+
}
96+
},
97+
"DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey": "43ABCED2B571DB1C2336479F8D53EBF39F6D1B5D",
98+
"DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey": {
99+
},
100+
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryAuthenticationStrategiesKey": {
101+
"43ABCED2B571DB1C2336479F8D53EBF39F6D1B5D": {
102+
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryAuthenticationTypeKey": "DVTSourceControlAuthenticationStrategy"
103+
}
104+
},
105+
"DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey": {
106+
"43ABCED2B571DB1C2336479F8D53EBF39F6D1B5D": 0
107+
},
108+
"DVTSourceControlWorkspaceBlueprintIdentifierKey": "7DFE7BE7-36F2-495F-93A8-833D9FC78BFB",
109+
"DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey": {
110+
"43ABCED2B571DB1C2336479F8D53EBF39F6D1B5D": "XCSTutorialProject1/"
111+
},
112+
"DVTSourceControlWorkspaceBlueprintNameKey": "XCSTutorialProject1",
113+
"DVTSourceControlWorkspaceBlueprintVersion": 204,
114+
"DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey": "XCSTutorialProject1.xcworkspace",
115+
"DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey": [
116+
{
117+
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey": "github.com:czechboy0/XCSTutorialProject1.git",
118+
"DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey": "com.apple.dt.Xcode.sourcecontrol.Git",
119+
"DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey": "43ABCED2B571DB1C2336479F8D53EBF39F6D1B5D"
120+
}
121+
]
122+
}
123+
},
124+
"xcsconfig": {
125+
"format_version": 1,
126+
"app_version": "0.7.1",
127+
"original_bot_name": "I am a Bot and I know it",
128+
"name": "test_bot",
129+
"api_version": "6"
130+
}
131+
}

0 commit comments

Comments
 (0)