Package org.eclipse.egit.github.core

Examples of org.eclipse.egit.github.core.Reference


                  + getExceptionMessage(e), e);
        }
      entries.add(entry);
    }

    Reference ref = null;
    try {
      ref = service.getReference(repository, branch);
    } catch (RequestException e) {
      if (404 != e.getStatus())
        throw new MojoExecutionException("Error getting reference: "
            + getExceptionMessage(e), e);
    } catch (IOException e) {
      throw new MojoExecutionException("Error getting reference: "
          + getExceptionMessage(e), e);
    }

    if (ref != null && !TYPE_COMMIT.equals(ref.getObject().getType()))
      throw new MojoExecutionException(
          MessageFormat
              .format("Existing ref {0} points to a {1} ({2}) instead of a commmit",
                  ref.getRef(), ref.getObject().getType(),
                  ref.getObject().getSha()));

    // Write tree
    Tree tree;
    try {
      int size = entries.size();
      if (size != 1)
        info(MessageFormat.format(
            "Creating tree with {0} blob entries", size));
      else
        info("Creating tree with 1 blob entry");
      String baseTree = null;
      if (merge && ref != null) {
        Tree currentTree = service.getCommit(repository,
            ref.getObject().getSha()).getTree();
        if (currentTree != null)
          baseTree = currentTree.getSha();
        info(MessageFormat.format("Merging with tree {0}", baseTree));
      }
      if (!dryRun)
        tree = service.createTree(repository, entries, baseTree);
      else
        tree = new Tree();
    } catch (IOException e) {
      throw new MojoExecutionException("Error creating tree: "
          + getExceptionMessage(e), e);
    }

    // Build commit
    Commit commit = new Commit();
    commit.setMessage(message);
    commit.setTree(tree);

    // Set parent commit SHA-1 if reference exists
    if (ref != null)
      commit.setParents(Collections.singletonList(new Commit().setSha(ref
          .getObject().getSha())));

    Commit created;
    try {
      if (!dryRun)
        created = service.createCommit(repository, commit);
      else
        created = new Commit();
      info(MessageFormat.format("Creating commit with SHA-1: {0}",
          created.getSha()));
    } catch (IOException e) {
      throw new MojoExecutionException("Error creating commit: "
          + getExceptionMessage(e), e);
    }

    TypedResource object = new TypedResource();
    object.setType(TYPE_COMMIT).setSha(created.getSha());
    if (ref != null) {
      // Update existing reference
      ref.setObject(object);
      try {
        info(MessageFormat.format(
            "Updating reference {0} from {1} to {2}", branch,
            commit.getParents().get(0).getSha(), created.getSha()));
        if (!dryRun)
          service.editReference(repository, ref, force);
      } catch (IOException e) {
        throw new MojoExecutionException("Error editing reference: "
            + getExceptionMessage(e), e);
      }
    } else {
      // Create new reference
      ref = new Reference().setObject(object).setRef(branch);
      try {
        info(MessageFormat.format(
            "Creating reference {0} starting at commit {1}",
            branch, created.getSha()));
        if (!dryRun)
View Full Code Here


      }
      TreeEntry entry = createEntry("", NO_JEKYLL_FILE, service, repository, outputDirectory);
      entries.add(entry);
    }

    Reference ref = getReference(service, repository);
   
    if(dryRun){
      log.debug("Dry run mode, skip deploy.");
      return;
    }

    // Write tree
    Tree tree = createTree(service, repository, ref, entries);

    // Build commit
    Commit commit = new Commit();
    commit.setMessage(message != null ? message : "GitHubWagon: Deploying OpooPress to GitHub Pages.");
    commit.setTree(tree);

    // Set parent commit SHA-1 if reference exists
    if (ref != null){
      commit.setParents(Collections.singletonList(new Commit().setSha(ref.getObject().getSha())));
    }

    Commit created;
    try {
      created = service.createCommit(repository, commit);
      log.info(MessageFormat.format("Creating commit with SHA-1: {0}", created.getSha()));
    } catch (IOException e) {
      throw new GitHubException("Error creating commit: " + e.getMessage(), e);
    }

    TypedResource object = new TypedResource();
    object.setType(TYPE_COMMIT).setSha(created.getSha());
    if (ref != null) {
      // Update existing reference
      ref.setObject(object);
      try {
        log.info(String.format("Updating reference %s from %s to %s", branch, commit.getParents().get(0).getSha(), created.getSha()));
        service.editReference(repository, ref, force);
      } catch (IOException e) {
        throw new GitHubException("Error editing reference: " + e.getMessage(), e);
      }
    } else {
      // Create new reference
      ref = new Reference().setObject(object).setRef(branch);
      try {
        log.info(MessageFormat.format("Creating reference {0} starting at commit {1}", branch, created.getSha()));
        service.createReference(repository, ref);
      } catch (IOException e) {
        throw new GitHubException("Error creating reference: " + e.getMessage(), e);
View Full Code Here

      throw new GitHubException("Error creating tree: " + e.getMessage(), e);
    }
  }

  private Reference getReference(DataService service, RepositoryId repository) throws GitHubException {
    Reference ref = null;
    try {
      ref = service.getReference(repository, branch);
    } catch (RequestException e) {
      if (404 != e.getStatus()){     
        throw new GitHubException("Error getting reference: " + e.getMessage(), e);
      }
    } catch (IOException e) {
      throw new GitHubException("Error getting reference: " + e.getMessage(), e);
    }

    if (ref != null && !TYPE_COMMIT.equals(ref.getObject().getType())){
      throw new GitHubException(MessageFormat.format("Existing ref {0} points to a {1} ({2}) instead of a commmit",
          ref.getRef(), ref.getObject().getType(), ref.getObject().getSha()));
    }
    return ref;
  }
