26
26
import org .openjdk .skara .host .*;
27
27
import org .openjdk .skara .host .network .URIBuilder ;
28
28
import org .openjdk .skara .json .*;
29
- import org .openjdk .skara .vcs .Repository ;
29
+ import org .openjdk .skara .vcs .* ;
30
30
31
31
import java .io .*;
32
32
import java .net .URI ;
@@ -115,11 +115,39 @@ private Map<String, HostedRepository> parseRepositories(JSONObject config) throw
115
115
return ret ;
116
116
}
117
117
118
- private HostedRepository getRepository (String name ) throws ConfigurationError {
119
- if (!repositories .containsKey (name )) {
120
- throw new ConfigurationError ("Repository " + name + " is not defined!" );
118
+ private static class RepositoryEntry {
119
+ HostedRepository repository ;
120
+ String ref ;
121
+ }
122
+
123
+ private RepositoryEntry parseRepositoryEntry (String entry ) throws ConfigurationError {
124
+ var ret = new RepositoryEntry ();
125
+ var refSeparatorIndex = entry .indexOf (':' );
126
+ if (refSeparatorIndex >= 0 ) {
127
+ ret .ref = entry .substring (refSeparatorIndex + 1 );
128
+ entry = entry .substring (0 , refSeparatorIndex );
129
+ }
130
+ var hostSeparatorIndex = entry .indexOf ('/' );
131
+ if (hostSeparatorIndex >= 0 ) {
132
+ var hostName = entry .substring (0 , hostSeparatorIndex );
133
+ var host = hosts .get (hostName );
134
+ if (!hosts .containsKey (hostName )) {
135
+ throw new ConfigurationError ("Repository entry " + entry + " uses undefined host '" + hostName + "'" );
136
+ }
137
+ var repositoryName = entry .substring (hostSeparatorIndex + 1 );
138
+ ret .repository = host .getRepository (repositoryName );
139
+ } else {
140
+ if (!repositories .containsKey (entry )) {
141
+ throw new ConfigurationError ("Repository " + entry + " is not defined!" );
142
+ }
143
+ ret .repository = repositories .get (entry );
144
+ }
145
+
146
+ if (ret .ref == null ) {
147
+ ret .ref = ret .repository .getRepositoryType () == VCS .GIT ? "master" : "default" ;
121
148
}
122
- return repositories .get (name );
149
+
150
+ return ret ;
123
151
}
124
152
125
153
public static BotRunnerConfiguration parse (JSONObject config , Path cwd ) throws ConfigurationError {
@@ -131,7 +159,6 @@ public static BotRunnerConfiguration parse(JSONObject config) throws Configurati
131
159
}
132
160
133
161
public BotConfiguration perBotConfiguration (String botName ) throws ConfigurationError {
134
-
135
162
if (!config .contains (botName )) {
136
163
throw new ConfigurationError ("No configuration for bot name: " + botName );
137
164
}
@@ -152,7 +179,18 @@ public Path storageFolder() {
152
179
@ Override
153
180
public HostedRepository repository (String name ) {
154
181
try {
155
- return getRepository (name );
182
+ var entry = parseRepositoryEntry (name );
183
+ return entry .repository ;
184
+ } catch (ConfigurationError configurationError ) {
185
+ throw new RuntimeException ("Couldn't find repository with name: " + name , configurationError );
186
+ }
187
+ }
188
+
189
+ @ Override
190
+ public String repositoryRef (String name ) {
191
+ try {
192
+ var entry = parseRepositoryEntry (name );
193
+ return entry .ref ;
156
194
} catch (ConfigurationError configurationError ) {
157
195
throw new RuntimeException ("Couldn't find repository with name: " + name , configurationError );
158
196
}
0 commit comments