Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use id to access orgs #1873

Merged
merged 65 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
d307bc2
change to org-id
anbraten Jun 19, 2023
2158c80
Merge remote-tracking branch 'upstream/master' into org-id
anbraten Jun 27, 2023
1c0a7b2
add org model
anbraten Jul 1, 2023
daf2d67
add store calls
anbraten Jul 6, 2023
244b090
Merge remote-tracking branch 'upstream/master' into org-id
anbraten Jul 6, 2023
9dff5d4
extend store and repo creation
anbraten Jul 7, 2023
cf84ec8
next
anbraten Jul 9, 2023
386b894
nits
anbraten Jul 9, 2023
4744273
support user-orgs
anbraten Jul 9, 2023
e0232f9
fix secret loading
anbraten Jul 9, 2023
cbcd825
Merge remote-tracking branch 'upstream/master' into org-id
anbraten Jul 9, 2023
984c782
implement forge functions
anbraten Jul 9, 2023
ea35fa9
adjust ui
anbraten Jul 9, 2023
d69a8bb
adjust permissions
anbraten Jul 9, 2023
6862950
nits
anbraten Jul 9, 2023
4543f55
add migration
anbraten Jul 9, 2023
7317b88
Merge branch 'master' into org-id
anbraten Jul 9, 2023
66aebb4
Merge branch 'org-id' of github.com:anbraten/woodpecker into org-id
anbraten Jul 9, 2023
ebfb9a8
adjust cli
anbraten Jul 9, 2023
7cec087
fix test
anbraten Jul 9, 2023
629e337
update swagger
anbraten Jul 9, 2023
f0dbdaa
fix web tests
anbraten Jul 9, 2023
e5d0767
sync repo first
anbraten Jul 9, 2023
025fac7
Merge branch 'master' into org-id
anbraten Jul 9, 2023
eaf7788
Merge branch 'master' into org-id
anbraten Jul 10, 2023
5f2e9a8
Merge branch 'master' into org-id
6543 Jul 10, 2023
cbb60fe
Merge branch 'master' into org-id
6543 Jul 10, 2023
e4c3246
fix migration
6543 Jul 10, 2023
9d76b5f
fix migration for real
6543 Jul 10, 2023
0aae927
cleanup migration
anbraten Jul 11, 2023
4e9e020
Merge branch 'org-id' of github.com:anbraten/woodpecker into org-id
anbraten Jul 11, 2023
6fa65b0
fix org insert into map
6543 Jul 10, 2023
02b437c
rename OrgFind to OrgGet
6543 Jul 11, 2023
528902b
explizite org get
6543 Jul 11, 2023
2662933
explizite
6543 Jul 11, 2023
fff31de
Merge branch 'master' into org-id
6543 Jul 11, 2023
b726a96
Merge branch 'main' into org-id
6543 Jul 12, 2023
f38b35a
Merge branch 'main' into org-id
6543 Jul 14, 2023
424fba2
Merge branch 'main' into org-id
6543 Jul 14, 2023
9b10575
Merge branch 'main' into org-id
6543 Jul 16, 2023
e9a81f5
xorm: make sure name is unique
6543 Jul 16, 2023
c33d467
add check for private orgs on lookup
6543 Jul 16, 2023
4a77439
more nits
6543 Jul 16, 2023
f1df4c4
more nits
6543 Jul 16, 2023
8424225
make sure no old orgs table exist
6543 Jul 16, 2023
44481da
fix migration by drop index&constraint on secret_owner first
6543 Jul 16, 2023
06028f2
for visibility dont check of org.IsUser ans just check by name
6543 Jul 16, 2023
d422127
adopt org to user
6543 Jul 16, 2023
c341c94
handle existing users in migration
6543 Jul 16, 2023
6df7d49
more text for errors
6543 Jul 16, 2023
e07c6fa
Merge branch 'main' into org-id
6543 Jul 16, 2023
76f19d4
fix
6543 Jul 16, 2023
10425d9
fix model and handle names case-insensitive
6543 Jul 16, 2023
12efab7
Merge branch 'main' into org-id
6543 Jul 17, 2023
038fa37
handle org name always lowercase
6543 Jul 17, 2023
326a972
add tests for new store funcs and fix OrgRepoList
6543 Jul 17, 2023
f99de94
fix license header .. see git blame
6543 Jul 17, 2023
6ffdadb
Update server/store/datastore/org_test.go
6543 Jul 17, 2023
693ad1a
fix lint
6543 Jul 17, 2023
99b3588
Merge branch 'main' into org-id
6543 Jul 17, 2023
0e0eccf
Merge branch 'main' into org-id
6543 Jul 17, 2023
90f97f5
Merge branch 'main' into org-id
6543 Jul 17, 2023
4db9c94
Merge branch 'main' into org-id
6543 Jul 18, 2023
215079f
Merge branch 'main' into org-id
6543 Jul 20, 2023
c2208e4
return 404
6543 Jul 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cli/common/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,9 @@ var RepoFlag = &cli.StringFlag{
Aliases: []string{"repo"},
Usage: "repository id or full-name (e.g. 134 or octocat/hello-world)",
}

