git-plugin icon indicating copy to clipboard operation
git-plugin copied to clipboard

Jenkins 54858: Init Org/Repo Name regex

Open Hrushi20 opened this issue 3 years ago • 7 comments

JENKINS-54858 - Adds Organization/Project and Repository name

Added a global git config for regex which is used internally to get the project name and repo name.

Checklist

  • [x] I have read the CONTRIBUTING doc
  • [ ] I have added tests that verify my changes
  • [x] No Javadoc warnings were introduced with my changes
  • [x] No spotbugs warnings were introduced with my changes
  • [ ] I have interactively tested my changes

Types of changes

What types of changes does your code introduce? Put an x in the boxes that apply. Delete the items in the list that do not apply fixes an issue)

  • [x] New feature (non-breaking change which adds functionality)

Hrushi20 avatar Feb 27 '22 05:02 Hrushi20

The regex I added here in the test case is temporary. I am working on the regex which covers all the scenarios.

Hrushi20 avatar Feb 27 '22 09:02 Hrushi20

A summary of the issue at JIRA: https://issues.jenkins.io/browse/JENKINS-54868

So let's compile a list of URLs you are expected to handle with your regex:

ssh://[email protected]:22/DefaultCollection/_ssh/elisp
ssh://[email protected]/MarkEWaite/tasks.git
ssh://git.assembla.com/git-plugin.bin.git
https://www.assembla.com/spaces/git-plugin/git-2/
https://markwaite.visualstudio.com/_git/elisp
https://markwaite.visualstudio.com/DefaultCollection/_git/elisp
https://markwaite.visualstudio.com/DefaultCollection/elisp/_git/elisp
https://markwaite:[email protected]/DefaultCollection/_git/elisp
https://markewaite:[email protected]/markewaite/tasks.git
https://markewaite:[email protected]/markewaite/bin.git
https://[email protected]/markewaite/tasks.git
https://[email protected]/markewaite/git-client-plugin.git
https://[email protected]/markewaite/bin.git
https://MarkEWaite:[email protected]/MarkEWaite/tasks.git
https://MarkEWaite:[email protected]/MarkEWaite/tasks.git
https://MarkEWaite:[email protected]/MarkEWaite/bin.git
https://jenkins-git-plugin.git.beanstalkapp.com/git-client-plugin.git
https://gitlab.com/MarkEWaite/tasks.git
https://gitlab.com/MarkEWaite/tasks
https://gitlab.com/MarkEWaite/bin
https://github.com/MarkEWaite/tasks.git
https://github.com/MarkEWaite/bin.git
https://git.assembla.com/git-plugin.bin.git
https://bitbucket.org/markewaite/tasks.git
https://bitbucket.org/markewaite/git-client-plugin.git
https://bitbucket.org/markewaite/bin.git
[email protected]:/jenkins-git-plugin/git-client-plugin.git
[email protected]:MarkEWaite/tasks.git
[email protected]:MarkEWaite/tasks.git
[email protected]:MarkEWaite/bin.git
[email protected]:git-plugin.bin.git
[email protected]:markewaite/tasks.git
[email protected]:markewaite/bin.git

Also, please note that

Our hosts include GitHub, Gitlab, AzureDevOps Server/TFS (on-prem), Gogs some just file://, (Mark Waite has listed more (above), like Assembla and BitBucket). Azure DevOps Server nomenclature is actually: http://tfs.mycorp.com/tfs/<TeamCollection>/<TeamProject>/_git/<RepoName>, so it's more than just <OrgName>/<Reponame>. Some of our host servers end in an internal domain which is not (com|org), We also don't need to supply a FQDN either; HOST will suffice.

krisstern avatar Feb 27 '22 09:02 krisstern

.*(@|\/\/).*?(\/|:)(?<group>.*?)\/(?<repo>.*)$ works with github,gitlab and bitbucket urls. The vscode and assembla urls are not working with this regex. Trying a way of not hard coding the names into the regex.

Hrushi20 avatar Feb 27 '22 09:02 Hrushi20

Yeah, you should have a list of regex patterns you can match against one-by-one. That way you get to catch all of the possible patterns without having one global URL regex pattern which may become unwieldy.

krisstern avatar Feb 27 '22 09:02 krisstern

Also a request from a user is the following:

it would be helpful to have a global configuration option in the git plugin that would allow the administrator to define the regular expression and the replacement text for those cases where the user runs their own git server.

krisstern avatar Feb 27 '22 09:02 krisstern

I moved all the tests to a new class. I tried setting the global config regex by calling the GitSCM.DescriptorImpl in my custom test class. Also I created a few test cases. When trying to run the test, I am getting an error stating- Jenkins.instance is missing. Read the documentation of Jenkins.getInstanceOrNull to see what you are doing wrong

How do I set the global config and use it to valid the tests. I created a set method in DesciptorImpl to set the global regex.

Hrushi20 avatar Feb 27 '22 11:02 Hrushi20

For now I am passing the global Regex as a parameter. After passing all the tests for all kinds of urls I will use the global config Regex.

Hrushi20 avatar Feb 27 '22 12:02 Hrushi20