parseArtifactURL reads an artifact URL into its repository, issue number and artifact number. Like an issue URL, it may be http, and its query and fragment are ignored: only those three are read from it, and requests go to the API.
(arg string)
| 170 | // fragment are ignored: only those three are read from it, and requests go to |
| 171 | // the API. |
| 172 | func parseArtifactURL(arg string) (ghrepo.Interface, int, int, error) { |
| 173 | invalid := fmt.Errorf("invalid artifact URL: %q", arg) |
| 174 | u, err := url.Parse(arg) |
| 175 | if err != nil || (u.Scheme != "http" && u.Scheme != "https") || u.Hostname() == "" { |
| 176 | return nil, 0, 0, invalid |
| 177 | } |
| 178 | m := artifactURLPath.FindStringSubmatch(u.Path) |
| 179 | if m == nil { |
| 180 | return nil, 0, 0, invalid |
| 181 | } |
| 182 | issueNumber, err := strconv.Atoi(m[3]) |
| 183 | if err != nil || issueNumber < 1 { |
| 184 | return nil, 0, 0, invalid |
| 185 | } |
| 186 | number, err := strconv.Atoi(m[4]) |
| 187 | if err != nil || number < 1 { |
| 188 | return nil, 0, 0, invalid |
| 189 | } |
| 190 | return ghrepo.NewWithHost(m[1], m[2], u.Hostname()), issueNumber, number, nil |
| 191 | } |
| 192 | |
| 193 | // appendNew appends number to numbers, refusing a number already there. |
| 194 | func appendNew(numbers []int, number int) ([]int, error) { |
no test coverage detected