Skip to content
Permalink
Browse files

[JENKINS-43507] Tidy up GitHubSCMNavigator

  • Loading branch information...
stephenc committed Jun 16, 2017
1 parent 10b52c1 commit 19b1697519ca20bd08022ed96a5a591a25e78abe
Showing with 3,116 additions and 17 deletions.
  1. +1 −1 pom.xml
  2. +27 −3 src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMBuilder.java
  3. +338 −13 src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigator.java
  4. +1,900 −0 src/test/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest.java
  5. +12 −0 ...resources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/basic_cloud.xml
  6. +13 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/basic_server.xml
  7. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_000000.xml
  8. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_000001.xml
  9. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_000010.xml
  10. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_000011.xml
  11. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_000100.xml
  12. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_000101.xml
  13. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_000110.xml
  14. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_000111.xml
  15. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_001000.xml
  16. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_001001.xml
  17. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_001010.xml
  18. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_001011.xml
  19. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_001100.xml
  20. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_001101.xml
  21. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_001110.xml
  22. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_001111.xml
  23. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_010000.xml
  24. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_010001.xml
  25. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_010010.xml
  26. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_010011.xml
  27. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_010100.xml
  28. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_010101.xml
  29. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_010110.xml
  30. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_010111.xml
  31. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_011000.xml
  32. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_011001.xml
  33. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_011010.xml
  34. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_011011.xml
  35. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_011100.xml
  36. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_011101.xml
  37. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_011110.xml
  38. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_011111.xml
  39. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_100000.xml
  40. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_100001.xml
  41. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_100010.xml
  42. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_100011.xml
  43. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_100100.xml
  44. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_100101.xml
  45. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_100110.xml
  46. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_100111.xml
  47. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_101000.xml
  48. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_101001.xml
  49. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_101010.xml
  50. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_101011.xml
  51. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_101100.xml
  52. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_101101.xml
  53. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_101110.xml
  54. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_101111.xml
  55. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_110000.xml
  56. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_110001.xml
  57. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_110010.xml
  58. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_110011.xml
  59. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_110100.xml
  60. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_110101.xml
  61. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_110110.xml
  62. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_110111.xml
  63. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_111000.xml
  64. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_111001.xml
  65. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_111010.xml
  66. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_111011.xml
  67. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_111100.xml
  68. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_111101.xml
  69. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_111110.xml
  70. +12 −0 ...esources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/build_111111.xml
  71. +13 −0 ...rces/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/exclude_branches.xml
  72. +13 −0 ...ources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/limit_branches.xml
  73. +13 −0 ...es/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/limit_repositories.xml
  74. +5 −0 ...test/resources/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/modern.xml
  75. +13 −0 ...es/org/jenkinsci/plugins/github_branch_source/GitHubSCMNavigatorTraitsTest/use_agent_checkout.xml
@@ -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>
@@ -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}.
@@ -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;

@@ -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";
}

/**
@@ -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()}.
Oops, something went wrong.

0 comments on commit 19b1697

Please sign in to comment.
You can’t perform that action at this time.