Esempio n. 1
0
 /**
  * Convert address to input stream.
  *
  * @param path Path of the asset, e.g. "yegor/rultor#pom.xml"
  * @return Stream with content
  * @throws IOException If fails
  */
 private InputStream asset(final String path) throws IOException {
   final Matcher matcher = GithubProfile.PATH.matcher(path);
   if (!matcher.matches()) {
     throw new IllegalArgumentException(String.format("invalid path of asset: %s", path));
   }
   final Repo rpo = this.repo.github().repos().get(new Coordinates.Simple(matcher.group(1)));
   return new ByteArrayInputStream(
       Base64.decodeBase64(new Content.Smart(rpo.contents().get(matcher.group(2))).content()));
 }
Esempio n. 2
0
 /**
  * GithubProfile should throw a ConfigException if some asset file doesn't exist.
  *
  * @throws Exception In case of error.
  */
 @Test(expected = Profile.ConfigException.class)
 public void testAssetNotFound() throws Exception {
   final Repo repo =
       GithubProfileTest.repo(
           Joiner.on('\n')
               .join("assets:", "  test.xml: jeff/test1#test.xmls", "merge:", "  script: hello!"));
   final String yaml = "friends:\n  - jeff/test2";
   repo.github()
       .repos()
       .get(new Coordinates.Simple("jeff/test1"))
       .contents()
       .create(
           Json.createObjectBuilder()
               .add("path", ".rultor.yml")
               .add("message", "rultor config")
               .add("content", Base64.encodeBase64String(yaml.getBytes()))
               .build());
   final Profile profile = new GithubProfile(repo);
   profile.assets();
 }
Esempio n. 3
0
 /**
  * Make a repo with YAML inside.
  *
  * @param yaml YAML config
  * @return Repo
  * @throws IOException If fails
  */
 private static Repo repo(final String yaml) throws IOException {
   final Github github = new MkGithub("jeff");
   github
       .repos()
       .create(new Repos.RepoCreate("test1", false))
       .contents()
       .create(
           Json.createObjectBuilder()
               .add("path", "test.xml")
               .add("message", "just test msg")
               .add("content", Base64.encodeBase64String("hey".getBytes()))
               .build());
   final Repo repo = github.repos().create(new Repos.RepoCreate("test2", false));
   repo.contents()
       .create(
           Json.createObjectBuilder()
               .add("path", ".rultor.yml")
               .add("message", "just test")
               .add("content", Base64.encodeBase64String(yaml.getBytes()))
               .build());
   return repo;
 }
Esempio n. 4
0
 /**
  * GithubProfile can fetch a YAML config.
  *
  * @throws Exception In case of error.
  */
 @Test
 public void fetchesYamlConfig() throws Exception {
   final Repo repo =
       GithubProfileTest.repo(
           Joiner.on('\n')
               .join(
                   "assets:",
                   "  test.xml: jeff/test1#test.xml",
                   "  beta: jeff/test1#test.xml",
                   "architect:",
                   " - jeff",
                   " - donald",
                   "merge:",
                   "  script: hello!"));
   final String yaml = "friends:\n  - jeff/test2";
   repo.github()
       .repos()
       .get(new Coordinates.Simple("jeff/test1"))
       .contents()
       .create(
           Json.createObjectBuilder()
               .add("path", ".rultor.yml")
               .add("message", "rultor config")
               .add("content", Base64.encodeBase64String(yaml.getBytes()))
               .build());
   final Profile profile = new GithubProfile(repo);
   MatcherAssert.assertThat(
       profile.read(),
       XhtmlMatchers.hasXPaths(
           "/p/entry[@key='merge']/entry[@key='script']",
           "/p/entry[@key='assets']/entry[@key='test.xml']",
           "/p/entry[@key='assets']/entry[@key='beta']"));
   MatcherAssert.assertThat(
       profile.read().xpath("/p/entry[@key='architect']/item/text()"),
       Matchers.contains("jeff", "donald"));
   MatcherAssert.assertThat(
       profile.assets(), Matchers.hasEntry(Matchers.equalTo("test.xml"), Matchers.notNullValue()));
 }
Esempio n. 5
0
 /**
  * GithubProfile can accept asset from repo name that contains a dot.
  *
  * @throws Exception In case of error.
  */
 @Test
 public void acceptsAssetsFromDotRepo() throws Exception {
   final Github github = new MkGithub("jeff");
   final String name = "te.st";
   final Repo repo = github.repos().create(new Repos.RepoCreate(name, false));
   repo.contents()
       .create(
           Json.createObjectBuilder()
               .add("path", ".rultor.yml")
               .add("message", "just test")
               .add(
                   "content",
                   Base64.encodeBase64String(
                       Joiner.on('\n')
                           .join(
                               "assets: ",
                               String.format("  something.xml: jeff/%s#.rultor.yml", name),
                               "friends:",
                               String.format("  - jeff/%s", name))
                           .getBytes()))
               .build());
   MatcherAssert.assertThat(
       new GithubProfile(repo).assets().entrySet(), Matchers.not(Matchers.emptyIterable()));
 }