/** * Create tree * * @param repository * @param entries * @return created tree * @throws IOException */ public Tree createTree(IRepositoryIdProvider repository, Collection<TreeEntry> entries) throws IOException { return createTree(repository, entries, null); }
/** * Edit reference * * @param repository * @param reference * @return updated reference * @throws IOException */ public Reference editReference(IRepositoryIdProvider repository, Reference reference) throws IOException { return editReference(repository, reference, false); }
/** * Get references for given repository * * @param repository * @return non-null but possibly empty list of references * @throws IOException */ public List<Reference> getReferences(IRepositoryIdProvider repository) throws IOException { final String id = getId(repository); StringBuilder uri = new StringBuilder(); uri.append(SEGMENT_REPOS); uri.append('/').append(id); uri.append(SEGMENT_GIT); uri.append(SEGMENT_REFS); PagedRequest<Reference> request = createPagedRequest(); request.setType(new TypeToken<List<Reference>>() { }.getType()); request.setUri(uri); return getAll(request); }
DataService service = new DataService(createClient(host, userName, password, oauth2Token, server, settings, session)); if (!dryRun) try { entry.setSha(service.createBlob(repository, new Blob() .setEncoding(ENCODING_BASE64).setContent(""))); } catch (IOException e) { ref = service.getReference(repository, branch); } catch (RequestException e) { if (404 != e.getStatus()) String baseTree = null; if (merge && ref != null) { Tree currentTree = service.getCommit(repository, ref.getObject().getSha()).getTree(); if (currentTree != null) tree = service.createTree(repository, entries, baseTree); else tree = new Tree(); UserService userService = new UserService(service.getClient()); User user = userService.getUser(); try { if (!dryRun) created = service.createCommit(repository, commit);
Reference ref = null; try { ref = service.getReference(repository, BRANCH_DEFAULT); } catch (RequestException e) { if (e.getStatus() != 404) { Tree currentTree = ref != null ? service.getCommit(repository, ref.getObject().getSha()).getTree() : null; String baseTree = null; if (currentTree != null) baseTree = currentTree.getSha(); Tree tree = service.createTree(repository, tree2, baseTree); tree.setTree(tree2); Commit commit = createCommit(); commit.setTree(tree); Commit created = service.createCommit(repository, commit); TypedResource object = new TypedResource(); object.setType(TypedResource.TYPE_COMMIT).setSha(created.getSha()); try { service.editReference(repository, ref, true); } catch (IOException e) { throw new Exception(e); service.createReference(repository, ref); } catch (IOException e) { throw new Exception(e);
public PublishHelper(CommitterInfo parameterObject,String commitMessage, RepositoryId id) { cl = new GitHubClient(); cl.setCredentials(parameterObject.login, parameterObject.password); rs = new RepositoryService(cl); service = new DataService(cl); this.email=parameterObject.email; this.name=parameterObject.name; this.commitMessage=commitMessage; this.id=id; }
protected static String createBlob(DataService service, RepositoryId repository, String prefix, String path) throws Exception { File file = new File(prefix, path); final long length = file.length(); final int size = length > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) length; ByteArrayOutputStream output = new ByteArrayOutputStream(size); FileInputStream stream = new FileInputStream(file); try { final byte[] buffer = new byte[8192]; int read; while ((read = stream.read(buffer)) != -1) output.write(buffer, 0, read); Blob blob = new Blob().setEncoding(Blob.ENCODING_BASE64); String encoded = EncodingUtils.toBase64(output.toByteArray()); blob.setContent(encoded); return service.createBlob(repository, blob); } finally { stream.close(); } }
DataService service = new DataService(createClient(host, userName, password, oauth2Token, server, settings, session)); if (!dryRun) try { entry.setSha(service.createBlob(repository, new Blob() .setEncoding(ENCODING_BASE64).setContent(""))); } catch (IOException e) { ref = service.getReference(repository, branch); } catch (RequestException e) { if (404 != e.getStatus()) String baseTree = null; if (merge && ref != null) { Tree currentTree = service.getCommit(repository, ref.getObject().getSha()).getTree(); if (currentTree != null) tree = service.createTree(repository, entries, baseTree); else tree = new Tree(); UserService userService = new UserService(service.getClient()); User user = userService.getUser(); try { if (!dryRun) created = service.createCommit(repository, commit);
public GetCommitFileProducer(GitHubEndpoint endpoint) throws Exception { super(endpoint); Registry registry = endpoint.getCamelContext().getRegistry(); Object service = registry.lookupByName(GitHubConstants.GITHUB_DATA_SERVICE); if (service != null) { LOG.debug("Using DataService found in registry {}", service.getClass().getCanonicalName()); dataService = (DataService) service; } else { dataService = new DataService(); } initService(dataService); if (endpoint.getEncoding() != null) { encoding = endpoint.getEncoding(); if (!encoding.equalsIgnoreCase(Blob.ENCODING_BASE64) && !encoding.equalsIgnoreCase(Blob.ENCODING_UTF8)) { throw new IllegalArgumentException("Unknown encoding '" + encoding + "'"); } } }
file.getAbsolutePath())); if (!dryRun) return service.createBlob(repository, blob); else return null;
file.getAbsolutePath())); if (!dryRun) return service.createBlob(repository, blob); else return null;
public static TreeEntry createTreeFromString(String prefix, String name, String content, DataService serv, RepositoryId id) throws Exception { TreeEntry entry = new TreeEntry(); entry.setPath(prefix + name); entry.setType(TreeEntry.TYPE_BLOB); entry.setMode(TreeEntry.MODE_BLOB); Blob blob = new Blob().setEncoding(Blob.ENCODING_UTF8); blob.setContent(content); entry.setSha(serv.createBlob(id, blob)); return entry; } }