зеркало из https://github.com/mislav/hub.git
Fix apply to recognize enterprise URLs
This commit is contained in:
Родитель
0c9c9083ff
Коммит
827e1d67d7
|
@ -5,6 +5,8 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
|
||||
"github.com/github/hub/github"
|
||||
)
|
||||
|
||||
var cmdApply = &Command{
|
||||
|
@ -44,44 +46,50 @@ func apply(command *Command, args *Args) {
|
|||
}
|
||||
|
||||
func transformApplyArgs(args *Args) {
|
||||
urlRegexp := regexp.MustCompile("^https?://(gist\\.)?github\\.com/")
|
||||
for _, url := range args.Params {
|
||||
if urlRegexp.MatchString(url) {
|
||||
idx := args.IndexOfParam(url)
|
||||
gist := urlRegexp.FindStringSubmatch(url)[1] == "gist."
|
||||
|
||||
fragmentRegexp := regexp.MustCompile("#.+")
|
||||
url = fragmentRegexp.ReplaceAllString(url, "")
|
||||
pullRegexp := regexp.MustCompile("(/pull/\\d+)/\\w*$")
|
||||
if !gist {
|
||||
if pullRegexp.MatchString(url) {
|
||||
pull := pullRegexp.FindStringSubmatch(url)[1]
|
||||
url = pullRegexp.ReplaceAllString(url, pull)
|
||||
}
|
||||
urlRegexp := regexp.MustCompile("^https?://(gist\\.)github\\.com/")
|
||||
for _, arg := range args.Params {
|
||||
var (
|
||||
url string
|
||||
gist bool
|
||||
)
|
||||
projectURL, err := github.ParseURL(arg)
|
||||
if err == nil {
|
||||
pullRegexp := regexp.MustCompile("/(pull|commit)/([0-9a-f]+)")
|
||||
match := pullRegexp.FindStringSubmatch(projectURL.Path)
|
||||
if match != nil {
|
||||
url = projectURL.Project.WebURL("", "", match[1]+"/"+match[2])
|
||||
}
|
||||
|
||||
var ext string
|
||||
} else {
|
||||
gist = urlRegexp.MatchString(arg)
|
||||
if gist {
|
||||
ext = ".txt"
|
||||
} else {
|
||||
ext = ".patch"
|
||||
url = arg
|
||||
}
|
||||
|
||||
if filepath.Ext(url) != ext {
|
||||
url += ext
|
||||
}
|
||||
|
||||
var prefix string
|
||||
if gist {
|
||||
prefix = "gist-"
|
||||
}
|
||||
|
||||
patchFile := filepath.Join(os.TempDir(), prefix+filepath.Base(url))
|
||||
|
||||
args.Before("curl", "-#LA", fmt.Sprintf("gh %s", Version), url, "-o", patchFile)
|
||||
args.Params[idx] = patchFile
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
if url == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
var ext string
|
||||
if gist {
|
||||
ext = ".txt"
|
||||
} else {
|
||||
ext = ".patch"
|
||||
}
|
||||
|
||||
idx := args.IndexOfParam(arg)
|
||||
if filepath.Ext(url) != ext {
|
||||
url += ext
|
||||
}
|
||||
|
||||
var prefix string
|
||||
if gist {
|
||||
prefix = "gist-"
|
||||
}
|
||||
|
||||
patchFile := filepath.Join(os.TempDir(), prefix+filepath.Base(url))
|
||||
|
||||
args.Before("curl", "-#LA", fmt.Sprintf("gh %s", Version), url, "-o", patchFile)
|
||||
args.Params[idx] = patchFile
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
url="$3"
|
||||
file="$5"
|
||||
|
||||
if [ "${url%.patch}" = "$url" ]; then
|
||||
echo "invalid pull request URL: $url" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cat > "$file" <<OUT
|
||||
From 7eb75a26ee8e402aad79fcf36a4c1461e3ec2592 Mon Sep 17 00:00:00 2001
|
||||
From: Mislav <mislav.marohnic@gmail.com>
|
||||
Date: Tue, 24 Jun 2014 11:07:05 -0700
|
||||
Subject: [PATCH] Create a README
|
||||
---
|
||||
diff --git a/README.md b/README.md
|
||||
new file mode 100644
|
||||
index 0000000..ce01362
|
||||
--- /dev/null
|
||||
+++ b/README.md
|
||||
+hello
|
||||
--
|
||||
1.9.3
|
||||
OUT
|
Загрузка…
Ссылка в новой задаче