From 897ded3c54bca0b5bebac8e60df9df51554064c4 Mon Sep 17 00:00:00 2001 From: Denis Gribanov Date: Mon, 23 Feb 2026 23:30:41 +0300 Subject: [PATCH] [AIR-3046] qs: eliminate unused funcs --- gitcmds/gitcmds.go | 140 --------------------------------------------- gitcmds/github.go | 27 --------- 2 files changed, 167 deletions(-) diff --git a/gitcmds/gitcmds.go b/gitcmds/gitcmds.go index 58a6cfc..6a02144 100644 --- a/gitcmds/gitcmds.go +++ b/gitcmds/gitcmds.go @@ -537,141 +537,6 @@ func IsBranchInMain(wd string) (bool, error) { return (parent == org+slash+repo) || (strings.TrimSpace(parent) == ""), err } -// GetMergedBranchList returns merged user's branch list -func GetMergedBranchList(wd string) (brlist []string, err error) { - mbrlist := []string{} - _, org, err := GetRepoAndOrgName(wd) - if err != nil { - return nil, fmt.Errorf("GetRepoAndOrgName failed: %w", err) - } - - repo, err := GetParentRepoName(wd) - if err != nil { - return nil, fmt.Errorf("GetParentRepoName failed: %w", err) - } - - stdout, _, err := new(exec.PipedExec). - Command("gh", "pr", "list", "-L", "200", "--state", "merged", "--author", org, "--repo", repo). - WorkingDir(wd). - Command("gawk", "-F:", "{print $2}"). - Command("gawk", "/MERGED/{print $1}"). - RunToStrings() - if err != nil { - return []string{}, err - } - - mbrlistraw := strings.Split(stdout, caret) - mainBranch, err := GetMainBranch(wd) - if err != nil { - return nil, fmt.Errorf(errMsgFailedToGetMainBranch, err) - } - - curbr, err := GetCurrentBranchName(wd) - if err != nil { - return nil, err - } - - for _, mbranchstr := range mbrlistraw { - arrstr := strings.TrimSpace(mbranchstr) - if (strings.TrimSpace(arrstr) != "") && !strings.Contains(arrstr, curbr) && !strings.Contains(arrstr, mainBranch) { - mbrlist = append(mbrlist, arrstr) - } - } - _, _, err = new(exec.PipedExec). - Command(git, "remote", "prune", origin). - WorkingDir(wd). - RunToStrings() - if err != nil { - return nil, err - } - - stdout, _, err = new(exec.PipedExec). - Command(git, branch, "-r"). - WorkingDir(wd). - RunToStrings() - if err != nil { - return nil, err - } - mybrlist := strings.Split(stdout, caret) - - for _, mybranch := range mybrlist { - mybranch := strings.TrimSpace(mybranch) - mybranch = strings.ReplaceAll(strings.TrimSpace(mybranch), originSlash, "") - mybranch = strings.TrimSpace(mybranch) - bfound := false - if !strings.Contains(mybranch, mainBranch) && !strings.Contains(mybranch, "HEAD") { - for _, mbranch := range mbrlist { - mbranch = strings.ReplaceAll(strings.TrimSpace(mbranch), "MERGED", "") - mbranch = strings.TrimSpace(mbranch) - if mybranch == mbranch { - bfound = true - break - } - } - } - if bfound { - // delete branch in fork - brlist = append(brlist, mybranch) - } - } - - return brlist, nil -} - -// DeleteBranchesRemote delete branch list -func DeleteBranchesRemote(wd string, brs []string) error { - if len(brs) == 0 { - return nil - } - - for _, br := range brs { - err := utils.Retry(func() error { - _, _, deleteErr := new(exec.PipedExec). - Command(git, push, origin, ":"+br). - WorkingDir(wd). - RunToStrings() - return deleteErr - }) - if err != nil { - return fmt.Errorf("branch %s was not deleted: %w", br, err) - } - - fmt.Printf("Branch %s deleted\n", br) - } - - return nil -} - -func PullUpstream(wd string) error { - mainBranch, err := GetMainBranch(wd) - if err != nil { - return fmt.Errorf(errMsgFailedToGetMainBranch, err) - } - - stdout, stderr, err := new(exec.PipedExec). - Command(git, pull, "--ff-only", "upstream", mainBranch, "--no-edit"). - WorkingDir(wd). - RunToStrings() - - if err != nil { - // Check if fast-forward failed - if checkAndShowFastForwardFailure(stderr, mainBranch) { - return fmt.Errorf("cannot fast-forward merge upstream/%s", mainBranch) - } - - // If upstream doesn't exist, try to create it - parentRepoName, err := GetParentRepoName(wd) - if err != nil { - return fmt.Errorf("GetParentRepoName failed: %w", err) - } - - return MakeUpstreamForBranch(wd, parentRepoName) - } - - logger.Verbose(stdout) - return nil -} - func GetNoteAndURL(notes []string) (note string, url string) { for _, s := range notes { s = strings.TrimSpace(s) @@ -844,13 +709,8 @@ func OpenGitRepository(dir string) (*goGitPkg.Repository, error) { DetectDotGit: true, }) if err != nil { - if errors.Is(err, goGitPkg.ErrRepositoryNotExists) { - return nil, errors.New("no .git directory found; please run this command inside a git repository") - } - return nil, fmt.Errorf("failed to open git repository: %w", err) } - return repo, nil } diff --git a/gitcmds/github.go b/gitcmds/github.go index f42acd8..b4a5d8b 100644 --- a/gitcmds/github.go +++ b/gitcmds/github.go @@ -6,7 +6,6 @@ package gitcmds import ( - "encoding/json" "errors" "fmt" "strings" @@ -95,29 +94,3 @@ func GetGithubIssueRepoFromURL(url string) (repoName string) { return } - -func GetGithubIssueNameByNumber(issueNum string, parentrepo string) (string, error) { - stdout, stderr, err := new(exec.PipedExec). - Command("gh", "issue", "view", issueNum, "--repo", parentrepo, "--json", "title"). - RunToStrings() - if err != nil { - logger.Verbose(stderr) - - if len(stderr) > 0 { - return "", errors.New(stderr) - } - - return "", fmt.Errorf("failed to get issue name by number: %w", err) - } - - type issueDetails struct { - Title string `json:"title"` - } - - var issue issueDetails - if err := json.Unmarshal([]byte(stdout), &issue); err != nil { - return "", fmt.Errorf("failed to parse issue title JSON: %w", err) - } - - return issue.Title, nil -}