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 57aa90a
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.kohsuke.github.GHRepository;
import org.kohsuke.github.GitHub;

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

Expand Down Expand Up @@ -82,7 +83,12 @@ 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();
final GitHubRepository gitHubRepository = gitHubDTOFactory.createRepository(gitHub.getUser(user).getRepository(repository));
gitHubRepository.setMirrorUrl(IsMirrorRepo.getMirrorUrl(gitHub, user, repository));//For now we need this hack it because original API
//don't parse mirror url. Pull request to GitHub API
//https://github.com/kohsuke/github-api/pull/233
return gitHubRepository;
} 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,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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*******************************************************************************
* 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;

/**
* Return mirror url if it exist otherwise null
*
* @author Vitalii Parfonov
*/
public class IsMirrorRepo {

public static String getMirrorUrl(GitHub gitHub, String user, String repo) throws IOException {
return gitHub.retrieve().to("/repos/" + user + '/' + repo, GHRepositoryWithMirrorUrl.class).getMirrorUrl();
}
}

0 comments on commit 57aa90a

Please sign in to comment.