dx-scanner icon indicating copy to clipboard operation
dx-scanner copied to clipboard

GitHub doesn't support self-hosted repositories

Open adelkahomolova opened this issue 5 years ago • 10 comments

GitHub can be self-hosted as well as Gitlab.

adelkahomolova avatar Mar 10 '20 13:03 adelkahomolova

Hey @adelkahomolova , I am pretty confused. What exactly needs to be done in this issue?

hariom1625 avatar Sep 30 '20 12:09 hariom1625

Hi, @hariom1625, thank you for the question. It is necessary to find out which VCS service is used (we support GitLab, GitHub, and Bitbucket). The way, how we found it out is just by URL (checking for "GitHub" string in URL). See ScanningStrategyDetectorUtils.ts As GitHub has also the option to have self-hosted repositories it is necessary to add this support. We've already implemented it for GitLab, so you can get the inspiration there ScanningStrategyDetector.ts Did I answer your question? :)

adelkahomolova avatar Sep 30 '20 13:09 adelkahomolova

Hey @adelkahomolova, I would love to trigger this issue and add support for GitHub. Can I go ahead?

haardikdharma10 avatar Sep 30 '20 16:09 haardikdharma10

Hi, @hariom1625, thank you for the question. It is necessary to find out which VCS service is used (we support GitLab, GitHub, and Bitbucket). The way, how we found it out is just by URL (checking for "GitHub" string in URL). See ScanningStrategyDetectorUtils.ts As GitHub has also the option to have self-hosted repositories it is necessary to add this support. We've already implemented it for GitLab, so you can get the inspiration there ScanningStrategyDetector.ts Did I answer your question? :)

Yes @adelkahomolova, That was helpful :-)

hariom1625 avatar Sep 30 '20 17:09 hariom1625

@haardikdharma10 Sure! Go ahead :)

adelkahomolova avatar Sep 30 '20 19:09 adelkahomolova

Thanks @adelkahomolova. I'd like some help on getting started. I went through both the files you mentioned above. The question I have is, do I need to change anything in the /src/services folder? I can see the file (GitHubService) but nothing such as githubClient similar to the one in gitlab folder (gitlabClient). Additionally, if you can help me with the files I need to edit, that'd be great :)

haardikdharma10 avatar Sep 30 '20 20:09 haardikdharma10

@haardikdharma10 Hi! Thank you for your question! There is no client for Github because we are using the Octokit library and it acts as the "Client".

There is a function to detect self-hosted Gitlab called determineGitLabRemoteServiceType: https://github.com/DXHeroes/dx-scanner/blob/master/src/detectors/ScanningStrategyDetector.ts#L193-L221 that is called in the function determineInputType: https://github.com/DXHeroes/dx-scanner/blob/master/src/detectors/ScanningStrategyDetector.ts#L90-L91

The correct solution is to create a similar function that tries to detect Github on a custom URL. E.g. to call endpoint https://api.[CUSTOM_DOMAIN] and it should return a similar response like this: https://api.github.com According to the response format and some keys, we're able to detect that the custom URL is remote Github on any other domain than github.com.

Do not hesitate to ask us if you have any other questions. 👏

Thank you

prokopsimek avatar Oct 01 '20 05:10 prokopsimek

@prokopsimek, Thanks a lot for such a brief and prompt response. It cleared almost everything in my head. Just to make sure before starting working on it:

  1. First thing is to add the two functions (listRepos and listGroups) in the GitHubService.ts file similar to the ones in the GitLabService.ts.
  2. Second, create a function similar to determineGitLabRemoteServiceTypeand call it in determineInputType.

If all of this sounds good to you, can I go ahead and raise a PR?

haardikdharma10 avatar Oct 01 '20 08:10 haardikdharma10

  1. It's not about adding the same methods as we use for GitLab. You have to find out, which endpoints ensure that you can get a valid response. But in the case of getting a list of repositories and lists of groups, the answer is yes. You have to add these methods in GitHubService.ts and than use them for determining.

  2. Yes, create similar to determineGitLabRemoteServiceType but call it the same way, so determineGitHubRemoteServiceType

If it's now clear to you, go for it! 👍

@haardikdharma10

adelkahomolova avatar Oct 01 '20 09:10 adelkahomolova

Thanks a lot! On it.

haardikdharma10 avatar Oct 01 '20 09:10 haardikdharma10