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

Omit ports in constructed URL #383

Merged
merged 4 commits into from
Apr 12, 2021
Merged

Omit ports in constructed URL #383

merged 4 commits into from
Apr 12, 2021

Conversation

alexanderchiu
Copy link
Contributor

@alexanderchiu alexanderchiu commented Feb 20, 2021

Hi!

Firstly want to say thanks to all the maintainers for this project. I was very excited when I came across it.

I ran into the same issue as described in #193 and I saw the stagnant related PR #259.

I thought I would add some tests ( as requested), and added a fix for the omitting ports in constructed URLs with fewer regex changes.

I don't write much JS so any style based feedback would be much appreciated!

@alexanderchiu alexanderchiu changed the title Alex/gh 193 Omit ports in constructed URL Feb 20, 2021
Base automatically changed from master to main February 24, 2021 17:03
@salemhilal
Copy link
Contributor

Hey, thank you for this PR (especially for the master -> main rename in the tests). We are prepping a minor version release at the moment, but once that's settled we can give this some more attention.

@alexanderchiu
Copy link
Contributor Author

Sounds good - thanks @salemhilal!

const line = null
const rev = "main"
expect(UrlToRepo(repo, path, line, rev)).toBe(
"//bitbucket.org/YourOrganization/RepoOne/src/main/test.txt"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this repo URL contain the port? i.e. would we expect this to be "//bitbucket.org:7999/YourOrganization/RepoOne/src/main/test.txt" in all cases?

Copy link
Contributor Author

@alexanderchiu alexanderchiu Mar 3, 2021

Choose a reason for hiding this comment

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

Thanks for the reviewing this.

My actual goal is to get Hound working with BitBucket Server. From https://confluence.atlassian.com/bitbucketserver074/enabling-ssh-access-to-git-repositories-in-bitbucket-server-1019386434.html#EnablingSSHaccesstoGitrepositoriesinBitbucketServer-SSHbaseURL

Resulting SSH URL for a repo: ssh://git@bitbucket.atlassian.com:7999/<projectname>/<reponame>.git
Bitbucket Server base URL: https://bitbucket.atlassian.com

In this case the port is required in the config.json when specifying the ssh url, but the port needs to be dropped when resolving the url when clicking through to a file after search.

I guess the best approach would be to allow specifying a {port} in base-url to allow the user to pick whether they want the port or not.

As an aside, I thought this was the only change needed to get it working with BitBucket Server, but after finally getting around to building and running my branch I've noticed that the required URL is in the form:

https://bitbucket.atlassian.com/projects/<projectname>/repos/<reponame>/browse 

which would require further additions to the UrlToRepo method. This diversion may not be what you want, so won't open a PR unless you think it's worthwhile.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for the late response here! I think that if the port is dropped to support bitbucket URLs, but bitbucket URLs are themselves also kinda weirdly formatted, it might be better to leave the port in by default, and then to make a special exemption for bitbucket / atlassian-hosted repositories. Does that work for you? I'd also be open to a PR to handle Bitbucket URLs, either as part of this PR or in a separate one.

Copy link
Contributor Author

@alexanderchiu alexanderchiu Apr 1, 2021

Choose a reason for hiding this comment

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

No stress. Thanks for getting back to me.

leave the port in by default, and then to make a special exemption for bitbucket / atlassian-hosted repositories.

Sounds good to me.

I'd also be open to a PR to handle Bitbucket URLs, either as part of this PR or in a separate one.

Ok cool thanks - I'm not really sure where the best place to add that logic would be. I'll update this PR so that the ports are not ommited, and then you can add the exemption for on prem bitbucket repositories (or give me some guidance on what you have in mind and I can do it).

Copy link
Contributor

Choose a reason for hiding this comment

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

For sure. I think in that function itself, there's already some edge cases being handled (like this one for Github wikis. I wouldn't be mad at exceptional handling of some sort for Bitbucket in there as well. If that method gets too unruly, it shouldn't be too difficult to refactor later, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added full support for the Bitbucket server style repos by adding expansion vars. Tested it against our deployed bitbucket and click through to source is working now. Everything else should have remained backwards compatible.

Copy link
Contributor

@salemhilal salemhilal left a comment

Choose a reason for hiding this comment

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

I have one implementation-specific question (I'm not totally familiar with how we would expect ports to be used here), but otherwise this PR looks good to me! Thank you for contributing this fix.

- Include port in url var expansion
- Add hostname/port/project/repo expansion variables

See GH-193
@Crocmagnon
Copy link

Hi there 👋🏻
I'm seeing mentions of bitbucket, will this fix work for gitlab for example ?

Our clone urls look something like this:

ssh://git@git.example.com:4222/group/project.git

The urls generated by hound on the search results look like this:

https://git.example.com/4222/group/project/blob/master/folder/file.extension

We expect the /4222 to be removed.

@salemhilal
Copy link
Contributor

Hey @Crocmagnon, this PR is exactly about that problem (see this issue for more). I haven't had a chance to put fresh eyes on this PR, but I'd like to do that shortly (life's crazy, etc.)

@alexanderchiu
Copy link
Contributor Author

I tested locally with the proposed changes and the following passes:

  test("gitlab", () => {
      const repo = {
          url: "ssh://git@git.example.com:4222/group/project.git",
          "url-pattern":
          {
              "base-url" : "{hostname}/{project}/{repo}/blob/{rev}/{path}{anchor}",
              "anchor" : "#{line}",
          }
      };
      const path = "folder/file.extension"
      const line = null
      const rev = "master"
      expect(UrlToRepo(repo, path, line, rev)).toBe(
          "//git.example.com/group/project/blob/master/folder/file.extension"
      );
  });

@salemhilal
Copy link
Contributor

@alexanderchiu if you want to toss that test into this PR that works for me. Otherwise, this looks good to merge!

@alexanderchiu
Copy link
Contributor Author

That functionality is already covered by an existing test so it's probably not necessary. I think you can merge when convenient. Thanks for the reviews @salemhilal!

@salemhilal salemhilal merged commit 60b8104 into hound-search:main Apr 12, 2021
@salemhilal
Copy link
Contributor

Thank you for this PR (and your patience) @alexanderchiu!

AlexFielder added a commit to AlexFielder/hound that referenced this pull request Jul 28, 2021
* Update config-example.json

* Add CONTRIBUTING.md file

* Dockerfile should use github.com/hound-search

This fixing the docker build issue.

* make listen URL clickable in iTerm (hound-search#340)

* Add Jest tests and Prettier support (hound-search#343)

This commit adds support for Jest and writes a few simple tests as
proof. Adding a test is as easy as adding a file that ends in
`.test.js` next to the file you want to test. Any file that matches that
pattern should have access to Jest functions. The whole test suite can
be run with `npm run test`.

I also added support for Prettier. Running `npm run format`
should run Prettier on any staged changes. I thought about adding Husky
to automatically run Prettier as a pre-commit hook, but it seems as
though Husky requires git v2.13 which would require me upgrading Git.

I didn't add support for ESLint yet since I figured that may be a
slightly more involved conversation — Prettier seems to be generally
uncontroverical and is generally only slightly configurable, whereas
ESlint is highly configurable and behaves however we want it to.

* Git VCS driver: Support non-default target refs (hound-search#345)

Currently, only the default ref (`master`) is supported.

- Allow target non-default target refs to be specified via configs.
- Add config-driven target ref auto-detection using the `HEAD` branch.
- Update default repo base URL pattern to link to the content revision,
  accounting for potential non-default target ref usage.
- Add global-level VCS configs which are merged into the repo-level configs
  during startup (repo-level vals take precedence).

* Exclude file path (hound-search#347)

* index: add a search option to exclude files given a regexp

* api: add the excludeFiles query parameter

Set the index search options ExcludeFileRegexp with this parameter
to allow excluding files from the search via a regexp.

* js: add the excludeFiles search parameter

* css: increase the label width to fit 'Exclude file path'

* js: correctly check that advanced is empty

* Update README with contact info for maintainers. (hound-search#348)

I don't think there's a clear way to see who has push privs to this repo from the public, and even if there is, the "Get In Touch" section should probably list the maintainers.

* incorporate detailing around gopath in README's quick start instructions (hound-search#352)

Co-authored-by: Rebecca Lau <blobbered@users.noreply.github.com>

* pin alpine version to make the docker pass

* Update Dockerfile

* More detailed setup documents with less assumptions on users (hound-search#359)

This commit updates the readme to be a little more verbose for people who don't necessarily have Go or Docker set up, but who want to contribute nonetheless. 

* Apply the old patch

* add  some figures

* remove the idea code

* get it untitled

* remove

* add .idea dev tools

* remove simple config

* get config back

* detailing tests and simplifying the setup

* Commit TLS support guide

Co-authored-by: Salem <salemhilal@gmail.com>

* make the statement terser

* delete unused img

* rewording

* back to the old path

* Update README.md

* Update README.md

* Update README.md

* Update README.md

Co-authored-by: Salem <salemhilal@gmail.com>

* Initialize Go Modules

`go mod init github.com/hound-search/hound`

* Replace jteeuwen/go-bindata with go-bindata/go-bindata

The former package is unmainatained since a while and the replacement
also fixes this bug I encountered when trying to build the package:
jteeuwen/discussions#6

* update Go version requirement in README file

* Add a -version flag to Houndd (hound-search#362)

This commit adds a `-version` flag to houndd. Running `houndd -version` prints the current version and exits.

Co-authored-by: Kartikay Shandil <kartikays@sahaj.ai>

* Add padding between advanced mode text inputs

* add margin bottom to fields that are not last

* update front end bundles

Co-authored-by: Blobb Ered <@blobbered>

* Setup Github Actions CI (hound-search#354)

* Setup Github Actions CI

Replaces Travis CI with Github Actions for better integration.
Jobs are run against more recent Go versions, namely 1.12 to 1.14 .
 .
For further documentation see

- https://github.com/actions/setup-go
- and https://help.github.com/en/actions

This adds `-race` flag to the Go tests and will run a meta linter
(golangci-lint).

* keep travis in until github workflows is tested

* tidy go mods

* remove lint command from github workflow

* add back go-bindata to go modules list

* up version of actions checkout to fix deprecation errors

* return go bindata to the go.sum file as well

Co-authored-by: Andreas Linz <anli@spreadshirt.net>

* Add a github actions badge

Thanks again @klingtnet and @blobbered for making this possible!

* Update README.md (hound-search#369)

Add clarification of using file:// protocol for accessing locally pulled repos

* Added new folder docs with config-options description on options. (hound-search#370)

* Added new folder docs with config-options description on options.

* Peer review comment update
updated formatting for config options documentation and added link
in readme.

* readme link update

* link update

* Minor edits from code review

Co-authored-by: kayyapil <k.ayyapillai@reply.com>
Co-authored-by: ehrktia <a.karthie+github@pm.me>
Co-authored-by: Salem <salemhilal@gmail.com>

* Test windows

* Run Go build and test on Ubuntu Linux and Windows

* Add lint

* Install dependencies in Dockerfile

* Fix typo

* Adding a tip for windows users (hound-search#379)

* Adding a tip for windows users

* Update README.md

Co-authored-by: Salem <salemhilal@gmail.com>

Co-authored-by: Salem <salemhilal@gmail.com>

* Use tini as default entry point (hound-search#376)

* Add a warning for the default branch rename (hound-search#380)

* Add a warning for the default branch rename

* Add a link to Github's renaming documentation.

* Update README to reflect branch rename. (hound-search#384)

* Update version in main.go

* support github webhook

* Omit ports in constructed URL (hound-search#383)

* Improve accessibility (hound-search#398)

* Resolve WCAG2AA.Principle3.Guideline3_1.3_1_1.H57.2

* Resolve WCAG2AA.Principle4.Guideline4_1.4_1_2.H91.InputText.Name

* Resolve WCAG2AA.Principle4.Guideline4_1.4_1_2.H91.Button.Name

* Improve stats contrast

* Improve advanced text contrast

* Improve repo title contrast

* Improve contrast in advanced section

* Improve line number contrast

* Improve excluded files contrast

* Improve "load all" button contrast

* Automatically build docker image and publish to ghcr.io (hound-search#401)

* Feat: Use goreleaser

* Feat: Add docker build, remove goreleaser

* Fix: Add image name

* Feat: Use ghcr.io and build-push-action@2

* We try again

* Trying yet again

* Fix: Use actor and GITHUB_TOKEN

* Fix: Use github.actor in image tag path

* Fix: use github.repository_owner instead of github.actor

When you have an organisation, github.actor != github.repository_owner

Co-authored-by: Jone Marius Vignes <jvig@ihelse.net>

* Update default-config.json (hound-search#391)

* Update default-config.json

* Update default-config.json (ref: main)

* Add hyperlinks to repository root (hound-search#396)

* Add literal search option (hound-search#397)

* Add literal search option

* Pull EscapeRegExp into common.js

* Add db/ to Jest ignore patterns

* Test EscapeRegExp() matches its input

* Test vacuous EscapeRegExp

* Give repo links a target of blank (hound-search#404)

Add rel="noopener noreferrer" to _blank links

Co-authored-by: Joseph Price <pricejosephd@gmail.com>
Co-authored-by: dschott <dschott@etsy.com>
Co-authored-by: Nicolas R <cpan@atoomic.org>
Co-authored-by: Igor <igorwwwwwwwwwwwwwwwwwwww@users.noreply.github.com>
Co-authored-by: Salem <salemhilal@gmail.com>
Co-authored-by: Richard Liang <rwliang@users.noreply.github.com>
Co-authored-by: Vincent Rischmann <vincent@rischmann.fr>
Co-authored-by: Blobb Ered <5307533+blobbered@users.noreply.github.com>
Co-authored-by: Rebecca Lau <blobbered@users.noreply.github.com>
Co-authored-by: Ruixi Fan <rfan@etsy.com>
Co-authored-by: Ruixi Fan <69488297+rfan-debug@users.noreply.github.com>
Co-authored-by: Andreas Linz <anli@spreadshirt.net>
Co-authored-by: Rebecca Lau <rblau@etsy.com>
Co-authored-by: Kartikay Shandil <shandilkartikay@gmail.com>
Co-authored-by: Kartikay Shandil <kartikays@sahaj.ai>
Co-authored-by: Ashley Roach <aroach@gmail.com>
Co-authored-by: karthick <a.karthie+github@gmail.com>
Co-authored-by: kayyapil <k.ayyapillai@reply.com>
Co-authored-by: ehrktia <a.karthie+github@pm.me>
Co-authored-by: David Kolossa <david.kolossa@posteo.de>
Co-authored-by: Sandro <sandro.jaeckel@gmail.com>
Co-authored-by: Andrew Stanton <StingyJack@users.noreply.github.com>
Co-authored-by: David Schott <dschott68@users.noreply.github.com>
Co-authored-by: Cor Bosman <cor@xs4all.net>
Co-authored-by: Jacob Rose <jacob@usroses.org>
Co-authored-by: Alexander Chiu <alexanderchiu@users.noreply.github.com>
Co-authored-by: Joel Armstrong <mrjoelarmstrong@gmail.com>
Co-authored-by: Jone Marius Vignes <73816+inful@users.noreply.github.com>
Co-authored-by: Jone Marius Vignes <jvig@ihelse.net>
Co-authored-by: Simon Legner <Simon.Legner@gmail.com>
Co-authored-by: Bucky Schwarz <hoorayimhelping@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants