Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extension: RepositorySizeGithubAPI to get size of a repo #316

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Changes from 4 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5018984
RepositoryAPI
rishabhBudhouliya Jul 28, 2020
b77c89e
Change import statement from GitRepoSizeEstimator to GitToolChooser
rishabhBudhouliya Jul 28, 2020
63e3e1d
Rename extension from RepositoryAPI to RepositorySizeAPI
rishabhBudhouliya Jul 28, 2020
f41e6aa
Rename extension
rishabhBudhouliya Jul 28, 2020
e3fe52b
Remove the extension class from GitSCMSource
rishabhBudhouliya Aug 10, 2020
4d067df
This class contains an extension which provides the size of a remote …
rishabhBudhouliya Aug 10, 2020
e1f6dc8
Merge branch 'master' into add-gitplugin-extension
rishabhBudhouliya Aug 10, 2020
b760cb8
Add automated test cases for the estimator class
rishabhBudhouliya Aug 10, 2020
8b4b2fd
Merge branch 'add-gitplugin-extension' of https://github.com/rishabhB…
rishabhBudhouliya Aug 10, 2020
98deda5
Remove unused GitToolChooser import
rishabhBudhouliya Aug 11, 2020
36954d1
Add an automated test case which expects isApplicableTo to fail due t…
rishabhBudhouliya Aug 11, 2020
37e2afd
remove unused imports from the test class
rishabhBudhouliya Aug 11, 2020
0eaf780
Point to local wiremock
bitwiseman Sep 1, 2020
a8ba6cc
Catch exceptions raised by GitHubRepositoryInfo incase of malformed URLs
rishabhBudhouliya Sep 5, 2020
ee7a8a1
Merge branch 'add-gitplugin-extension' of https://github.com/rishabhB…
rishabhBudhouliya Sep 5, 2020
03efd94
Merge branch 'master' into add-gitplugin-extension
rishabhBudhouliya Sep 5, 2020
5ce9fcb
Fix upper bound dependencies requirement
rishabhBudhouliya Sep 5, 2020
f752531
Merge branch 'add-gitplugin-extension' of https://github.com/rishabhB…
rishabhBudhouliya Sep 5, 2020
a8f522c
Depend on git plugin 4.4.0 and Jenkins 2.204.1
rishabhBudhouliya Sep 5, 2020
801806c
Base commit for auto formatting for open PRs
bitwiseman Mar 4, 2021
1b1d76d
Merge branch 'task/formatting-base' into add-gitplugin-extension
bitwiseman Mar 4, 2021
fe70bc1
Apply autoformatting
bitwiseman Mar 4, 2021
c40ee6e
Merge remote-tracking branch 'upstream/master' into add-gitplugin-ext…
bitwiseman Mar 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import javax.servlet.http.HttpServletResponse;
import jenkins.model.Jenkins;
import jenkins.plugins.git.AbstractGitSCMSource;
import jenkins.plugins.git.GitToolChooser;
import jenkins.plugins.git.GitTagSCMRevision;
import jenkins.plugins.git.MergeWithGitSCMExtension;
import jenkins.plugins.git.traits.GitBrowserSCMSourceTrait;
Expand Down Expand Up @@ -1916,6 +1917,27 @@ public void afterSave() {
}
}

/**
* This extension intends to perform a GET request without any credentials on the provided repository URL
* to return the size of repository.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Git Plugin is adding a new class called the GitToolChooser which requires the size of a remote repository to recommend an optimal git implementation ("git" or "jgit").

This size can be measured in two ways:

  • By cache created by a multi branch project
  • From REST APIs exposed by the git providers themselves

Since the git plugin probably doesn't involve calling any REST API in the code base, we would like to delegate the task to the plugins which do.

In terms of the GitHub Branch Source Plugin, implementing this extension serves no purpose for the plugin, it only acts as a helper method for git plugin to improve internal performance.

@Extension
public static class RepositorySizeGithubAPI extends GitToolChooser.RepositorySizeAPI {

@Override
public boolean isApplicableTo(String repoUrl) {
return repoUrl.contains("github");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not sufficient. GitHub Enterprise servers can have any kind of name with our without "github" in the url. Also, there could be git repos with "github" in the name.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I understand. So this means checking the repository url might not be enough to confirm the applicability. Would you suggest that we send some user info as well? A combination of those two could be enough to see if it is being provided by Github?

}

@Override
public Long getSizeOfRepository(String repoUrl) throws Exception {
GitHubRepositoryInfo info = GitHubRepositoryInfo.forRepositoryUrl(repoUrl);
GitHub github = Connector.connect(info.getApiUri(), null);
GHRepository ghRepository = github.getRepository(info.getRepoOwner() + '/' + info.getRepository());
return (long) ghRepository.getSize();
}
}

@Symbol("github")
@Extension
public static class DescriptorImpl extends SCMSourceDescriptor implements CustomDescribableModel {
Expand Down