GitHub API org.kohsuke FileNotFoundException - java

I'm trying to use the org.kohsuke API to connect to a github repo and get the list of PRS this is my code:
public static void main(String... args) {
try {
GitHub github = GitHub.connect();
GHRepository r = github.getOrganization("rasilvap").getRepository("lift-tool-test");
List<GHPullRequest> i = r.getPullRequests(GHPullRequest.State.OPEN);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
I'm getting the next error in the line GitHub github = GitHub.connect();
java.io.FileNotFoundException: /Users/{myuser}/.github (No such file or directory)
I'm not pretty sure why is looking in my local pc, I have to create a .github folder y my user path?
Any ideas?

Related

java.nio.file.AccessDeniedException error?

Im trying to zip my created folder. Right now im testing localy and it create folder but after that i want to zip it.
This is my code for zip:
public static void pack(final String sourceDirPath, final String zipFilePath) throws IOException {
Path p = Files.createFile(Paths.get(zipFilePath));
try (ZipOutputStream zs = new ZipOutputStream(Files.newOutputStream(p))) {
Path pp = Paths.get(sourceDirPath);
Files.walk(pp).filter(path -> !Files.isDirectory(path)).forEach(path -> {
ZipEntry zipEntry = new ZipEntry(pp.relativize(path).toString());
try {
zs.putNextEntry(zipEntry);
Files.copy(path, zs);
zs.closeEntry();
} catch (IOException e) {
System.err.println(e);
}
});
} }
But im getting an error AccessDeniedException. Is there any option to zip created folder, i dont want to zip file because in that folder i will have subfolders, so i want to zip main folder. Any suggestion how can i achive that?
According to:
Getting "java.nio.file.AccessDeniedException" when trying to write to a folder
I think you should add the filename and the extension to your 'zipFilePath', for example: "C:\Users\XXXXX\Desktop\zippedFile.zip"

JGit: How to fix NoRemoteRepositoryException while creating Git Repository and pushing it to GitHub?

Using JGit, I want to create a NEW repository and push it to GitHub. I am getting NoRemoteRepositoryException. Please help. What am I missing in my code?
private void createNewRepository(Task task, String path) {
File directory = new File(path);
try {
Git git = Git.init().setDirectory(directory).call();
git.add().addFilepattern( "readme.txt" ).call();
git.commit().setMessage( "Create readme file" ).call();
RemoteAddCommand remoteAddCommand = git.remoteAdd();
remoteAddCommand.setName("origin");
remoteAddCommand.setUri(new URIish(task.getVcUrl()));
remoteAddCommand.call();
CredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(task.getVcUsername(), task.getVcPassword());
git.push().setCredentialsProvider(credentialsProvider).
setRemote("origin").setPushAll().setForce(true).call();
} catch (GitAPIException ex) {
logger.warn(ex.getLocalizedMessage(), ex);
taskLogger.get().append(ex.getLocalizedMessage()).append("\n");
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
The error stacktrace is
Caused by: org.eclipse.jgit.errors.NoRemoteRepositoryException:
http://github.com/AAA/Orgtest_sd3:
https://github.com/AAA/Orgtest_sd3/info/refs?service=git-receive-pack not
found
at
org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:520)
at
org.eclipse.jgit.transport.TransportHttp.openPush(TransportHttp.java:440)
at org.eclipse.jgit.transport.PushProcess.execute(PushProcess.java:160)
at org.eclipse.jgit.transport.Transport.push(Transport.java:1344)
at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:169)
You cannot create a new remote repository from your local host, neither with JGit nor with native Git.
You'll have to first create a repository on the remote host, then you can clone, fetch, and push from/to this repository.

Load a Config file on an Android app using Appium with Java

I have been searching for a long time to find a way to import a config file on an Android app using Appium with Java. I am still learning on this and I hope that I find some help here.
Here is the case:
I have an android app that I started testing but before that I have to import a configuration file into this app in order to become active.
public class sipphone extends base {
public static void main(String[] args) throws MalformedURLException {
// TODO Auto-generated method stub
AndroidDriver<AndroidElement> driver=capabilities();
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
File configImport= new File("src");
File file= new File(configImport, "testconfig.config");
driver.findElementById("android:id/button1").click();
driver.findElementById("android:id/btn_later").click();
try{
//import file from src directory
}
catch (Exception e) {
return;
}
}
}
How can I load the file inside the try block and then into the Android App?
Please check
https://appium.github.io/java-client/io/appium/java_client/android/PushesFiles.html#pushFile
Search on http://discuss.appium.io/ or https://github.com/appium/appium on how to use it

Extracting Text From JPG

I've tried this code and added the needed jar files but still I'm getting an error message like Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'libtesseract302'.
Is there a complete tutorial how to extract text and what things should be done to address the error? Any help is appreciated...
import net.sourceforge.tess4j.*;
import java.io.File;
public class ExtractTxtFromImg {
public static void main(String[] args) {
File imgFile = new File("C:\\Documents and Settings\\rueca\\Desktop\\sampleImg.jpg");
Tesseract instance = Tesseract.getInstance(); // JNA Interface Mapping
// Tesseract1 instance = new Tesseract1(); // JNA Direct Mapping
try {
String result = instance.doOCR(imgFile);
System.out.println(result);
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
}
In addition to adding the jars, you also need to add the natives. You can do so with Djava.library.path="C:\[absolute path to dir containing *.dll files and such]"
Note that you need to provide the directory, not the file itself.

jgit need 2 arguments error message

I am trying a simple java class to test the functionality of jGit (see below).
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import java.io.File;
import java.io.IOException;
public class CreateRepository {
public static void main( String[] args ){
Repository myrepo = createRepository("/mypath");
}
public static Repository createRepository(String repoPath) {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repo = null;
try {
repo = builder.setGitDir(new File(repoPath))
.readEnvironment() // scan environment GIT_* variables
.findGitDir() // scan up the file system tree
.build();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return repo;
}
}
When i run this on Eclipse Indigo with latest jgit jar in my build path i get the error message "Need 2 arguments" - nothing else, no exceptions! :S
Thanks for any help in advance.
The only part of JGit which displays that error message is in the main() function of MyersDiff.
/**
* #param args two filenames specifying the contents to be diffed
*/
public static void main(String[] args) {
if (args.length != 2) {
System.err.println(JGitText.get().need2Arguments);
System.exit(1);
}
// ...
}
So check your classpath and make sure your project (and your main()) are before the jgit.jar, and that you don't somehow calls the wrong main().
First look into package org.eclipse.jgit.api.
The easiest start is from class Git:
// clone a repository
Git git = Git.cloneRepository().setURI("git://yourserver/repo.git").call();
// init a fresh new repository in the current directory
Git git = Git.init().call();
// open a repository on your disk
Git git = Git.open(new File("/path/of/repo");
Then explore the commands available on the git object you get
from these starting points.

Categories

Resources