fix(pr/shared): add ParseFullReference func
Signed-off-by: Babak K. Shandiz <babakks@github.com>
This commit is contained in:
parent
9b2ecf4c0e
commit
fd11b1e8de
1 changed files with 25 additions and 0 deletions
|
|
@ -328,6 +328,31 @@ func ParseURL(prURL string) (ghrepo.Interface, int, error) {
|
|||
return repo, prNumber, nil
|
||||
}
|
||||
|
||||
var fullReferenceRE = regexp.MustCompile(`^(?:([^/]+)/([^/]+))#(\d+)$`)
|
||||
|
||||
// ParseFullReference parses a short issue/pull request reference of the form
|
||||
// "owner/repo#number", where owner, repo and number are all required.
|
||||
func ParseFullReference(s string) (ghrepo.Interface, int, error) {
|
||||
if s == "" {
|
||||
return nil, 0, errors.New("empty reference")
|
||||
}
|
||||
|
||||
m := fullReferenceRE.FindStringSubmatch(s)
|
||||
if m == nil {
|
||||
return nil, 0, fmt.Errorf("invalid reference: %q", s)
|
||||
}
|
||||
|
||||
number, err := strconv.Atoi(m[3])
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("invalid reference: %q", number)
|
||||
}
|
||||
|
||||
owner := m[1]
|
||||
repo := m[2]
|
||||
|
||||
return ghrepo.New(owner, repo), number, nil
|
||||
}
|
||||
|
||||
func findByNumber(httpClient *http.Client, repo ghrepo.Interface, number int, fields []string) (*api.PullRequest, error) {
|
||||
type response struct {
|
||||
Repository struct {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue