MCPcopy
hub / github.com/ossf/scorecard / parseOrgName

Function parseOrgName

cmd/internal/org/org.go:92–127  ·  view source on GitHub ↗

parseOrgName extracts the GitHub organization from a supported input. Supported: - owner > owner - github.com/owner > owner - http://github.com/owner > owner - https://github.com/owner > owner Returns "" if no org can be parsed.

(input string)

Source from the content-addressed store, hash-verified

90//
91// Returns "" if no org can be parsed.
92func parseOrgName(input string) string {
93 s := strings.TrimSpace(input)
94 if s == "" {
95 return ""
96 }
97
98 // Strip optional scheme.
99 switch {
100 case strings.HasPrefix(s, "https://"):
101 s = strings.TrimPrefix(s, "https://")
102 case strings.HasPrefix(s, "http://"):
103 s = strings.TrimPrefix(s, "http://")
104 }
105
106 // If it's exactly the host, there's no org.
107 if s == "github.com" {
108 return ""
109 }
110
111 // Strip host prefix if present.
112 if after, ok := strings.CutPrefix(s, "github.com/"); ok {
113 s = after
114 }
115
116 // Keep only the first path segment (the org).
117 if i := strings.IndexByte(s, '/'); i >= 0 {
118 s = s[:i]
119 }
120
121 // Basic sanity: org shouldn't contain dots (to avoid host-like values).
122 if s == "" || strings.Contains(s, ".") {
123 return ""
124 }
125
126 return s
127}

Callers 2

ListOrgReposFunction · 0.85
TestParseOrgNameFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestParseOrgNameFunction · 0.68