View Full Code Here

                  + getExceptionMessage(e), e);
        }
      entries.add(entry);
    }

    Reference ref = null;
    try {
      ref = service.getReference(repository, branch);
    } catch (RequestException e) {
      if (404 != e.getStatus())
        throw new MojoExecutionException("Error getting reference: "
            + getExceptionMessage(e), e);
    } catch (IOException e) {
      throw new MojoExecutionException("Error getting reference: "
          + getExceptionMessage(e), e);
    }

    if (ref != null && !TYPE_COMMIT.equals(ref.getObject().getType()))
      throw new MojoExecutionException(
          MessageFormat
              .format("Existing ref {0} points to a {1} ({2}) instead of a commmit",
                  ref.getRef(), ref.getObject().getType(),
                  ref.getObject().getSha()));

    // Write tree
    Tree tree;
    try {
      int size = entries.size();
      if (size != 1)
        info(MessageFormat.format(
            "Creating tree with {0} blob entries", size));
      else
        info("Creating tree with 1 blob entry");
      String baseTree = null;
      if (merge && ref != null) {
        Tree currentTree = service.getCommit(repository,
            ref.getObject().getSha()).getTree();
        if (currentTree != null)
          baseTree = currentTree.getSha();
        info(MessageFormat.format("Merging with tree {0}", baseTree));
      }
      if (!dryRun)
        tree = service.createTree(repository, entries, baseTree);
      else
        tree = new Tree();
    } catch (IOException e) {
      throw new MojoExecutionException("Error creating tree: "
          + getExceptionMessage(e), e);
    }

    // Build commit
    Commit commit = new Commit();
    commit.setMessage(message);
    commit.setTree(tree);

        try {
            UserService userService = new UserService(service.getClient());
            User user = userService.getUser();

            CommitUser author = new CommitUser();
            author.setName(user.getName());
            author.setEmail(user.getEmail());
            author.setDate(new GregorianCalendar().getTime());

            commit.setAuthor(author);
            commit.setCommitter(author);
        } catch (IOException e) {
            throw new MojoExecutionException("Error retrieving user info: "
                    + getExceptionMessage(e), e);
        }

    // Set parent commit SHA-1 if reference exists
    if (ref != null)
      commit.setParents(Collections.singletonList(new Commit().setSha(ref
          .getObject().getSha())));

    Commit created;
    try {
      if (!dryRun)
        created = service.createCommit(repository, commit);
      else
        created = new Commit();
      info(MessageFormat.format("Creating commit with SHA-1: {0}",
          created.getSha()));
    } catch (IOException e) {
      throw new MojoExecutionException("Error creating commit: "
          + getExceptionMessage(e), e);
    }

    TypedResource object = new TypedResource();
    object.setType(TYPE_COMMIT).setSha(created.getSha());
    if (ref != null) {
      // Update existing reference
      ref.setObject(object);
      try {
        info(MessageFormat.format(
            "Updating reference {0} from {1} to {2}", branch,
            commit.getParents().get(0).getSha(), created.getSha()));
        if (!dryRun)
          service.editReference(repository, ref, force);
      } catch (IOException e) {
        throw new MojoExecutionException("Error editing reference: "
            + getExceptionMessage(e), e);
      }
    } else {
      // Create new reference
      ref = new Reference().setObject(object).setRef(branch);
      try {
        info(MessageFormat.format(
            "Creating reference {0} starting at commit {1}",
            branch, created.getSha()));
        if (!dryRun)
View Full Code Here

TOP

Related Classes of org.eclipse.egit.github.core.Reference

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.