Skip to content

Commit 09c9fd6

Browse files
improve: Add hint about making GitHub org membership public in error messages
When users try to publish to a GitHub organization but don't have permission, the error message now includes a helpful hint suggesting they may need to make their organization membership public in GitHub settings. This addresses the issue where users couldn't understand why they were unable to publish servers from organization repositories, even when they were members of the organization. Fixes #398 Co-authored-by: adam jones <[email protected]>
1 parent 45bf43f commit 09c9fd6

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

internal/api/handlers/v0/publish.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,48 @@ func buildPermissionErrorMessage(attemptedResource string, permissions []auth.Pe
8484
}
8585
errorMsg += ". Attempting to publish: " + attemptedResource
8686

87+
// Add helpful hint for GitHub organization publishing issues
88+
if strings.HasPrefix(attemptedResource, "io.github.") && !hasPermissionForResource(attemptedResource, permissions) {
89+
// Extract the org name from the resource pattern
90+
parts := strings.Split(attemptedResource, "/")
91+
if len(parts) >= 2 {
92+
namespace := parts[0] // e.g., "io.github.orgname"
93+
if orgName := extractGitHubOrgName(namespace); orgName != "" {
94+
// Check if user has permission for their personal namespace but not this org
95+
hasPersonalPermission := false
96+
for _, perm := range permissions {
97+
if strings.Contains(perm.ResourcePattern, "io.github.") && perm.Action == auth.PermissionActionPublish {
98+
hasPersonalPermission = true
99+
break
100+
}
101+
}
102+
103+
if hasPersonalPermission {
104+
errorMsg += ". If you're trying to publish to a GitHub organization, you may need to make your membership of the '" + orgName + "' organization public in your GitHub settings"
105+
}
106+
}
107+
}
108+
}
109+
87110
return errorMsg
88111
}
112+
113+
// extractGitHubOrgName extracts the organization name from a GitHub namespace
114+
// e.g., "io.github.orgname" -> "orgname"
115+
func extractGitHubOrgName(namespace string) string {
116+
const prefix = "io.github."
117+
if strings.HasPrefix(namespace, prefix) {
118+
return namespace[len(prefix):]
119+
}
120+
return ""
121+
}
122+
123+
// hasPermissionForResource checks if any permission matches the given resource
124+
func hasPermissionForResource(resource string, permissions []auth.Permission) bool {
125+
for _, perm := range permissions {
126+
if perm.Action == auth.PermissionActionPublish && strings.HasPrefix(resource, strings.TrimSuffix(perm.ResourcePattern, "*")) {
127+
return true
128+
}
129+
}
130+
return false
131+
}

0 commit comments

Comments
 (0)