mirror of
				https://gitea.com/gitea/tea.git
				synced 2025-10-31 01:05:26 +01:00 
			
		
		
		
	tea pr create: make local repo optional (#393)
this is a partial fix to #378, making the command available outside of a local repo. new behaviour: - when run interactively without local repo context, the head repo prompt is not pre-populated - when run with flags without local repo context, it will complain unless `--head` is specified refactor: - pass TeaContext down to task.CreatePull Co-authored-by: Norwin <git@nroo.de> Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/393 Reviewed-by: Alexey 〒erentyev <axifive@noreply.gitea.io> Reviewed-by: 6543 <6543@obermui.de> Co-authored-by: Norwin <noerw@noreply.gitea.io> Co-committed-by: Norwin <noerw@noreply.gitea.io>
This commit is contained in:
		| @@ -6,26 +6,23 @@ package interact | ||||
|  | ||||
| import ( | ||||
| 	"code.gitea.io/sdk/gitea" | ||||
| 	"code.gitea.io/tea/modules/config" | ||||
| 	"code.gitea.io/tea/modules/git" | ||||
| 	"code.gitea.io/tea/modules/context" | ||||
| 	"code.gitea.io/tea/modules/task" | ||||
|  | ||||
| 	"github.com/AlecAivazis/survey/v2" | ||||
| ) | ||||
|  | ||||
| // CreatePull interactively creates a PR | ||||
| func CreatePull(login *config.Login, owner, repo string) error { | ||||
| func CreatePull(ctx *context.TeaContext) (err error) { | ||||
| 	var base, head string | ||||
|  | ||||
| 	// owner, repo | ||||
| 	owner, repo, err := promptRepoSlug(owner, repo) | ||||
| 	if err != nil { | ||||
| 	if ctx.Owner, ctx.Repo, err = promptRepoSlug(ctx.Owner, ctx.Repo); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	// base | ||||
| 	base, err = task.GetDefaultPRBase(login, owner, repo) | ||||
| 	if err != nil { | ||||
| 	if base, err = task.GetDefaultPRBase(ctx.Login, ctx.Owner, ctx.Repo); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	promptI := &survey.Input{Message: "Target branch:", Default: base} | ||||
| @@ -34,14 +31,14 @@ func CreatePull(login *config.Login, owner, repo string) error { | ||||
| 	} | ||||
|  | ||||
| 	// head | ||||
| 	localRepo, err := git.RepoForWorkdir() | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	var headOwner, headBranch string | ||||
| 	promptOpts := survey.WithValidator(survey.Required) | ||||
| 	headOwner, headBranch, err := task.GetDefaultPRHead(localRepo) | ||||
| 	if err == nil { | ||||
| 		promptOpts = nil | ||||
|  | ||||
| 	if ctx.LocalRepo != nil { | ||||
| 		headOwner, headBranch, err = task.GetDefaultPRHead(ctx.LocalRepo) | ||||
| 		if err == nil { | ||||
| 			promptOpts = nil | ||||
| 		} | ||||
| 	} | ||||
| 	promptI = &survey.Input{Message: "Source repo owner:", Default: headOwner} | ||||
| 	if err := survey.AskOne(promptI, &headOwner); err != nil { | ||||
| @@ -52,17 +49,15 @@ func CreatePull(login *config.Login, owner, repo string) error { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	head = task.GetHeadSpec(headOwner, headBranch, owner) | ||||
| 	head = task.GetHeadSpec(headOwner, headBranch, ctx.Owner) | ||||
|  | ||||
| 	opts := gitea.CreateIssueOption{Title: task.GetDefaultPRTitle(head)} | ||||
| 	if err = promptIssueProperties(login, owner, repo, &opts); err != nil { | ||||
| 	if err = promptIssueProperties(ctx.Login, ctx.Owner, ctx.Repo, &opts); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	return task.CreatePull( | ||||
| 		login, | ||||
| 		owner, | ||||
| 		repo, | ||||
| 		ctx, | ||||
| 		base, | ||||
| 		head, | ||||
| 		&opts) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Norwin
					Norwin