var OrgFlag = &cli.StringFlag{
Name: "organization",
Aliases: []string{"org"},
Usage: "organization id or full-name (e.g. 123 or octocat)",
}
37 changes: 28 additions & 9 deletions cli/secret/secret.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package secret

import (
"fmt"
"strconv"
"strings"

"github.com/urfave/cli/v2"
Expand All @@ -24,29 +26,46 @@ var Command = &cli.Command{
},
}

func parseTargetArgs(client woodpecker.Client, c *cli.Context) (global bool, owner string, repoID int64, err error) {
func parseTargetArgs(client woodpecker.Client, c *cli.Context) (global bool, orgID, repoID int64, err error) {
if c.Bool("global") {
return true, "", -1, nil
return true, -1, -1, nil
}

repoIDOrFullName := c.String("repository")
if repoIDOrFullName == "" {
repoIDOrFullName = c.Args().First()
}

orgName := c.String("organization")
if orgName != "" && repoIDOrFullName == "" {
return false, orgName, -1, err
orgIDOrName := c.String("organization")
if orgIDOrName == "" && repoIDOrFullName == "" {
if err := cli.ShowSubcommandHelp(c); err != nil {
return false, -1, -1, err
}

return false, -1, -1, fmt.Errorf("missing arguments")
}

if orgIDOrName != "" && repoIDOrFullName == "" {
if orgID, err := strconv.ParseInt(orgIDOrName, 10, 64); err == nil {
return false, orgID, -1, nil
}

org, err := client.OrgLookup(orgIDOrName)
if err != nil {
return false, -1, -1, err
}

return false, org.ID, -1, nil
}

if orgName != "" && !strings.Contains(repoIDOrFullName, "/") {
repoIDOrFullName = orgName + "/" + repoIDOrFullName
if orgIDOrName != "" && !strings.Contains(repoIDOrFullName, "/") {
repoIDOrFullName = orgIDOrName + "/" + repoIDOrFullName
}

repoID, err = internal.ParseRepo(client, repoIDOrFullName)
if err != nil {
return false, "", -1, err
return false, -1, -1, err
}

return false, "", repoID, nil
return false, -1, repoID, nil
}
13 changes: 6 additions & 7 deletions cli/secret/secret_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ var secretCreateCmd = &cli.Command{
Name: "global",
Usage: "global secret",
},
&cli.StringFlag{
Name: "organization",
Usage: "organization name (e.g. octocat)",
},
common.OrgFlag,
common.RepoFlag,
&cli.StringFlag{
Name: "name",
Expand Down Expand Up @@ -74,7 +71,7 @@ func secretCreate(c *cli.Context) error {
secret.Value = string(out)
}

global, owner, repoID, err := parseTargetArgs(client, c)
global, orgID, repoID, err := parseTargetArgs(client, c)
if err != nil {
return err
}
Expand All @@ -83,10 +80,12 @@ func secretCreate(c *cli.Context) error {
_, err = client.GlobalSecretCreate(secret)
return err
}
if owner != "" {
_, err = client.OrgSecretCreate(owner, secret)

if orgID != -1 {
_, err = client.OrgSecretCreate(orgID, secret)
return err
}

_, err = client.SecretCreate(repoID, secret)
return err
}
Expand Down
11 changes: 4 additions & 7 deletions cli/secret/secret_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ var secretInfoCmd = &cli.Command{
Name: "global",
Usage: "global secret",
},
&cli.StringFlag{
Name: "organization",
Usage: "organization name (e.g. octocat)",
},
common.OrgFlag,
common.RepoFlag,
&cli.StringFlag{
Name: "name",
Expand All @@ -44,7 +41,7 @@ func secretInfo(c *cli.Context) error {
return err
}

global, owner, repoID, err := parseTargetArgs(client, c)
global, orgID, repoID, err := parseTargetArgs(client, c)
if err != nil {
return err
}
Expand All @@ -55,8 +52,8 @@ func secretInfo(c *cli.Context) error {
if err != nil {
return err
}
} else if owner != "" {
secret, err = client.OrgSecret(owner, secretName)
} else if orgID != -1 {
secret, err = client.OrgSecret(orgID, secretName)
if err != nil {
return err
}
Expand Down
11 changes: 4 additions & 7 deletions cli/secret/secret_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ var secretListCmd = &cli.Command{
Name: "global",
Usage: "global secret",
},
&cli.StringFlag{
Name: "organization",
Usage: "organization name (e.g. octocat)",
},
common.OrgFlag,
common.RepoFlag,
common.FormatFlag(tmplSecretList, true),
),
Expand All @@ -39,7 +36,7 @@ func secretList(c *cli.Context) error {
return err
}

global, owner, repoID, err := parseTargetArgs(client, c)
global, orgID, repoID, err := parseTargetArgs(client, c)
if err != nil {
return err
}
Expand All @@ -50,8 +47,8 @@ func secretList(c *cli.Context) error {
if err != nil {
return err
}
} else if owner != "" {
list, err = client.OrgSecretList(owner)
} else if orgID != -1 {
list, err = client.OrgSecretList(orgID)
if err != nil {
return err
}
Expand Down
11 changes: 4 additions & 7 deletions cli/secret/secret_rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ var secretDeleteCmd = &cli.Command{
Name: "global",
Usage: "global secret",
},
&cli.StringFlag{
Name: "organization",
Usage: "organization name (e.g. octocat)",
},
common.OrgFlag,
common.RepoFlag,
&cli.StringFlag{
Name: "name",
Expand All @@ -37,16 +34,16 @@ func secretDelete(c *cli.Context) error {
return err
}

global, owner, repoID, err := parseTargetArgs(client, c)
global, orgID, repoID, err := parseTargetArgs(client, c)
if err != nil {
return err
}

if global {
return client.GlobalSecretDelete(secretName)
}
if owner != "" {
return client.OrgSecretDelete(owner, secretName)
if orgID != -1 {
return client.OrgSecretDelete(orgID, secretName)
}
return client.SecretDelete(repoID, secretName)
}
11 changes: 4 additions & 7 deletions cli/secret/secret_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ var secretUpdateCmd = &cli.Command{
Name: "global",
Usage: "global secret",
},
&cli.StringFlag{
Name: "organization",
Usage: "organization name (e.g. octocat)",
},
common.OrgFlag,
common.RepoFlag,
&cli.StringFlag{
Name: "name",
Expand Down Expand Up @@ -71,7 +68,7 @@ func secretUpdate(c *cli.Context) error {
secret.Value = string(out)
}

global, owner, repoID, err := parseTargetArgs(client, c)
global, orgID, repoID, err := parseTargetArgs(client, c)
if err != nil {
return err
}
Expand All @@ -80,8 +77,8 @@ func secretUpdate(c *cli.Context) error {
_, err = client.GlobalSecretUpdate(secret)
return err
}
if owner != "" {
_, err = client.OrgSecretUpdate(owner, secret)
if orgID != -1 {
_, err = client.OrgSecretUpdate(orgID, secret)
return err
}
_, err = client.SecretUpdate(repoID, secret)
Expand Down
Loading