GetInputConfigForRef returns the input config for the ref. A string is also passed because if the ref is a git ref, it would only have a git.Name, instead of a git branch, a git ref and a git tag. Therefore the original string is passed.
(ref Ref, value string)
| 902 | // passed because if the ref is a git ref, it would only have a git.Name, instead |
| 903 | // of a git branch, a git ref and a git tag. Therefore the original string is passed. |
| 904 | func GetInputConfigForRef(ref Ref, value string) (bufconfig.InputConfig, error) { |
| 905 | _, options, err := getRawPathAndOptions(value) |
| 906 | if err != nil { |
| 907 | return nil, err |
| 908 | } |
| 909 | switch t := ref.(type) { |
| 910 | case ArchiveRef: |
| 911 | switch t.ArchiveType() { |
| 912 | case ArchiveTypeZip: |
| 913 | return bufconfig.NewZipArchiveInputConfig( |
| 914 | t.Path(), |
| 915 | t.SubDirPath(), |
| 916 | t.StripComponents(), |
| 917 | ) |
| 918 | case ArchiveTypeTar: |
| 919 | return bufconfig.NewTarballInputConfig( |
| 920 | t.Path(), |
| 921 | t.SubDirPath(), |
| 922 | t.CompressionType().String(), |
| 923 | t.StripComponents(), |
| 924 | ) |
| 925 | default: |
| 926 | return nil, fmt.Errorf("invalid archive type: %v", t.ArchiveType()) |
| 927 | } |
| 928 | case DirRef: |
| 929 | return bufconfig.NewDirectoryInputConfig( |
| 930 | t.Path(), |
| 931 | ) |
| 932 | case ModuleRef: |
| 933 | return bufconfig.NewModuleInputConfig( |
| 934 | t.ModuleRef().String(), |
| 935 | ) |
| 936 | case ProtoFileRef: |
| 937 | return bufconfig.NewProtoFileInputConfig( |
| 938 | t.Path(), |
| 939 | t.IncludePackageFiles(), |
| 940 | ) |
| 941 | case GitRef: |
| 942 | return bufconfig.NewGitRepoInputConfig( |
| 943 | t.Path(), |
| 944 | t.SubDirPath(), |
| 945 | options["branch"], |
| 946 | options["tag"], |
| 947 | options["ref"], |
| 948 | toPointer(t.Depth()), |
| 949 | t.RecurseSubmodules(), |
| 950 | ) |
| 951 | default: |
| 952 | return nil, fmt.Errorf("unexpected Ref of type %T", ref) |
| 953 | } |
| 954 | } |
| 955 | |
| 956 | func toPointer[T any](value T) *T { |
| 957 | return &value |
no test coverage detected
searching dependent graphs…