diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 74fa93d..e50e261 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,8 +1,8 @@ { "name": "Tea DevContainer", - "image": "mcr.microsoft.com/devcontainers/go:1.21-bullseye", + "image": "mcr.microsoft.com/devcontainers/go:1.22-bullseye", "features": { - "ghcr.io/devcontainers/features/git-lfs:1.1.0": {} + "ghcr.io/devcontainers/features/git-lfs:1.2.2": {} }, "customizations": { "vscode": { diff --git a/.gitea/issue_template/bug.md b/.gitea/issue_template/bug.md index 3057c94..b75142b 100644 --- a/.gitea/issue_template/bug.md +++ b/.gitea/issue_template/bug.md @@ -8,7 +8,7 @@ labels: ### describe your environment - tea version used (`tea -v`): - - [ ] I also reproduced the issue [with the latest master build](https://dl.gitea.com/tea/main/) + - [ ] I also reproduced the issue [with the latest main build](https://dl.gitea.com/tea/main/) - Gitea version used: - [ ] the issue only occurred after updating gitea recently - operating system: diff --git a/.gitea/workflows/release-nightly.yml b/.gitea/workflows/release-nightly.yml index 66d93e8..7cc076c 100644 --- a/.gitea/workflows/release-nightly.yml +++ b/.gitea/workflows/release-nightly.yml @@ -12,18 +12,17 @@ jobs: with: fetch-depth: 0 - run: git fetch --force --tags - - name: setup go - uses: https://github.com/actions/setup-go@v5 + - uses: actions/setup-go@v5 with: go-version: '>=1.20.1' - name: import gpg id: import_gpg - uses: https://github.com/crazy-max/ghaction-import-gpg@v6 + uses: crazy-max/ghaction-import-gpg@v6 with: gpg_private_key: ${{ secrets.GPGSIGN_KEY }} passphrase: ${{ secrets.GPGSIGN_PASSPHRASE }} - name: goreleaser - uses: https://github.com/goreleaser/goreleaser-action@v5 + uses: goreleaser/goreleaser-action@v6 with: distribution: goreleaser-pro version: latest @@ -37,10 +36,9 @@ jobs: S3_BUCKET: ${{ secrets.AWS_BUCKET }} GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} GPGSIGN_PASSPHRASE: ${{ secrets.GPGSIGN_PASSPHRASE }} + GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }} release-image: runs-on: ubuntu-latest - container: - image: catthehacker/ubuntu:act-latest env: DOCKER_ORG: gitea DOCKER_LATEST: nightly @@ -63,7 +61,7 @@ jobs: password: ${{ secrets.DOCKER_PASSWORD }} - name: Build and push - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 env: ACTIONS_RUNTIME_TOKEN: '' # See https://gitea.com/gitea/act_runner/issues/119 with: diff --git a/.gitea/workflows/release-tag.yml b/.gitea/workflows/release-tag.yml index aac6619..e3d0419 100644 --- a/.gitea/workflows/release-tag.yml +++ b/.gitea/workflows/release-tag.yml @@ -13,19 +13,18 @@ jobs: with: fetch-depth: 0 - run: git fetch --force --tags - - name: setup go - uses: https://github.com/actions/setup-go@v5 + - uses: actions/setup-go@v5 with: - go-version: '>=1.20.1' + go-version-file: 'go.mod' - name: import gpg id: import_gpg - uses: https://github.com/crazy-max/ghaction-import-gpg@v6 + uses: crazy-max/ghaction-import-gpg@v6 with: gpg_private_key: ${{ secrets.GPGSIGN_KEY }} passphrase: ${{ secrets.GPGSIGN_PASSPHRASE }} fingerprint: CC64B1DB67ABBEECAB24B6455FC346329753F4B0 - name: goreleaser - uses: https://github.com/goreleaser/goreleaser-action@v5 + uses: goreleaser/goreleaser-action@v6 with: distribution: goreleaser-pro version: latest diff --git a/.gitea/workflows/test-pr.yml b/.gitea/workflows/test-pr.yml index 94a3682..b552f0a 100644 --- a/.gitea/workflows/test-pr.yml +++ b/.gitea/workflows/test-pr.yml @@ -1,7 +1,6 @@ name: check-and-test -on: - - push +on: - pull_request jobs: @@ -9,10 +8,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: setup go - uses: https://github.com/actions/setup-go@v5 + - uses: actions/setup-go@v5 with: - go-version: '>=1.20.1' + go-version-file: 'go.mod' - name: lint and build run: | make clean diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 8feeb4c..e5fc422 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -96,9 +96,7 @@ checksum: extra_files: - glob: ./**.xz -env_files: - # override gitea actions which passes GITHUB_TOKEN to set env var as null - github_token: /dev/null +force_token: gitea signs: - diff --git a/LICENSE b/LICENSE index a8d4b49..f4b69a7 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,4 @@ Copyright (c) 2016 The Gitea Authors -Copyright (c) 2015 The Gogs Authors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 79e468c..a69c627 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ [![Release](https://raster.shields.io/badge/dynamic/json.svg?label=release&url=https://gitea.com/api/v1/repos/gitea/tea/releases&query=$[0].tag_name)](https://gitea.com/gitea/tea/releases) [![Join the chat at https://img.shields.io/discord/322538954119184384.svg](https://img.shields.io/discord/322538954119184384.svg)](https://discord.gg/Gitea) [![Go Report Card](https://goreportcard.com/badge/code.gitea.io/tea)](https://goreportcard.com/report/code.gitea.io/tea) [![GoDoc](https://pkg.go.dev/badge/code.gitea.io/tea?status.svg)](https://godoc.org/code.gitea.io/tea) +![Tea Release Status](https://gitea.com/gitea/tea/actions/workflows/release-nightly.yml/badge.svg) ## The official CLI for Gitea @@ -28,15 +29,16 @@ COMMANDS help, h Shows a list of commands or help for one command ENTITIES: - issues, issue, i List, create and update issues - pulls, pull, pr Manage and checkout pull requests - labels, label Manage issue labels - milestones, milestone, ms List and create milestones - releases, release, r Manage releases - times, time, t Operate on tracked times of a repository's issues & pulls - organizations, organization, org List, create, delete organizations - repos, repo Show repository details - comment, c Add a comment to an issue / pr + issues, issue, i List, create and update issues + pulls, pull, pr Manage and checkout pull requests + labels, label Manage issue labels + milestones, milestone, ms List and create milestones + releases, release, r Manage releases + release assets, release asset, r a Manage release attachments + times, time, t Operate on tracked times of a repository's issues & pulls + organizations, organization, org List, create, delete organizations + repos, repo Show repository details + comment, c Add a comment to an issue / pr HELPERS: open, o Open something of the repository in web browser notifications, notification, n Show notifications diff --git a/cmd/attachments.go b/cmd/attachments.go new file mode 100644 index 0000000..0e2ff77 --- /dev/null +++ b/cmd/attachments.go @@ -0,0 +1,28 @@ +// Copyright 2024 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package cmd + +import ( + "code.gitea.io/tea/cmd/attachments" + "code.gitea.io/tea/cmd/flags" + + "github.com/urfave/cli/v2" +) + +// CmdReleaseAttachments represents a release attachment (file attachment) +var CmdReleaseAttachments = cli.Command{ + Name: "assets", + Aliases: []string{"asset", "a"}, + Category: catEntities, + Usage: "Manage release assets", + Description: "Manage release assets", + ArgsUsage: " ", // command does not accept arguments + Action: attachments.RunReleaseAttachmentList, + Subcommands: []*cli.Command{ + &attachments.CmdReleaseAttachmentList, + &attachments.CmdReleaseAttachmentCreate, + &attachments.CmdReleaseAttachmentDelete, + }, + Flags: flags.AllDefaultFlags, +} diff --git a/cmd/attachments/create.go b/cmd/attachments/create.go new file mode 100644 index 0000000..84ec30a --- /dev/null +++ b/cmd/attachments/create.go @@ -0,0 +1,64 @@ +// Copyright 2024 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package attachments + +import ( + "fmt" + "os" + "path/filepath" + + "code.gitea.io/tea/cmd/flags" + "code.gitea.io/tea/modules/context" + + "github.com/urfave/cli/v2" +) + +// CmdReleaseAttachmentCreate represents a sub command of Release Attachments to create a release attachment +var CmdReleaseAttachmentCreate = cli.Command{ + Name: "create", + Aliases: []string{"c"}, + Usage: "Create one or more release attachments", + Description: `Create one or more release attachments`, + ArgsUsage: " [...]", + Action: runReleaseAttachmentCreate, + Flags: flags.AllDefaultFlags, +} + +func runReleaseAttachmentCreate(cmd *cli.Context) error { + ctx := context.InitCommand(cmd) + ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) + client := ctx.Login.Client() + + if ctx.Args().Len() < 2 { + return fmt.Errorf("No release tag or assets specified.\nUsage:\t%s", ctx.Command.UsageText) + } + + tag := ctx.Args().First() + if len(tag) == 0 { + return fmt.Errorf("Release tag needed to create attachment") + } + + release, err := getReleaseByTag(ctx.Owner, ctx.Repo, tag, client) + if err != nil { + return err + } + + for _, asset := range ctx.Args().Slice()[1:] { + var file *os.File + if file, err = os.Open(asset); err != nil { + return err + } + + filePath := filepath.Base(asset) + + if _, _, err = ctx.Login.Client().CreateReleaseAttachment(ctx.Owner, ctx.Repo, release.ID, file, filePath); err != nil { + file.Close() + return err + } + + file.Close() + } + + return nil +} diff --git a/cmd/attachments/delete.go b/cmd/attachments/delete.go new file mode 100644 index 0000000..0287297 --- /dev/null +++ b/cmd/attachments/delete.go @@ -0,0 +1,100 @@ +// Copyright 2024 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package attachments + +import ( + "fmt" + + "code.gitea.io/tea/cmd/flags" + "code.gitea.io/tea/modules/context" + + "code.gitea.io/sdk/gitea" + "github.com/urfave/cli/v2" +) + +// CmdReleaseAttachmentDelete represents a sub command of Release Attachments to delete a release attachment +var CmdReleaseAttachmentDelete = cli.Command{ + Name: "delete", + Aliases: []string{"rm"}, + Usage: "Delete one or more release attachments", + Description: `Delete one or more release attachments`, + ArgsUsage: " [...]", + Action: runReleaseAttachmentDelete, + Flags: append([]cli.Flag{ + &cli.BoolFlag{ + Name: "confirm", + Aliases: []string{"y"}, + Usage: "Confirm deletion (required)", + }, + }, flags.AllDefaultFlags...), +} + +func runReleaseAttachmentDelete(cmd *cli.Context) error { + ctx := context.InitCommand(cmd) + ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) + client := ctx.Login.Client() + + if ctx.Args().Len() < 2 { + return fmt.Errorf("No release tag or attachment names specified.\nUsage:\t%s", ctx.Command.UsageText) + } + + tag := ctx.Args().First() + if len(tag) == 0 { + return fmt.Errorf("Release tag needed to delete attachment") + } + + if !ctx.Bool("confirm") { + fmt.Println("Are you sure? Please confirm with -y or --confirm.") + return nil + } + + release, err := getReleaseByTag(ctx.Owner, ctx.Repo, tag, client) + if err != nil { + return err + } + + existing, _, err := client.ListReleaseAttachments(ctx.Owner, ctx.Repo, release.ID, gitea.ListReleaseAttachmentsOptions{ + ListOptions: gitea.ListOptions{Page: -1}, + }) + if err != nil { + return err + } + + for _, name := range ctx.Args().Slice()[1:] { + var attachment *gitea.Attachment + for _, a := range existing { + if a.Name == name { + attachment = a + } + } + if attachment == nil { + return fmt.Errorf("Release does not have attachment named '%s'", name) + } + + _, err = client.DeleteReleaseAttachment(ctx.Owner, ctx.Repo, release.ID, attachment.ID) + if err != nil { + return err + } + } + + return nil +} + +func getReleaseAttachmentByName(owner, repo string, release int64, name string, client *gitea.Client) (*gitea.Attachment, error) { + al, _, err := client.ListReleaseAttachments(owner, repo, release, gitea.ListReleaseAttachmentsOptions{ + ListOptions: gitea.ListOptions{Page: -1}, + }) + if err != nil { + return nil, err + } + if len(al) == 0 { + return nil, fmt.Errorf("Release does not have any attachments") + } + for _, a := range al { + if a.Name == name { + return a, nil + } + } + return nil, fmt.Errorf("Attachment does not exist") +} diff --git a/cmd/attachments/list.go b/cmd/attachments/list.go new file mode 100644 index 0000000..8808763 --- /dev/null +++ b/cmd/attachments/list.go @@ -0,0 +1,74 @@ +// Copyright 2024 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package attachments + +import ( + "fmt" + + "code.gitea.io/tea/cmd/flags" + "code.gitea.io/tea/modules/context" + "code.gitea.io/tea/modules/print" + + "code.gitea.io/sdk/gitea" + "github.com/urfave/cli/v2" +) + +// CmdReleaseAttachmentList represents a sub command of release attachment to list release attachments +var CmdReleaseAttachmentList = cli.Command{ + Name: "list", + Aliases: []string{"ls"}, + Usage: "List Release Attachments", + Description: "List Release Attachments", + ArgsUsage: "", // command does not accept arguments + Action: RunReleaseAttachmentList, + Flags: append([]cli.Flag{ + &flags.PaginationPageFlag, + &flags.PaginationLimitFlag, + }, flags.AllDefaultFlags...), +} + +// RunReleaseAttachmentList list release attachments +func RunReleaseAttachmentList(cmd *cli.Context) error { + ctx := context.InitCommand(cmd) + ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) + client := ctx.Login.Client() + + tag := ctx.Args().First() + if len(tag) == 0 { + return fmt.Errorf("Release tag needed to list attachments") + } + + release, err := getReleaseByTag(ctx.Owner, ctx.Repo, tag, client) + if err != nil { + return err + } + + attachments, _, err := ctx.Login.Client().ListReleaseAttachments(ctx.Owner, ctx.Repo, release.ID, gitea.ListReleaseAttachmentsOptions{ + ListOptions: ctx.GetListOptions(), + }) + if err != nil { + return err + } + + print.ReleaseAttachmentsList(attachments, ctx.Output) + return nil +} + +func getReleaseByTag(owner, repo, tag string, client *gitea.Client) (*gitea.Release, error) { + rl, _, err := client.ListReleases(owner, repo, gitea.ListReleasesOptions{ + ListOptions: gitea.ListOptions{Page: -1}, + }) + if err != nil { + return nil, err + } + if len(rl) == 0 { + return nil, fmt.Errorf("Repo does not have any release") + } + for _, r := range rl { + if r.TagName == tag { + return r, nil + } + } + return nil, fmt.Errorf("Release tag does not exist") +} diff --git a/cmd/branches.go b/cmd/branches.go new file mode 100644 index 0000000..31edee6 --- /dev/null +++ b/cmd/branches.go @@ -0,0 +1,36 @@ +// Copyright 2024 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package cmd + +import ( + "code.gitea.io/tea/cmd/branches" + + "github.com/urfave/cli/v2" +) + +// CmdBranches represents to login a gitea server. +var CmdBranches = cli.Command{ + Name: "branches", + Aliases: []string{"branch", "b"}, + Category: catEntities, + Usage: "Consult branches", + Description: `Lists branches when called without argument. If a branch is provided, will show it in detail.`, + ArgsUsage: "[]", + Action: runBranches, + Subcommands: []*cli.Command{ + &branches.CmdBranchesList, + &branches.CmdBranchesProtect, + &branches.CmdBranchesUnprotect, + }, + Flags: append([]cli.Flag{ + &cli.BoolFlag{ + Name: "comments", + Usage: "Whether to display comments (will prompt if not provided & run interactively)", + }, + }, branches.CmdBranchesList.Flags...), +} + +func runBranches(ctx *cli.Context) error { + return branches.RunBranchesList(ctx) +} diff --git a/cmd/branches/list.go b/cmd/branches/list.go new file mode 100644 index 0000000..7d9cf46 --- /dev/null +++ b/cmd/branches/list.go @@ -0,0 +1,73 @@ +// Copyright 2024 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package branches + +import ( + "code.gitea.io/tea/cmd/flags" + "code.gitea.io/tea/modules/context" + "code.gitea.io/tea/modules/print" + + "code.gitea.io/sdk/gitea" + "github.com/urfave/cli/v2" +) + +var branchFieldsFlag = flags.FieldsFlag(print.BranchFields, []string{ + "name", "protected", "user-can-merge", "user-can-push", +}) + +// CmdBranchesListFlags Flags for command list +var CmdBranchesListFlags = append([]cli.Flag{ + branchFieldsFlag, + &flags.PaginationPageFlag, + &flags.PaginationLimitFlag, +}, flags.AllDefaultFlags...) + +// CmdBranchesList represents a sub command of branches to list branches +var CmdBranchesList = cli.Command{ + Name: "list", + Aliases: []string{"ls"}, + Usage: "List branches of the repository", + Description: `List branches of the repository`, + ArgsUsage: " ", // command does not accept arguments + Action: RunBranchesList, + Flags: CmdBranchesListFlags, +} + +// RunBranchesList list branches +func RunBranchesList(cmd *cli.Context) error { + ctx := context.InitCommand(cmd) + ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) + + owner := ctx.Owner + if ctx.IsSet("owner") { + owner = ctx.String("owner") + } + + var branches []*gitea.Branch + var protections []*gitea.BranchProtection + var err error + branches, _, err = ctx.Login.Client().ListRepoBranches(owner, ctx.Repo, gitea.ListRepoBranchesOptions{ + ListOptions: ctx.GetListOptions(), + }) + + if err != nil { + return err + } + + protections, _, err = ctx.Login.Client().ListBranchProtections(owner, ctx.Repo, gitea.ListBranchProtectionsOptions{ + ListOptions: ctx.GetListOptions(), + }) + + if err != nil { + return err + } + + fields, err := branchFieldsFlag.GetValues(cmd) + if err != nil { + return err + } + + print.BranchesList(branches, protections, ctx.Output, fields) + return nil +} diff --git a/cmd/branches/protect.go b/cmd/branches/protect.go new file mode 100644 index 0000000..1883709 --- /dev/null +++ b/cmd/branches/protect.go @@ -0,0 +1,101 @@ +// Copyright 2024 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package branches + +import ( + "fmt" + + "code.gitea.io/tea/cmd/flags" + "code.gitea.io/tea/modules/context" + + "code.gitea.io/sdk/gitea" + "github.com/urfave/cli/v2" +) + +// CmdBranchesProtectFlags Flags for command protect/unprotect +var CmdBranchesProtectFlags = append([]cli.Flag{ + branchFieldsFlag, + &flags.PaginationPageFlag, + &flags.PaginationLimitFlag, +}, flags.AllDefaultFlags...) + +// CmdBranchesProtect represents a sub command of branches to protect a branch +var CmdBranchesProtect = cli.Command{ + Name: "protect", + Aliases: []string{"P"}, + Usage: "Protect branches", + Description: `Block actions push/merge on specified branches`, + ArgsUsage: "", + Action: RunBranchesProtect, + Flags: CmdBranchesProtectFlags, +} + +// CmdBranchesUnprotect represents a sub command of branches to protect a branch +var CmdBranchesUnprotect = cli.Command{ + Name: "unprotect", + Aliases: []string{"U"}, + Usage: "Unprotect branches", + Description: `Suppress existing protections on specified branches`, + ArgsUsage: "", + Action: RunBranchesProtect, + Flags: CmdBranchesProtectFlags, +} + +// RunBranchesProtect function to protect/unprotect a list of branches +func RunBranchesProtect(cmd *cli.Context) error { + ctx := context.InitCommand(cmd) + ctx.Ensure(context.CtxRequirement{RemoteRepo: true}) + + if !cmd.Args().Present() { + return fmt.Errorf("must specify at least one branch") + } + + owner := ctx.Owner + if ctx.IsSet("owner") { + owner = ctx.String("owner") + } + + for _, branch := range ctx.Args().Slice() { + + var err error + command := ctx.Command.Name + if command == "protect" { + _, _, err = ctx.Login.Client().CreateBranchProtection(owner, ctx.Repo, gitea.CreateBranchProtectionOption{ + BranchName: branch, + RuleName: "", + EnablePush: false, + EnablePushWhitelist: false, + PushWhitelistUsernames: []string{}, + PushWhitelistTeams: []string{}, + PushWhitelistDeployKeys: false, + EnableMergeWhitelist: false, + MergeWhitelistUsernames: []string{}, + MergeWhitelistTeams: []string{}, + EnableStatusCheck: false, + StatusCheckContexts: []string{}, + RequiredApprovals: 1, + EnableApprovalsWhitelist: false, + ApprovalsWhitelistUsernames: []string{}, + ApprovalsWhitelistTeams: []string{}, + BlockOnRejectedReviews: false, + BlockOnOfficialReviewRequests: false, + BlockOnOutdatedBranch: false, + DismissStaleApprovals: false, + RequireSignedCommits: false, + ProtectedFilePatterns: "", + UnprotectedFilePatterns: "", + }) + } else if command == "unprotect" { + _, err = ctx.Login.Client().DeleteBranchProtection(owner, ctx.Repo, branch) + } else { + return fmt.Errorf("command %s is not supported", command) + } + + if err != nil { + return err + } + } + + return nil +} diff --git a/cmd/releases.go b/cmd/releases.go index f19fc08..f0190ed 100644 --- a/cmd/releases.go +++ b/cmd/releases.go @@ -25,6 +25,7 @@ var CmdReleases = cli.Command{ &releases.CmdReleaseCreate, &releases.CmdReleaseDelete, &releases.CmdReleaseEdit, + &CmdReleaseAttachments, }, Flags: flags.AllDefaultFlags, } diff --git a/cmd/repos.go b/cmd/repos.go index 8bd274a..1482c47 100644 --- a/cmd/repos.go +++ b/cmd/repos.go @@ -29,6 +29,7 @@ var CmdRepos = cli.Command{ &repos.CmdRepoCreateFromTemplate, &repos.CmdRepoFork, &repos.CmdRepoMigrate, + &repos.CmdRepoRm, }, Flags: repos.CmdReposListFlags, } diff --git a/cmd/repos/delete.go b/cmd/repos/delete.go new file mode 100644 index 0000000..93b5bae --- /dev/null +++ b/cmd/repos/delete.go @@ -0,0 +1,85 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package repos + +import ( + "fmt" + + "code.gitea.io/tea/cmd/flags" + "code.gitea.io/tea/modules/context" + + "github.com/AlecAivazis/survey/v2" + "github.com/urfave/cli/v2" +) + +// CmdRepoRm represents a sub command of repos to delete an existing repo +var CmdRepoRm = cli.Command{ + Name: "delete", + Aliases: []string{"rm"}, + Usage: "Delete an existing repository", + Description: "Removes a repository from Create a repository from an existing repo", + ArgsUsage: " ", // command does not accept arguments + Action: runRepoDelete, + Flags: append([]cli.Flag{ + &cli.StringFlag{ + Name: "name", + Aliases: []string{""}, + Required: true, + Usage: "name of the repo", + }, + &cli.StringFlag{ + Name: "owner", + Aliases: []string{"O"}, + Required: false, + Usage: "owner of the repo", + }, + &cli.BoolFlag{ + Name: "force", + Aliases: []string{"f"}, + Required: false, + Value: false, + Usage: "Force the deletion and don't ask for confirmation", + }, + }, flags.LoginOutputFlags...), +} + +func runRepoDelete(cmd *cli.Context) error { + ctx := context.InitCommand(cmd) + + client := ctx.Login.Client() + + var owner string + if ctx.IsSet("owner") { + owner = ctx.String("owner") + + } else { + owner = ctx.Login.User + } + + repoName := ctx.String("name") + + repoSlug := fmt.Sprintf("%s/%s", owner, repoName) + + if !ctx.Bool("force") { + var enteredRepoSlug string + promptRepoName := &survey.Input{ + Message: fmt.Sprintf("Confirm the deletion of the repository '%s' by typing its name: ", repoSlug), + } + if err := survey.AskOne(promptRepoName, &enteredRepoSlug, survey.WithValidator(survey.Required)); err != nil { + return err + } + + if enteredRepoSlug != repoSlug { + return fmt.Errorf("Entered wrong repository name '%s', expected '%s'", enteredRepoSlug, repoSlug) + } + } + + _, err := client.DeleteRepo(owner, repoName) + if err != nil { + return err + } + + fmt.Printf("Successfully deleted %s/%s\n", owner, repoName) + return nil +} diff --git a/docs/CLI.md b/docs/CLI.md index aa3da52..49d87cd 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -789,6 +789,60 @@ Edit one or more releases **--title, -t**="": Change Title +### assets, asset, a + +Manage release assets + +**--login, -l**="": Use a different Gitea Login. Optional + +**--output, -o**="": Output format. (simple, table, csv, tsv, yaml, json) + +**--remote, -R**="": Discover Gitea login from remote. Optional + +**--repo, -r**="": Override local repository path or gitea repository slug to interact with. Optional + +#### list, ls + +List Release Attachments + +**--limit, --lm**="": specify limit of items per page + +**--login, -l**="": Use a different Gitea Login. Optional + +**--output, -o**="": Output format. (simple, table, csv, tsv, yaml, json) + +**--page, -p**="": specify page, default is 1 + +**--remote, -R**="": Discover Gitea login from remote. Optional + +**--repo, -r**="": Override local repository path or gitea repository slug to interact with. Optional + +#### create, c + +Create one or more release attachments + +**--login, -l**="": Use a different Gitea Login. Optional + +**--output, -o**="": Output format. (simple, table, csv, tsv, yaml, json) + +**--remote, -R**="": Discover Gitea login from remote. Optional + +**--repo, -r**="": Override local repository path or gitea repository slug to interact with. Optional + +#### delete, rm + +Delete one or more release attachments + +**--confirm, -y**: Confirm deletion (required) + +**--login, -l**="": Use a different Gitea Login. Optional + +**--output, -o**="": Output format. (simple, table, csv, tsv, yaml, json) + +**--remote, -R**="": Discover Gitea login from remote. Optional + +**--repo, -r**="": Override local repository path or gitea repository slug to interact with. Optional + ## times, time, t Operate on tracked times of a repository's issues & pulls @@ -1119,6 +1173,102 @@ Migrate a repository **--wiki**: Copy the wiki +### delete, rm + +Delete an existing repository + +**--force, -f**: Force the deletion and don't ask for confirmation + +**--login, -l**="": Use a different Gitea Login. Optional + +**--name, -**="": name of the repo + +**--output, -o**="": Output format. (simple, table, csv, tsv, yaml, json) + +**--owner, -O**="": owner of the repo + +## branches, branch, b + +Consult branches + +**--comments**: Whether to display comments (will prompt if not provided & run interactively) + +**--fields, -f**="": Comma-separated list of fields to print. Available values: + name,protected,user-can-merge,user-can-push,protection + (default: name,protected,user-can-merge,user-can-push) + +**--limit, --lm**="": specify limit of items per page + +**--login, -l**="": Use a different Gitea Login. Optional + +**--output, -o**="": Output format. (simple, table, csv, tsv, yaml, json) + +**--page, -p**="": specify page, default is 1 + +**--remote, -R**="": Discover Gitea login from remote. Optional + +**--repo, -r**="": Override local repository path or gitea repository slug to interact with. Optional + +### list, ls + +List branches of the repository + +**--fields, -f**="": Comma-separated list of fields to print. Available values: + name,protected,user-can-merge,user-can-push,protection + (default: name,protected,user-can-merge,user-can-push) + +**--limit, --lm**="": specify limit of items per page + +**--login, -l**="": Use a different Gitea Login. Optional + +**--output, -o**="": Output format. (simple, table, csv, tsv, yaml, json) + +**--page, -p**="": specify page, default is 1 + +**--remote, -R**="": Discover Gitea login from remote. Optional + +**--repo, -r**="": Override local repository path or gitea repository slug to interact with. Optional + +### protect, P + +Protect branches + +**--fields, -f**="": Comma-separated list of fields to print. Available values: + name,protected,user-can-merge,user-can-push,protection + (default: name,protected,user-can-merge,user-can-push) + +**--limit, --lm**="": specify limit of items per page + +**--login, -l**="": Use a different Gitea Login. Optional + +**--output, -o**="": Output format. (simple, table, csv, tsv, yaml, json) + +**--page, -p**="": specify page, default is 1 + +**--remote, -R**="": Discover Gitea login from remote. Optional + +**--repo, -r**="": Override local repository path or gitea repository slug to interact with. Optional + +### unprotect, U + +Unprotect branches + +**--fields, -f**="": Comma-separated list of fields to print. Available values: + name,protected,user-can-merge,user-can-push,protection + (default: name,protected,user-can-merge,user-can-push) + +**--limit, --lm**="": specify limit of items per page + +**--login, -l**="": Use a different Gitea Login. Optional + +**--output, -o**="": Output format. (simple, table, csv, tsv, yaml, json) + +**--page, -p**="": specify page, default is 1 + +**--remote, -R**="": Discover Gitea login from remote. Optional + +**--repo, -r**="": Override local repository path or gitea repository slug to interact with. Optional + ## comment, c Add a comment to an issue / pr diff --git a/go.mod b/go.mod index bd622b3..db7118c 100644 --- a/go.mod +++ b/go.mod @@ -4,33 +4,34 @@ go 1.20 require ( code.gitea.io/gitea-vet v0.2.3 - code.gitea.io/sdk/gitea v0.17.1 + code.gitea.io/sdk/gitea v0.18.0 gitea.com/noerw/unidiff-comments v0.0.0-20220822113322-50f4daa0e35c github.com/AlecAivazis/survey/v2 v2.3.7 - github.com/adrg/xdg v0.4.0 + github.com/adrg/xdg v0.5.0 github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de - github.com/charmbracelet/glamour v0.6.0 + github.com/charmbracelet/glamour v0.7.0 github.com/enescakir/emoji v1.0.0 - github.com/go-git/go-git/v5 v5.11.0 + github.com/go-git/go-git/v5 v5.12.0 github.com/muesli/termenv v0.15.2 github.com/olekukonko/tablewriter v0.0.5 github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 - github.com/stretchr/testify v1.8.4 + github.com/stretchr/testify v1.9.0 github.com/urfave/cli/v2 v2.25.7 - golang.org/x/crypto v0.21.0 - golang.org/x/term v0.18.0 + golang.org/x/crypto v0.25.0 + golang.org/x/term v0.22.0 gopkg.in/yaml.v3 v3.0.1 ) require ( dario.cat/mergo v1.0.0 // indirect github.com/Microsoft/go-winio v0.6.1 // indirect - github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect + github.com/ProtonMail/go-crypto v1.0.0 // indirect github.com/acomagu/bufpipe v1.0.4 // indirect github.com/alecthomas/chroma v0.10.0 // indirect + github.com/alecthomas/chroma/v2 v2.8.0 // indirect github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/aymerick/douceur v0.2.0 // indirect - github.com/cloudflare/circl v1.3.3 // indirect + github.com/cloudflare/circl v1.3.7 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/cyphar/filepath-securejoin v0.2.4 // indirect github.com/davecgh/go-spew v1.1.1 // indirect @@ -51,22 +52,23 @@ require ( github.com/mattn/go-isatty v0.0.18 // indirect github.com/mattn/go-runewidth v0.0.14 // indirect github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect - github.com/microcosm-cc/bluemonday v1.0.21 // indirect + github.com/microcosm-cc/bluemonday v1.0.25 // indirect github.com/muesli/reflow v0.3.0 // indirect github.com/pjbgf/sha1cd v0.3.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rivo/uniseg v0.4.2 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/sergi/go-diff v1.2.0 // indirect - github.com/skeema/knownhosts v1.2.1 // indirect + github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect + github.com/skeema/knownhosts v1.2.2 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect - github.com/yuin/goldmark v1.5.2 // indirect - github.com/yuin/goldmark-emoji v1.0.1 // indirect - golang.org/x/mod v0.12.0 // indirect - golang.org/x/net v0.21.0 // indirect - golang.org/x/sys v0.18.0 // indirect - golang.org/x/text v0.14.0 // indirect - golang.org/x/tools v0.13.0 // indirect + github.com/yuin/goldmark v1.5.4 // indirect + github.com/yuin/goldmark-emoji v1.0.2 // indirect + golang.org/x/mod v0.17.0 // indirect + golang.org/x/net v0.25.0 // indirect + golang.org/x/sync v0.7.0 // indirect + golang.org/x/sys v0.22.0 // indirect + golang.org/x/text v0.16.0 // indirect + golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect gopkg.in/warnings.v0 v0.1.2 // indirect ) diff --git a/go.sum b/go.sum index adba1b6..c781650 100644 --- a/go.sum +++ b/go.sum @@ -6,6 +6,8 @@ code.gitea.io/sdk/gitea v0.17.0 h1:8JPBss4+Jf7AE1YcfyiGrngTXE8dFSG3si/bypsTH34= code.gitea.io/sdk/gitea v0.17.0/go.mod h1:ndkDk99BnfiUCCYEUhpNzi0lpmApXlwRFqClBlOlEBg= code.gitea.io/sdk/gitea v0.17.1 h1:3jCPOG2ojbl8AcfaUCRYLT5MUcBMFwS0OSK2mA5Zok8= code.gitea.io/sdk/gitea v0.17.1/go.mod h1:aCnBqhHpoEWA180gMbaCtdX9Pl6BWBAuuP2miadoTNM= +code.gitea.io/sdk/gitea v0.18.0 h1:+zZrwVmujIrgobt6wVBWCqITz6bn1aBjnCUHmpZrerI= +code.gitea.io/sdk/gitea v0.18.0/go.mod h1:IG9xZJoltDNeDSW0qiF2Vqx5orMWa7OhVWrjvrd5NpI= dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= gitea.com/noerw/unidiff-comments v0.0.0-20220822113322-50f4daa0e35c h1:8fTkq2UaVkLHZCF+iB4wTxINmVAToe2geZGayk9LMbA= @@ -19,12 +21,18 @@ github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63n github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w= github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 h1:kkhsdkhsCvIsutKu5zLMgWtgh9YxGCNAw8Ad8hjwfYg= github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= +github.com/ProtonMail/go-crypto v1.0.0 h1:LRuvITjQWX+WIfr930YHG2HNfjR1uOfyf5vE0kC2U78= +github.com/ProtonMail/go-crypto v1.0.0/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ= github.com/acomagu/bufpipe v1.0.4/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4= github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls= github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E= +github.com/adrg/xdg v0.5.0 h1:dDaZvhMXatArP1NPHhnfaQUqWBLBsmx1h1HXQdMoFCY= +github.com/adrg/xdg v0.5.0/go.mod h1:dDdY4M4DF9Rjy4kHPeNL+ilVF+p2lK8IdM9/rTSGcI4= github.com/alecthomas/chroma v0.10.0 h1:7XDcGkCQopCNKjZHfYrNLraA+M7e0fMiJ/Mfikbfjek= github.com/alecthomas/chroma v0.10.0/go.mod h1:jtJATyUxlIORhUOFNA9NZDWGAQ8wpxQQqNSB4rjA/1s= +github.com/alecthomas/chroma/v2 v2.8.0 h1:w9WJUjFFmHHB2e8mRpL9jjy3alYDlU0QLDezj1xE264= +github.com/alecthomas/chroma/v2 v2.8.0/go.mod h1:yrkMI9807G1ROx13fhe1v6PN2DDeaR73L3d+1nmYQtw= github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de h1:FxWPpzIjnTlhPwqqXc4/vE0f7GvRjuAsbW+HOIe8KnA= github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de/go.mod h1:DCaWoUhZrYW9p1lxo/cm8EmUOOzAPSEZNGF2DK1dJgw= @@ -37,8 +45,12 @@ github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd3 github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= github.com/charmbracelet/glamour v0.6.0 h1:wi8fse3Y7nfcabbbDuwolqTqMQPMnVPeZhDM273bISc= github.com/charmbracelet/glamour v0.6.0/go.mod h1:taqWV4swIMMbWALc0m7AfE9JkPSU8om2538k9ITBxOc= +github.com/charmbracelet/glamour v0.7.0 h1:2BtKGZ4iVJCDfMF229EzbeR1QRKLWztO9dMtjmqZSng= +github.com/charmbracelet/glamour v0.7.0/go.mod h1:jUMh5MeihljJPQbJ/wf4ldw2+yBP59+ctV36jASy7ps= github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs= github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= +github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU= +github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI= @@ -72,6 +84,8 @@ github.com/go-git/go-git/v5 v5.10.0 h1:F0x3xXrAWmhwtzoCokU4IMPcBdncG+HAAqi9FcOOj github.com/go-git/go-git/v5 v5.10.0/go.mod h1:1FOZ/pQnqw24ghP2n7cunVl0ON55BsjPYvhWHvZGhoo= github.com/go-git/go-git/v5 v5.11.0 h1:XIZc1p+8YzypNr34itUfSvYJcv+eYdTnTvOZ2vD3cA4= github.com/go-git/go-git/v5 v5.11.0/go.mod h1:6GFcX2P3NM7FPBfpePbpLd21XxsgdAt+lKqXmCUiUCY= +github.com/go-git/go-git/v5 v5.12.0 h1:7Md+ndsjrzZxbddRDZjF14qK+NN56sy6wkqaVrjZtys= +github.com/go-git/go-git/v5 v5.12.0/go.mod h1:FTM9VKtnI2m65hNI/TenDDDnUf2Q9FHnXYjuz9i5OEY= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= @@ -114,6 +128,8 @@ github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQ github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE= github.com/microcosm-cc/bluemonday v1.0.21 h1:dNH3e4PSyE4vNX+KlRGHT5KrSvjeUkoNPwEORjffHJg= github.com/microcosm-cc/bluemonday v1.0.21/go.mod h1:ytNkv4RrDrLJ2pqlsSI46O6IVXmZOBBD4SaJyDwwTkM= +github.com/microcosm-cc/bluemonday v1.0.25 h1:4NEwSfiJ+Wva0VxN5B8OwMicaJvD8r9tlJWm9rtloEg= +github.com/microcosm-cc/bluemonday v1.0.25/go.mod h1:ZIOjCQp1OrzBBPIJmfX4qDYFuhU02nx4bn030ixfHLE= github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s= github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8= github.com/muesli/termenv v0.13.0/go.mod h1:sP1+uffeLaEYpyOTb8pLCUctGcGLnoFjSn4YJK5e2bc= @@ -140,11 +156,15 @@ github.com/seletskiy/tplutil v0.0.0-20200921103632-f880f6245597 h1:nZY1S2jo+VtDr github.com/seletskiy/tplutil v0.0.0-20200921103632-f880f6245597/go.mod h1:F8CBHSOjnzjx9EeXyWJTAzJyVxN+Y8JH2WjLMn4utiw= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= +github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8= +github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/skeema/knownhosts v1.2.0 h1:h9r9cf0+u7wSE+M183ZtMGgOJKiL96brpaz5ekfJCpM= github.com/skeema/knownhosts v1.2.0/go.mod h1:g4fPeYpque7P0xefxtGzV81ihjC8sX2IqpAoNkjxbMo= github.com/skeema/knownhosts v1.2.1 h1:SHWdIUa82uGZz+F+47k8SY4QhhI291cXCpopT1lK2AQ= github.com/skeema/knownhosts v1.2.1/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo= +github.com/skeema/knownhosts v1.2.2 h1:Iug2P4fLmDw9f41PB6thxUkNUkJzB5i+1/exaj40L3A= +github.com/skeema/knownhosts v1.2.2/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo= github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 h1:JIAuq3EEf9cgbU6AtGPK4CTG3Zf6CKMNqf0MHTggAUA= github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -154,6 +174,8 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs= github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= @@ -162,11 +184,16 @@ github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRT github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.3.7/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/goldmark v1.5.2 h1:ALmeCk/px5FSm1MAcFBAsVKZjDuMVj8Tm7FFIlMJnqU= github.com/yuin/goldmark v1.5.2/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +github.com/yuin/goldmark v1.5.4 h1:2uY/xC0roWy8IBEGLgB1ywIoEJFGmRrX21YQcvGZzjU= +github.com/yuin/goldmark v1.5.4/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/goldmark-emoji v1.0.1 h1:ctuWEyzGBwiucEqxzwe0SOYDXPAucOrE9NQC18Wa1os= github.com/yuin/goldmark-emoji v1.0.1/go.mod h1:2w1E6FEWLcDQkoTE+7HU6QF1F6SLlNGjRIBbIZQFqkQ= +github.com/yuin/goldmark-emoji v1.0.2 h1:c/RgTShNgHTtc6xdz2KKI74jJr6rWi7FPgnP9GAsO5s= +github.com/yuin/goldmark-emoji v1.0.2/go.mod h1:RhP/RWpexdp+KHs7ghKnifRoIs/Bq4nDS7tRbCkOwKY= 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/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -190,11 +217,19 @@ golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo= golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= +golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= +golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= +golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= +golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= +golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= +golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= 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= @@ -214,11 +249,17 @@ golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= +golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= +golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= 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/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -252,6 +293,14 @@ golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= +golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= +golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= @@ -272,6 +321,14 @@ golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U= golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8= golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= +golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q= +golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk= +golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw= +golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= +golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA= +golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0= +golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk= +golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -284,6 +341,10 @@ golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 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= @@ -291,6 +352,8 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= 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= @@ -301,6 +364,7 @@ gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main.go b/main.go index 240452b..d5c3f1d 100644 --- a/main.go +++ b/main.go @@ -48,6 +48,7 @@ func main() { &cmd.CmdTrackedTimes, &cmd.CmdOrgs, &cmd.CmdRepos, + &cmd.CmdBranches, &cmd.CmdAddComment, &cmd.CmdOpen, diff --git a/modules/print/attachment.go b/modules/print/attachment.go new file mode 100644 index 0000000..91fe5f3 --- /dev/null +++ b/modules/print/attachment.go @@ -0,0 +1,25 @@ +// Copyright 2024 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package print + +import ( + "code.gitea.io/sdk/gitea" +) + +// ReleaseAttachmentsList prints a listing of release attachments +func ReleaseAttachmentsList(attachments []*gitea.Attachment, output string) { + t := tableWithHeader( + "Name", + "Size", + ) + + for _, attachment := range attachments { + t.addRow( + attachment.Name, + formatSize(attachment.Size), + ) + } + + t.print(output) +} diff --git a/modules/print/branch.go b/modules/print/branch.go new file mode 100644 index 0000000..1375a30 --- /dev/null +++ b/modules/print/branch.go @@ -0,0 +1,86 @@ +// Copyright 2024 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package print + +import ( + "fmt" + + "code.gitea.io/sdk/gitea" +) + +// BranchesList prints a listing of the branches +func BranchesList(branches []*gitea.Branch, protections []*gitea.BranchProtection, output string, fields []string) { + fmt.Println(fields) + printables := make([]printable, len(branches)) + + for i, branch := range branches { + var protection *gitea.BranchProtection + for _, p := range protections { + if p.BranchName == branch.Name { + protection = p + } + } + printables[i] = &printableBranch{branch, protection} + } + + t := tableFromItems(fields, printables, isMachineReadable(output)) + t.print(output) +} + +type printableBranch struct { + branch *gitea.Branch + protection *gitea.BranchProtection +} + +func (x printableBranch) FormatField(field string, machineReadable bool) string { + switch field { + case "name": + return x.branch.Name + case "protected": + return fmt.Sprintf("%t", x.branch.Protected) + case "user-can-merge": + return fmt.Sprintf("%t", x.branch.UserCanMerge) + case "user-can-push": + return fmt.Sprintf("%t", x.branch.UserCanPush) + case "protection": + if x.protection != nil { + approving := "" + for _, entry := range x.protection.ApprovalsWhitelistTeams { + approving += entry + "/" + } + for _, entry := range x.protection.ApprovalsWhitelistUsernames { + approving += entry + "/" + } + merging := "" + for _, entry := range x.protection.MergeWhitelistTeams { + approving += entry + "/" + } + for _, entry := range x.protection.MergeWhitelistUsernames { + approving += entry + "/" + } + pushing := "" + for _, entry := range x.protection.PushWhitelistTeams { + approving += entry + "/" + } + for _, entry := range x.protection.PushWhitelistUsernames { + approving += entry + "/" + } + return fmt.Sprintf( + "- enable-push: %t\n- approving: %s\n- merging: %s\n- pushing: %s\n", + x.protection.EnablePush, approving, merging, pushing, + ) + } + return "" + } + return "" +} + +// BranchFields are all available fields to print with BranchesList() +var BranchFields = []string{ + "name", + "protected", + "user-can-merge", + "user-can-push", + "protection", +}