Initial commit
This commit is contained in:
commit
535372dad8
|
@ -0,0 +1,8 @@
|
|||
module gitea_cleaner
|
||||
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
code.gitea.io/sdk/gitea v0.15.0 // indirect
|
||||
github.com/hashicorp/go-version v1.2.1 // indirect
|
||||
)
|
|
@ -0,0 +1,28 @@
|
|||
code.gitea.io/gitea-vet v0.2.1/go.mod h1:zcNbT/aJEmivCAhfmkHOlT645KNOf9W2KnkLgFjGGfE=
|
||||
code.gitea.io/sdk/gitea v0.15.0 h1:tsNhxDM/2N1Ohv1Xq5UWrht/esg0WmtRj4wsHVHriTg=
|
||||
code.gitea.io/sdk/gitea v0.15.0/go.mod h1:klY2LVI3s3NChzIk/MzMn7G1FHrfU7qd63iSMVoHRBA=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pBJ3TkI=
|
||||
github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20200325010219-a49f79bcc224/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
@ -0,0 +1,61 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"bufio"
|
||||
"os"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
)
|
||||
|
||||
func main() {
|
||||
client, _ := gitea.NewClient("_REPO_", gitea.SetToken("_TOKEN_"))
|
||||
|
||||
users_to_delete := []*gitea.User{}
|
||||
|
||||
users, _, _ := client.SearchUsers(gitea.SearchUsersOption{
|
||||
ListOptions: gitea.ListOptions{
|
||||
PageSize: 100,
|
||||
},
|
||||
})
|
||||
|
||||
for _, user := range users {
|
||||
repos, _, _ := client.ListUserRepos( user.UserName, gitea.ListReposOptions{
|
||||
ListOptions: gitea.ListOptions{
|
||||
PageSize: 100,
|
||||
},
|
||||
})
|
||||
orgs, _, _ := client.ListUserOrgs( user.UserName, gitea.ListOrgsOptions{
|
||||
ListOptions: gitea.ListOptions{
|
||||
PageSize: 100,
|
||||
},
|
||||
})
|
||||
all_repos, _, _ := client.SearchRepos( gitea.SearchRepoOptions{
|
||||
ListOptions: gitea.ListOptions{
|
||||
PageSize: 100,
|
||||
},
|
||||
})
|
||||
is_collaborator := false
|
||||
for _, x := range all_repos {
|
||||
result, _, _ := client.IsCollaborator(x.Owner.UserName, x.Name, user.UserName)
|
||||
if result {
|
||||
is_collaborator = true
|
||||
}
|
||||
}
|
||||
|
||||
if user.StarredRepoCount == 0 && len(repos) == 0 && len(orgs) == 0 && !is_collaborator {
|
||||
fmt.Printf("%+v - %+v\n", user.UserName, user.FullName)
|
||||
users_to_delete = append(users_to_delete, user)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Print("These okay to delete? [y/n] ")
|
||||
input := bufio.NewScanner(os.Stdin)
|
||||
input.Scan()
|
||||
fmt.Println(input.Text())
|
||||
|
||||
for _, x := range users_to_delete {
|
||||
client.AdminDeleteUser(x.UserName)
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"bufio"
|
||||
"os"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
)
|
||||
|
||||
var bad_names = []string{"cash_support","tech_advice","techjaadu","cash_app","academic_help","cashapp","cashhelpsapp","robinhood","contactsupport","squarecash","tech_advise","technical_support","technician-help","tech_support","technicalservices","technicalsupport","onlineserviceprovider","cash-operation"}
|
||||
|
||||
func main() {
|
||||
client, _ := gitea.NewClient("_REPO_", gitea.SetToken("_TOKEN_"))
|
||||
|
||||
repos_to_ban := []*gitea.Repository{}
|
||||
|
||||
for _, banned_name := range bad_names {
|
||||
repos, _, _ := client.SearchRepos( gitea.SearchRepoOptions{
|
||||
Keyword: banned_name,
|
||||
ListOptions: gitea.ListOptions{
|
||||
PageSize: 100,
|
||||
},
|
||||
})
|
||||
|
||||
for _, x := range repos {
|
||||
fmt.Printf("%+v - %+v\n", x.Owner.UserName, x.FullName)
|
||||
repos_to_ban = append(repos_to_ban, x)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Print("These okay to delete? [y/n] ")
|
||||
input := bufio.NewScanner(os.Stdin)
|
||||
input.Scan()
|
||||
fmt.Println(input.Text())
|
||||
|
||||
for _, x := range repos_to_ban {
|
||||
client.DeleteRepo(x.Owner.UserName, x.Name)
|
||||
}
|
||||
|
||||
for _, x := range repos_to_ban {
|
||||
client.AdminDeleteUser(x.Owner.UserName)
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue