Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-43507] Tidy up GitHubSCMNavigator
  • Loading branch information
stephenc committed Jun 16, 2017
1 parent 10b52c1 commit 19b1697
Show file tree
Hide file tree
Showing 75 changed files with 3,116 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -91,7 +91,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>branch-api</artifactId>
<version>2.0.11-20170615.161903-2</version>
<version>2.0.11-20170616.163514-4</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Expand Up @@ -49,7 +49,6 @@
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.transport.RefSpec;
import org.jenkinsci.plugins.github.config.GitHubServerConfig;
import org.kohsuke.github.GitHub;

/**
* Builds a {@link GitSCM} for {@link GitHubSCMSource}.
Expand All @@ -58,17 +57,37 @@
*/
public class GitHubSCMBuilder extends GitSCMBuilder<GitHubSCMBuilder> {

/**
* Singleton instance of {@link HttpsRepositoryUriResolver}.
*/
private static final HttpsRepositoryUriResolver HTTPS = new HttpsRepositoryUriResolver();
/**
* Singleton instance of {@link SshRepositoryUriResolver}.
*/
private static final SshRepositoryUriResolver SSH = new SshRepositoryUriResolver();
/**
* The context within which credentials should be resolved.
*/
@CheckForNull
private final SCMSourceOwner context;
/**
* The API URL
*/
@NonNull
private final String apiUri;
/**
* The repository owner.
*/
@NonNull
private final String repoOwner;
/**
* The repository name.
*/
@NonNull
private final String repository;
/**
* The definitive HTML user-facing URL of the repository (as provided by the GitHub API) if available.
*/
@CheckForNull
private final URL repositoryUrl;

Expand Down Expand Up @@ -105,14 +124,20 @@ public GitHubSCMBuilder(@NonNull GitHubSCMSource source,
}
}

/**
* Tries to guess the HTTPS URL of the Git repository.
*
* @param source the source.
* @return the (possibly incorrect) best guess at the Git repository URL.
*/
private static String guessRemote(GitHubSCMSource source) {
String apiUri = StringUtils.removeEnd(source.getApiUri(), "/");
if (StringUtils.isBlank(apiUri) || GitHubServerConfig.GITHUB_URL.equals(apiUri)) {
apiUri = "https://github.com";
} else {
apiUri = StringUtils.removeEnd(apiUri, "/api/v3");
}
return apiUri + "/" + source.getRepoOwner() + "/" + source.getRepository() + ".git";
return apiUri + "/" + source.getRepoOwner() + "/" + source.getRepository() + ".git";
}

/**
Expand Down Expand Up @@ -189,7 +214,6 @@ public static RepositoryUriResolver uriResolver(@CheckForNull Item context, @Non
}
}


/**
* Updates the {@link GitSCMBuilder#withRemote(String)} based on the current {@link #head()} and
* {@link #revision()}.
Expand Down

0 comments on commit 19b1697

Please sign in to comment.