-
Notifications
You must be signed in to change notification settings - Fork 370
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
base: master
Are you sure you want to change the base?
Changes from 4 commits
5018984
b77c89e
63e3e1d
f41e6aa
e3fe52b
4d067df
e1f6dc8
b760cb8
8b4b2fd
98deda5
36954d1
37e2afd
0eaf780
a8ba6cc
ee7a8a1
03efd94
5ce9fcb
f752531
a8f522c
801806c
1b1d76d
fe70bc1
c40ee6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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. | ||
*/ | ||
@Extension | ||
public static class RepositorySizeGithubAPI extends GitToolChooser.RepositorySizeAPI { | ||
|
||
@Override | ||
public boolean isApplicableTo(String repoUrl) { | ||
return repoUrl.contains("github"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do this?
There was a problem hiding this comment.
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:
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.