| 14 | ) |
| 15 | |
| 16 | func WithPrAndIssueQueryParams(client *api.Client, baseRepo ghrepo.Interface, baseURL string, state IssueMetadataState, projectsV1Support gh.ProjectsV1Support) (string, error) { |
| 17 | u, err := url.Parse(baseURL) |
| 18 | if err != nil { |
| 19 | return "", err |
| 20 | } |
| 21 | q := u.Query() |
| 22 | if state.Title != "" { |
| 23 | q.Set("title", state.Title) |
| 24 | } |
| 25 | // We always want to send the body parameter, even if it's empty, to prevent the web interface from |
| 26 | // applying the default template. Since the user has the option to select a template in the terminal, |
| 27 | // assume that empty body here means that the user either skipped it or erased its contents. |
| 28 | q.Set("body", state.Body) |
| 29 | if len(state.Assignees) > 0 { |
| 30 | q.Set("assignees", strings.Join(state.Assignees, ",")) |
| 31 | } |
| 32 | // Set a template parameter if no body parameter is provided e.g. Web Mode |
| 33 | if len(state.Template) > 0 && len(state.Body) == 0 { |
| 34 | q.Set("template", state.Template) |
| 35 | } |
| 36 | if len(state.Labels) > 0 { |
| 37 | q.Set("labels", strings.Join(state.Labels, ",")) |
| 38 | } |
| 39 | if len(state.ProjectTitles) > 0 { |
| 40 | projectPaths, err := api.ProjectTitlesToPaths(client, baseRepo, state.ProjectTitles, projectsV1Support) |
| 41 | if err != nil { |
| 42 | return "", fmt.Errorf("could not add to project: %w", err) |
| 43 | } |
| 44 | q.Set("projects", strings.Join(projectPaths, ",")) |
| 45 | } |
| 46 | if len(state.Milestones) > 0 { |
| 47 | q.Set("milestone", state.Milestones[0]) |
| 48 | } |
| 49 | |
| 50 | u.RawQuery = q.Encode() |
| 51 | return u.String(), nil |
| 52 | } |
| 53 | |
| 54 | // Maximum length of a URL: 8192 bytes |
| 55 | func ValidURL(urlStr string) bool { |