Skip to content

Commit

Permalink
IDEX-3128: Add posibility to get mirror repository url
Browse files Browse the repository at this point in the history
Will be used for warn user if the try contribute mirrored repository like https://github.com/apache/tomee.
Also create pull request to original lib hub4j/github-api#233
  • Loading branch information
Vitaly Parfonov committed Nov 19, 2015
1 parent 5d83090 commit 1a5d8dc
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.kohsuke.github.GHPersonSet;
import org.kohsuke.github.GHPullRequest;
import org.kohsuke.github.GHRepository;
import org.kohsuke.github.GHRepositoryWithMirrorUrl;
import org.kohsuke.github.GHUser;
import org.kohsuke.github.PagedIterable;

Expand Down Expand Up @@ -132,6 +133,13 @@ public GitHubRepository createRepository(GHRepository ghRepository) throws ApiEx
return dtoRepository;
}

//TODO: can be removed after accepting https://github.com/kohsuke/github-api/pull/233
public GitHubRepository createRepositoryWithMirrorUrl(GHRepositoryWithMirrorUrl ghRepository) throws ApiException, IOException {
GitHubRepository dtoRepository = createRepository(ghRepository);
dtoRepository.setMirrorUrl(String.valueOf(ghRepository.getMirrorUrl()));
return dtoRepository;
}

/**
* Create DTO object of GitHub pull-requests collection from given pull-requests
* @param ghPullRequestsList collection of pull-requests from kohsuke GitHub library
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
import org.kohsuke.github.GHPersonSet;
import org.kohsuke.github.GHPullRequest;
import org.kohsuke.github.GHRepository;
import org.kohsuke.github.GHRepositoryWithMirrorUrl;
import org.kohsuke.github.GitHub;

import org.kohsuke.github.CheGitHubClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -82,7 +84,9 @@ public class GitHubService {
public GitHubRepository getUserRepository(@PathParam("user") String user, @PathParam("repository") String repository)
throws ApiException {
try {
return gitHubDTOFactory.createRepository(gitHubFactory.connect().getUser(user).getRepository(repository));
final GitHub gitHub = gitHubFactory.connect();
//TODO: temporary solution can be remove after accepting https://github.com/kohsuke/github-api/pull/233
return gitHubDTOFactory.createRepositoryWithMirrorUrl(CheGitHubClient.getRepository(gitHub, user, repository)) ;
} catch (IOException e) {
LOG.error("Get user info error", e);
throw new ServerException(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
*/
@DTO
public interface GitHubRepository {

/**
*
* @return mirror url if it mirrored repository like http://github.com/apache/tomee
*/
String getMirrorUrl();

void setMirrorUrl(String mirrorUrl);

/**
* Get repository's name.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 2012-2015 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.kohsuke.github;

import java.io.IOException;

/**
*
* Getting GitHub repo with mirror url original lib not support this
*
* https://github.com/kohsuke/github-api/pull/233
* @author Vitalii Parfonov
*/
public class CheGitHubClient {

public static GHRepositoryWithMirrorUrl getRepository(GitHub gitHub, String user, String repo) throws IOException {
return gitHub.retrieve().to("/repos/" + user + '/' + repo, GHRepositoryWithMirrorUrl.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*******************************************************************************
* Copyright (c) 2012-2015 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.kohsuke.github;

/**
* Add mirror url original lib don't support it
*
* @author Vitalii Parfonov
*/
@SuppressWarnings({"UnusedDeclaration"})
public class GHRepositoryWithMirrorUrl extends GHRepository {


private String mirror_url;


public String getMirrorUrl() {
return mirror_url;
}
}

0 comments on commit 1a5d8dc

Please sign in to comment.