mirror of
https://github.com/Graylog2/graylog-project-cli.git
synced 2026-03-13 08:02:57 +08:00
Add support for parsing GitHub API PR URLs
This commit is contained in:
@@ -35,7 +35,14 @@ func ParseGitHubPRString(prString string) (string, int, error) {
|
||||
|
||||
var parts []string
|
||||
|
||||
if strings.HasPrefix(strings.ToLower(prString), "https://github.com/") && strings.Contains(prString, "/pull/") {
|
||||
if strings.HasPrefix(strings.ToLower(prString), "https://api.github.com/") && strings.Contains(prString, "/pulls/") {
|
||||
// Input is a PR API URL like this: https://api.github.com/repos/Graylog2/graylog2-server/pulls/9309
|
||||
u, err := neturl.Parse(prString)
|
||||
if err != nil {
|
||||
return "", 0, errors.Wrapf(err, "couldn't parse GitHub pull request API URL <%s>", prString)
|
||||
}
|
||||
parts = strings.SplitN(strings.TrimPrefix(u.Path, "/repos/"), "/pulls/", 2)
|
||||
} else if strings.HasPrefix(strings.ToLower(prString), "https://github.com/") && strings.Contains(prString, "/pull/") {
|
||||
// Input is a PR URL like this: https://github.com/Graylog2/graylog2-server/pull/9692
|
||||
u, err := neturl.Parse(prString)
|
||||
if err != nil {
|
||||
|
||||
@@ -162,6 +162,7 @@ func TestParseGitHubPRString(t *testing.T) {
|
||||
}{
|
||||
{"Graylog2/graylog2-server#123", "Graylog2/graylog2-server", 123, false},
|
||||
{"https://github.com/Graylog2/graylog-plugin-collector/pull/9692", "Graylog2/graylog-plugin-collector", 9692, false},
|
||||
{"https://api.github.com/repos/Graylog2/graylog2-server/pulls/9309", "Graylog2/graylog2-server", 9309, false},
|
||||
{"https://github.com/Graylog2/graylog-plugin-collector/pull/", "", 0, true},
|
||||
{"https://github.com/9692", "", 0, true},
|
||||
{"https://example.com/Graylog2/graylog-plugin-collector/pull/9692", "", 0, true},
|
||||
|
||||
Reference in New Issue
Block a user