本文整理匯總了Java中org.kohsuke.github.GitHub.getRepository方法的典型用法代碼示例。如果您正苦於以下問題:Java GitHub.getRepository方法的具體用法?Java GitHub.getRepository怎麽用?Java GitHub.getRepository使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.kohsuke.github.GitHub
的用法示例。
在下文中一共展示了GitHub.getRepository方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: readGHRepo
import org.kohsuke.github.GitHub; //導入方法依賴的package包/類
public static Optional<GHRepository> readGHRepo() {
try {
GitHub github = GitHub.connect();
String desiredRepo = System.getProperty("GITHUB_REPOSITORY");
System.out.println("Desired Repo:" + desiredRepo);
GHRepository repo = github.getRepository(desiredRepo);
return Optional.of(repo);
} catch (Exception e) {
for (Object o : System.getProperties().keySet()) {
System.out.println(o + ":" + System.getProperty(o + ""));
}
for (String env : System.getenv().keySet()) {
System.out.println(env + ":" + System.getenv(env));
}
e.printStackTrace();
return Optional.empty();
}
}
示例2: deleteRepository
import org.kohsuke.github.GitHub; //導入方法依賴的package包/類
/**
* ɾ��ָ����repository
* @param strRepoName Ҫɾ����github����
* @return void
*/
public void deleteRepository(String strRepoName){
GitHub github;
GHRepository repo;
try {
System.out.println("Delete repo started!\t"+strRepoName);
github = GitHub.connectToEnterprise(getApiUrl(), getUserId(), getPassword());
repo = github.getRepository(strRepoName);
repo.delete();
System.out.println("Delete repo finished!");
} catch (IOException e) {
// TODO Auto-generated catch block
errHandle(e.getMessage());
}
bFinished = true;
}
示例3: removeRepo
import org.kohsuke.github.GitHub; //導入方法依賴的package包/類
public synchronized static void removeRepo(String owner, String repoName) throws KaramelException {
try {
GitHub gitHub = GitHub.connectUsingPassword(GithubApi.getUser(), GithubApi.getPassword());
if (!gitHub.isCredentialValid()) {
throw new KaramelException("Invalid GitHub credentials");
}
GHRepository repo = null;
if (owner.compareToIgnoreCase(GithubApi.getUser()) != 0) {
GHOrganization org = gitHub.getOrganization(owner);
repo = org.getRepository(repoName);
} else {
repo = gitHub.getRepository(owner + "/" + repoName);
}
repo.delete();
} catch (IOException ex) {
throw new KaramelException("Problem authenticating with gihub-api when trying to remove a repository");
}
}
示例4: withPermission
import org.kohsuke.github.GitHub; //導入方法依賴的package包/類
private NullSafePredicate<GitHub> withPermission(final GitHubRepositoryName name, GHPermission permission) {
return new NullSafePredicate<GitHub>() {
@Override
protected boolean applyNullSafe(@Nonnull GitHub gh) {
try {
final GHRepository repo = gh.getRepository(name.getUserName() + "/" + name.getRepositoryName());
if (permission == GHPermission.ADMIN) {
return repo.hasAdminAccess();
} else if (permission == GHPermission.PUSH) {
return repo.hasPushAccess();
} else {
return repo.hasPullAccess();
}
} catch (IOException e) {
return false;
}
}
};
}
示例5: GitHubRepository
import org.kohsuke.github.GitHub; //導入方法依賴的package包/類
@Inject
public GitHubRepository(
ScopedProvider<GitHubLogin> ghLoginProvider,
@GitHubURL String gitHubUrl,
@Assisted("organisation") String organisation,
@Assisted("repository") String repository)
throws IOException {
this.cloneUrl = gitHubUrl + "/" + organisation + "/" + repository + ".git";
this.organisation = organisation;
this.repository = repository;
GitHubLogin ghLogin = ghLoginProvider.get();
GitHub gh = ghLogin.getHub();
this.username = ghLogin.getMyself().getLogin();
this.password = ghLogin.getToken().accessToken;
this.ghRepository = gh.getRepository(organisation + "/" + repository);
}
示例6: getLastRelease
import org.kohsuke.github.GitHub; //導入方法依賴的package包/類
/**
* @return poslední platné vydání
*/
private String getLastRelease()
{
try
{
GitHub github = GitHub.connectAnonymously() ;
GHRepository repo = github.getRepository(GITHUB_REPOSITORY);
final List<GHRelease> releases = repo.getReleases();
return (!releases.isEmpty()) ? releases.get(0).getTagName() : null ;
}
catch (IOException e)
{
throw new IllegalStateException(e);
}
}
示例7: _getRecentChanges
import org.kohsuke.github.GitHub; //導入方法依賴的package包/類
private static String _getRecentChanges() {
StringBuilder sb = new StringBuilder();
try {
GitHub github = GitHub.connectAnonymously();
GHRepository repo = github.getRepository("chriskearney/creeper");
PagedIterable<GHCommit> list = repo.queryCommits().list();
int i = 1;
for (GHCommit ghCommit : list.asList()) {
if (i < 10) {
sb.append("Change #" + i + " | " + ghCommit.getCommitShortInfo().getMessage() + "\r\n");
} else {
continue;
}
i++;
}
} catch (IOException e) {
SentryManager.logSentry(RecentChangesManager.class, e, "Recent changes problem!");
}
return sb.toString();
}
示例8: getRelease
import org.kohsuke.github.GitHub; //導入方法依賴的package包/類
/**
* @return a {@link GHRelease} for the latest ServerBrowser release
* @throws IOException
* if there was an error querying GitHub
*/
public static Optional<GHRelease> getRelease() throws IOException {
final GitHub gitHub = GitHubBuilder.fromEnvironment().withRateLimitHandler(RateLimitHandler.FAIL).build();
final GHRepository repository = gitHub.getRepository("Bios-Marcel/ServerBrowser");
final List<GHRelease> releases = repository.listReleases().asList();
if (!releases.isEmpty()) {
return Optional.ofNullable(releases.get(0));
}
return Optional.empty();
}
示例9: commit
import org.kohsuke.github.GitHub; //導入方法依賴的package包/類
public static void commit(String rep,String content,String commitmsg,String path,boolean isAdd){
try{
GitHub github = GitHub.connectUsingPassword("[email protected]", "xiaomin0322#####");
GHRepository repo =github.getRepository(rep);
GHContent contentObj = null;
if(isAdd){
List<GHContent> contents = repo.getDirectoryContent("/");
if(CollectionUtils.isNotEmpty(contents)){
for(GHContent c:contents){
String name = c.getName();
System.out.println("name==="+name);
if(path.equals(name)){
System.out.println("找到目標文件");
contentObj = c;
}
}
}
}
if(contentObj==null){
System.out.println("創建文件>>>>>>>>>>>>>>>>>>>>>");
repo.createContent(content,commitmsg, path);
//contentObj = repo.getFileContent(path);
}
if(isAdd){
StringBuilder builder = new StringBuilder();
String str = IOUtils.toString(contentObj.read());
System.out.println("獲取遠程內容為:"+str);
builder.append(str).append("\r\n");
builder.append(content);
contentObj.update(builder.toString(), commitmsg);
}
System.out.println("提交成功>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
}catch(Exception e){
System.out.println("提交出現異常>>>>>>>>>>>>>>>>>>>>>>>>>");
e.printStackTrace();
}
}
示例10: getNonForkRepository
import org.kohsuke.github.GitHub; //導入方法依賴的package包/類
protected String getNonForkRepository(GitHub github, CharSequence htmlUrl) throws IOException {
String repo = getRepository(htmlUrl);
if(repo == null) {
return null;
}
// try up to three times to cater for some connection issues that
// we see from time to time
int retries = 3;
while(true) {
try {
final GHRepository repository = github.getRepository(repo);
if (repository.isFork()) {
//System.out.println("Ignoring forked repo " + repo);
return null;
}
return repo;
} catch (HttpException e) {
retries--;
if(retries <= 0) {
throw e;
}
// retry once more
System.out.println("Retry " + retries + " after failing to talk to Github");
e.printStackTrace(System.out);
}
}
}
示例11: getLatestVersion
import org.kohsuke.github.GitHub; //導入方法依賴的package包/類
public String getLatestVersion() {
String result = null;
try {
final GitHub github = GitHub.connectAnonymously();
final GHRepository repository = github.getRepository(REPOSITORY_NAME);
result = repository.listReleases().asList().stream().map((r) -> r.getName().substring(1)).max((a, b) -> {
return new DefaultArtifactVersion(a).compareTo(new DefaultArtifactVersion(b));
}).orElse(null);
} catch (final IOException e) {
logger.log(Level.WARNING, "Unable to get latest version", e);
}
return result;
}
示例12: getContents
import org.kohsuke.github.GitHub; //導入方法依賴的package包/類
/**
* �Ӹ�repository����������Դ
* @param strRepoName github����
* @param strLocalPath �����ļ���·��
* @return void
*/
public void getContents(String strRepoName, String strRemotePath, String strLocalPath){
GitHub github;
GHRepository repo;
try {
if(strLocalPath.charAt(strLocalPath.length()-1) != '\\')
strLocalPath += "\\";
System.out.println("Download started!\t"+strRepoName + "/" + strRemotePath+" => " + strLocalPath);
github = GitHub.connectToEnterprise(getApiUrl(), getUserId(), getPassword());
repo = github.getRepository( strRepoName);
List<GHContent> contents = repo.getDirectoryContent(strRemotePath);
Iterator it = contents.iterator();
while(it.hasNext()){
GHContent content = (GHContent)it.next();
if(content.isDirectory()){
getRepoDirectory(content, strRemotePath, strLocalPath);
}
else {
String strFileName = strLocalPath + content.getName();
if(content.getDownloadUrl() != null && content.getSize() < 1024 * 1024){
writeFile(content.read(), strFileName);
}
else if(content.getGitUrl() != null){
writeFileFromGitUrl(content.getGitUrl(), strFileName);
}
}
}
System.out.println("Download finished!");
} catch(FileNotFoundException e1){
System.out.println("Error:"+e1.getCause().getMessage()+"��Դ������");
System.exit(0);
} catch (IOException e) {
// TODO Auto-generated catch block
errHandle(e.getMessage());
}
bFinished = true;
}
示例13: deleteContents
import org.kohsuke.github.GitHub; //導入方法依賴的package包/類
/**
* ��ָ����repo����ɾ��ָ�����ļ���
* @param strRepoName github����
* @param strDirectory Ҫɾ�����ļ���
* @return void
*/
public void deleteContents(String strRepoName, String strDirectory){
GitHub github;
GHRepository repo;
try {
System.out.println("Delete started!\t"+strRepoName+"/" + strDirectory);
github = GitHub.connectToEnterprise(getApiUrl(), getUserId(), getPassword());
repo = github.getRepository(strRepoName);
List<GHContent> lContents = null;
try{
lContents = repo.getDirectoryContent(strDirectory);
Iterator<GHContent> it = lContents.iterator();
while(it.hasNext()){
GHContent content = it.next();
if(content.isDirectory()){
deleteContentsDir(repo, content.getPath());
//content.delete("delete dir");
}
else{
System.out.println("Deleted!\t" + content.getPath());
content.delete("delete dir");
}
}
}
catch(FileNotFoundException ex){
System.out.println(strDirectory + " does not exists.");
}
System.out.println("Delete finished!");
} catch (Exception e) {
// TODO Auto-generated catch block
errHandle(e.getMessage());
}
bFinished = true;
}
示例14: updateContents
import org.kohsuke.github.GitHub; //導入方法依賴的package包/類
/**
* �ύ��Դ��ָ����repo��
* @param strRepoName github����
* @param strPath ����·��
* @return void
*/
public void updateContents(String strRepoName, String strLocalPath, String strRemotePath){
GitHub github;
GHRepository repo;
try {
if(strLocalPath.charAt(strLocalPath.length()-1) != '\\')
strLocalPath += "\\";
if(strRemotePath.length() > 0 && strRemotePath.charAt(strRemotePath.length()-1) == '/')
strRemotePath = strRemotePath.substring(0, strRemotePath.length()-1);
System.out.println("Upload started!\t"+strLocalPath + " => " + strRepoName+"/"+strRemotePath);
github = GitHub.connectToEnterprise(getApiUrl(), getUserId(), getPassword());
repo = github.getRepository( strRepoName);
Path startingDir = Paths.get(strLocalPath);
UpdateFileFinder finder = new UpdateFileFinder(repo, strRemotePath, strLocalPath, "*.*");
Files.walkFileTree(startingDir, finder);
finder.done();
System.out.println("Upload finished!");
} catch (Exception e) {
// TODO Auto-generated catch block
if(e.getClass().equals(FileNotFoundException.class)){
System.out.println("Error:"+e.getCause().getMessage()+"�ֿⲻ����");
System.exit(0);
}
else
errHandle(e.getMessage());
}
bFinished = true;
}
示例15: runNotesBuilder
import org.kohsuke.github.GitHub; //導入方法依賴的package包/類
/**
* Executes NotesBuilder based on passed command line options.
* @param cliOptions command line options.
* @return result of NotesBuilder work.
* @throws IOException if an I/O error occurs.
* @throws GitAPIException if an error occurs while accessing GitHub API.
*/
private static Result runNotesBuilder(CliOptions cliOptions)
throws IOException, GitAPIException {
final String localRepoPath = cliOptions.getLocalRepoPath();
final String startRef = cliOptions.getStartRef();
final String endRef = cliOptions.getEndRef();
final String authToken = cliOptions.getAuthToken();
final GitHub connection;
if (authToken == null) {
connection = GitHub.connectAnonymously();
}
else {
connection = GitHub.connectUsingOAuth(authToken);
}
final GHRepository remoteRepo = connection.getRepository(REMOTE_REPO_PATH);
final Result result = NotesBuilder.buildResult(remoteRepo, localRepoPath, startRef, endRef);
if (result.hasWarnings()) {
printListOf(result.getWarningMessages());
}
if (result.hasErrors()) {
printListOf(result.getErrorMessages());
}
return result;
}