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

Commit

Permalink
modules/doc/github: fix find revision in page
Browse files Browse the repository at this point in the history
  • Loading branch information
unknwon committed May 27, 2018
1 parent 3c105d8 commit 74ee40a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
build:
go install -v
cp '$(GOPATH)/bin/gowalker' .
cp '$(GOPATH)/bin/gowalker' .

web: build
./gowalker
2 changes: 1 addition & 1 deletion gowalker.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"github.com/Unknwon/gowalker/routers/apiv1"
)

const APP_VER = "1.9.6.0627"
const APP_VER = "1.9.7.0527"

func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
Expand Down
12 changes: 6 additions & 6 deletions modules/doc/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,26 @@ import (

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

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

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

type RepoInfo struct {
Expand Down

0 comments on commit 74ee40a

Please sign in to comment.