Skip to content
This repository was archived by the owner on Mar 12, 2022. It is now read-only.

Commit 74ee40a

Browse files
committed
modules/doc/github: fix find revision in page
1 parent 3c105d8 commit 74ee40a

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
build:
22
go install -v
3-
cp '$(GOPATH)/bin/gowalker' .
3+
cp '$(GOPATH)/bin/gowalker' .
4+
5+
web: build
6+
./gowalker

gowalker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
"github.com/Unknwon/gowalker/routers/apiv1"
3434
)
3535

36-
const APP_VER = "1.9.6.0627"
36+
const APP_VER = "1.9.7.0527"
3737

3838
func init() {
3939
runtime.GOMAXPROCS(runtime.NumCPU())

modules/doc/github.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,26 @@ import (
3333

3434
var (
3535
githubRawHeader = http.Header{"Accept": {"application/vnd.github-blob.raw"}}
36-
githubRevisionPattern = regexp.MustCompile(`data-clipboard-text="[a-z0-9A-Z]+`)
36+
githubRevisionPattern = regexp.MustCompile(`value="[a-z0-9A-Z]+"`)
3737
githubPattern = regexp.MustCompile(`^github\.com/(?P<owner>[a-z0-9A-Z_.\-]+)/(?P<repo>[a-z0-9A-Z_.\-]+)(?P<dir>/[a-z0-9A-Z_.\-/]*)?$`)
3838
)
3939

4040
func getGithubRevision(importPath, tag string) (string, error) {
4141
data, err := com.HttpGetBytes(Client, fmt.Sprintf("https://%s/commits/"+tag, importPath), nil)
4242
if err != nil {
43-
return "", fmt.Errorf("fetch revision page: %v", err)
43+
return "", fmt.Errorf("fail to get revision(%s): %v", importPath, err)
4444
}
4545

46-
i := bytes.Index(data, []byte(`btn-outline`))
46+
i := bytes.Index(data, []byte(`commit-links-group BtnGroup`))
4747
if i == -1 {
48-
return "", errors.New("find revision locater: not found")
48+
return "", fmt.Errorf("cannot find locater in page: %s", importPath)
4949
}
5050
data = data[i+1:]
5151
m := githubRevisionPattern.FindSubmatch(data)
5252
if m == nil {
53-
return "", fmt.Errorf("find revision: not found")
53+
return "", fmt.Errorf("cannot find revision in page: %s", importPath)
5454
}
55-
return strings.TrimPrefix(string(m[0]), `data-clipboard-text="`), nil
55+
return strings.TrimSuffix(strings.TrimPrefix(string(m[0]), `value="`), `"`), nil
5656
}
5757

5858
type RepoInfo struct {

0 commit comments

Comments
 (0)