1
2
3
4
5 package com.jcabi.github;
6
7 import com.jcabi.log.Logger;
8 import java.io.IOException;
9 import org.apache.commons.lang3.RandomStringUtils;
10
11
12
13
14
15 public final class RepoRule {
16
17
18
19
20
21
22
23 public Repo repo(final Repos repos) throws IOException {
24 final Repos.RepoCreate settings = new Repos.RepoCreate(
25 "foo",
26 false
27 ).withAutoInit(true);
28 int attempts = 0;
29 Repo repo = null;
30 while (repo == null) {
31 final Repos.RepoCreate request = settings.withName(
32 RandomStringUtils.secure().nextAlphanumeric(20)
33 );
34 try {
35 repo = repos.create(request);
36 } catch (final AssertionError ex) {
37 Logger.warn(
38 this, "Create repository failed. Message: %s",
39 ex.getMessage()
40 );
41 ++attempts;
42 if (attempts > 5) {
43 throw new IllegalStateException(
44 String.format(
45 "Failed to created repository %s",
46 request.name()
47 ),
48 ex
49 );
50 }
51 }
52 }
53 return repo;
54 }
55 }