@@ -448,9 +448,15 @@ fragment repositoryFields on Repository {
448448 }
449449
450450 // Skip repos from unsupported code hosts but don't report them explicitly.
451- if ! includeUnsupported && strings .ToLower (repo .ExternalRepository .ServiceType ) != "github" && strings .ToLower (repo .ExternalRepository .ServiceType ) != "bitbucketserver" {
452- unsupported = append (unsupported , repo .Name )
453- continue
451+ if ! includeUnsupported {
452+ ok , err := isCodeHostSupportedForCampaigns (repo .ExternalRepository .ServiceType )
453+ if err != nil {
454+ return nil , errors .Wrap (err , "failed code host check" )
455+ }
456+ if ! ok {
457+ unsupported = append (unsupported , repo .Name )
458+ continue
459+ }
454460 }
455461
456462 if repo .DefaultBranch == nil || repo .DefaultBranch .Name == "" {
@@ -517,3 +523,44 @@ func askForConfirmation(s string) (bool, error) {
517523
518524 return false , nil
519525}
526+
527+ type minimumVersionDate struct {
528+ version string
529+ date string
530+ }
531+
532+ // codeHostCampaignVersions contains the minimum Sourcegraph version and build
533+ // date required for the given code host kind. If a code host is present with a
534+ // value of nil, this means that any Sourcegraph version will pass the check.
535+ var codeHostCampaignVersions = map [string ]* minimumVersionDate {
536+ "github" : nil ,
537+ "bitbucketserver" : nil ,
538+ "gitlab" : {
539+ version : "3.18.0" ,
540+ date : "2020-07-14" ,
541+ },
542+ }
543+
544+ func isCodeHostSupportedForCampaigns (kind string ) (bool , error ) {
545+ // TODO(LawnGnome): this is a temporary hack; I intend to improve our
546+ // testing story including mocking requests to Sourcegraph as part of
547+ // https://github.com/sourcegraph/sourcegraph/issues/12333
548+ return isCodeHostSupportedForCampaignsImpl (kind , getSourcegraphVersion )
549+ }
550+
551+ func isCodeHostSupportedForCampaignsImpl (kind string , getVersion func () (string , error )) (bool , error ) {
552+ mvd , ok := codeHostCampaignVersions [strings .ToLower (kind )]
553+ if ! ok {
554+ return false , nil
555+ }
556+ if mvd == nil {
557+ return true , nil
558+ }
559+
560+ ver , err := getVersion ()
561+ if err != nil {
562+ return false , errors .Wrap (err , "getting Sourcegraph version" )
563+ }
564+
565+ return sourcegraphVersionCheck (ver , fmt .Sprintf (">= %s" , mvd .version ), mvd .date )
566+ }
0 commit comments