mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2026-04-15 01:41:56 +00:00
Merge branch 'origin/main' into 'next-release/main'
This commit is contained in:
@@ -191,7 +191,7 @@ func (c *config) Repo(ctx context.Context, u *model.User, remoteID model.ForgeRe
|
||||
if err != nil {
|
||||
return nil, errors.Join(err, forge_types.ErrRepoNotFound)
|
||||
}
|
||||
perm, err := client.GetPermission(repo.FullName)
|
||||
perm, err := client.GetPermission(owner, repo.FullName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -38,7 +38,6 @@ func Handler() http.Handler {
|
||||
e.GET("/2.0/repositories/:owner", getUserRepos)
|
||||
e.GET("/2.0/user/", getUser)
|
||||
e.GET("/2.0/user/emails", getEmails)
|
||||
e.GET("/2.0/user/permissions/repositories", getPermission)
|
||||
e.GET("/2.0/user/workspaces/:workspace/permissions/repositories", getPermissions)
|
||||
e.GET("/2.0/repositories/:owner/:name/commits/:commit", getBranchHead)
|
||||
e.GET("/2.0/repositories/:owner/:name/pullrequests", getPullRequests)
|
||||
@@ -200,29 +199,35 @@ func getUserRepos(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func getPermission(c *gin.Context) {
|
||||
func getPermissions(c *gin.Context) {
|
||||
workspace := c.Param("workspace")
|
||||
q := c.Query("q")
|
||||
|
||||
if c.Query("page") == "" || c.Query("page") == "1" {
|
||||
switch c.Query("q") {
|
||||
case "repository.full_name=\"test_name/repo_name\"":
|
||||
c.String(http.StatusOK, permissionPayLoad)
|
||||
return
|
||||
case "repository.full_name=\"martinherren1984/publictestrepo\"":
|
||||
c.String(http.StatusOK, permissionHookPayLoad)
|
||||
return
|
||||
switch workspace {
|
||||
case "test_name":
|
||||
// Handle query for specific repo (new GetPermission format)
|
||||
if q == "repository.full_name=\"test_name/repo_name\"" {
|
||||
c.String(http.StatusOK, permissionPayLoad)
|
||||
return
|
||||
}
|
||||
// Handle listing all permissions (ListPermissionsAll)
|
||||
if q == "" {
|
||||
c.String(http.StatusOK, permissionsPayLoad)
|
||||
return
|
||||
}
|
||||
case "martinherren1984":
|
||||
// Handle hook test cases
|
||||
if q == "repository.full_name=\"martinherren1984/publictestrepo\"" {
|
||||
c.String(http.StatusOK, permissionHookPayLoad)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
c.String(http.StatusOK, "{\"values\":[]}")
|
||||
}
|
||||
|
||||
func getPermissions(c *gin.Context) {
|
||||
if (c.Query("page") == "" || c.Query("page") == "1") && c.Param("workspace") == "test_name" {
|
||||
c.String(http.StatusOK, permissionsPayLoad)
|
||||
} else {
|
||||
c.String(http.StatusOK, "{\"values\":[]}")
|
||||
}
|
||||
}
|
||||
|
||||
const tokenPayload = `
|
||||
{
|
||||
"access_token":"2YotnFZFEjr1zCsicMWpAA",
|
||||
|
||||
@@ -32,7 +32,6 @@ import (
|
||||
const (
|
||||
pathUser = "%s/2.0/user/"
|
||||
pathEmails = "%s/2.0/user/emails"
|
||||
pathPermission = "%s/2.0/user/permissions/repositories?q=repository.full_name=%q"
|
||||
pathPermissions = "%s/2.0/user/workspaces/%s/permissions/repositories?%s"
|
||||
pathWorkspaces = "%s/2.0/user/workspaces/?%s"
|
||||
pathWorkspace = "%s/2.0/workspaces/%s"
|
||||
@@ -156,9 +155,9 @@ func (c *Client) CreateStatus(owner, name, revision string, status *PipelineStat
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) GetPermission(fullName string) (*RepoPerm, error) {
|
||||
func (c *Client) GetPermission(owner, fullName string) (*RepoPerm, error) {
|
||||
out := new(RepoPermResp)
|
||||
uri := fmt.Sprintf(pathPermission, c.base, fullName)
|
||||
uri := fmt.Sprintf(pathPermissions, c.base, owner, fmt.Sprintf("q=%s", url.QueryEscape(fmt.Sprintf("repository.full_name=%q", fullName))))
|
||||
_, err := c.do(uri, http.MethodGet, nil, out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user