Skip to content

Conversation

@burkeholland
Copy link
Collaborator

Fixes #2324

@mcornella
Copy link

I think the fix would be either to add gist.github.com = false to the _servers Map, or to look at host.authority to see if it's gist.github.com. This is a sample value of host on a gist repo:

{
	"authority": "gist.github.com",
	"fragment": "",
	"path": "/20dec7376005dec0a1...",
	"query": "",
	"scheme": "https"
}
@mcornella
Copy link

mcornella commented Aug 23, 2021

This works for me for both git@github.com and git@gist.github.com, while keeping functionality for non-gist repos:

diff --git a/src/authentication/githubServer.ts b/src/authentication/githubServer.ts
index a3859d4..dc87dc0 100644
--- a/src/authentication/githubServer.ts
+++ b/src/authentication/githubServer.ts
@@ -17,6 +17,11 @@ export class GitHubManager {
 			return false;
 		}
 
+		// gist repos are not supported
+		if (host.authority === 'gist.github.com' || /^\/[a-z0-9]+$/i.test(host.path)) {
+			return false;
+		}
+
 		if (this._servers.has(host.authority)) {
 			return !!this._servers.get(host.authority);
 		}

EDIT: summary of what it works on:

  1. git@gist.github.com:gist-id
  2. git@github.com:gist-id
  3. https://gist.github.com/gist-id
  4. https://gist.github.com/user/gist-id

I'm unaware if https://github.com/id is a valid normal repository remote URL, which this patch would break. If it is, removing the regex test part of the condition would work, but then (2) wouldn't be detected as a gist.

@alexr00 alexr00 self-assigned this Aug 24, 2021
// .wiki repos are not supported
if (host.path.endsWith('.wiki')) {
// .wiki/.git repos are not supported
if (host.path.endsWith('.wiki') || host.path.match(/gist[.]github[.]com/g)) {
Copy link
Member

Choose a reason for hiding this comment

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

Does this need to be a global regular expression match (/g)?

Copy link
Collaborator Author

@burkeholland burkeholland Aug 27, 2021

Choose a reason for hiding this comment

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

Doesn't. What do you think of the proposed solution from @mcornella? It appears to handle the github.com case as well. I have no idea what that regex does, but his solution for gist.github.com looks more elegant than mine.

Copy link
Member

Choose a reason for hiding this comment

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

I usually go here to visualize regular expressions: https://regexper.com/#%5E%5C%2F%5Ba-z0-9%5D%2B%24

I don't think we want to exclude all github hosts with non-alphanumeric characters in them (I have no idea how often those will occur with enterprise for example). I'm happy with the simple test that this PR uses.

Choose a reason for hiding this comment

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

I'm ok with ignoring that part and just check the domain name. For that though we need to check host.authority instead of host.path.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed the g for now

Copy link
Member

Choose a reason for hiding this comment

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

@burkeholland, @mcornella is correct, it is host.authority then needs to be checked for gist.github.com.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Implemented hostpath check as per @mcornella

@alexr00 alexr00 added this to the September 2021 milestone Aug 24, 2021
Copy link
Member

@alexr00 alexr00 left a comment

Choose a reason for hiding this comment

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

Just #2933 (comment) then we're good to merge.

@alexr00 alexr00 modified the milestones: September 2021, October 2021 Sep 27, 2021
Copy link
Member

@alexr00 alexr00 left a comment

Choose a reason for hiding this comment

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

Doesn't host.authority need to be checked instead of host.path?

@alexr00 alexr00 modified the milestones: October 2021, November 2021 Oct 27, 2021
Copy link
Member

@alexr00 alexr00 left a comment

Choose a reason for hiding this comment

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

Ready to merge now!

@alexr00 alexr00 merged commit 4e2646f into microsoft:main Nov 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants