Skip to content

Commit

Permalink
Merge pull request #62 from xushiwei/q
Browse files Browse the repository at this point in the history
fetcher: githubisstask
  • Loading branch information
xushiwei authored Aug 7, 2024
2 parents 886dd4a + e0db408 commit 7ef487a
Show file tree
Hide file tree
Showing 13 changed files with 228 additions and 18 deletions.
1 change: 1 addition & 0 deletions cmd/hdq/hdq.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/goplus/hdq/cmd/hdq/internal/help"
"github.com/qiniu/x/log"

_ "github.com/goplus/hdq/fetcher/githubisstask"
_ "github.com/goplus/hdq/fetcher/gopkg"
_ "github.com/goplus/hdq/fetcher/hrefs"
_ "github.com/goplus/hdq/fetcher/torch"
Expand Down
Binary file not shown.
77 changes: 77 additions & 0 deletions fetcher/githubisstask/_testdata/gopkgsupport/out.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"issue": "",
"tasks": [
{
"desc": "fmt* (Imported By: 4513111)",
"done": true
},
{
"desc": "time* (Imported By: 2238303)",
"done": true
},
{
"desc": "strings (Imported By: 2104027)",
"done": true
},
{
"desc": "os* (Imported By: 1956039)",
"done": true
},
{
"desc": "context (Imported By: 1460725)",
"done": true
},
{
"desc": "net/http (Imported By: 1415440)",
"done": false
},
{
"desc": "errors (Imported By: 1294097)",
"done": true
},
{
"desc": "io (Imported By: 1268791)",
"done": true
},
{
"desc": "strconv (Imported By: 1206047)",
"done": true
},
{
"desc": "encoding/json (Imported By: 1201739)",
"done": false
},
{
"desc": "log (Imported By: 1117493)",
"done": true
},
{
"desc": "sync* (Imported By: 1075441)",
"done": true
},
{
"desc": "bytes (Imported By: 1021859)",
"done": true
},
{
"desc": "io/ioutil (Imported By: 794650)",
"done": true
},
{
"desc": "reflect* (Imported By: 647872)",
"done": true
},
{
"desc": "path/filepath (Imported By: 541715)",
"done": true
},
{
"desc": "net (Imported By: 538522)",
"done": false
},
{
"desc": "math (Imported By: 502954)",
"done": true
}
]
}
51 changes: 51 additions & 0 deletions fetcher/githubisstask/github_issue_task.gop
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright 2024 The GoPlus Authors (goplus.org)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package githubisstask

import (
"strings"

"github.com/goplus/hdq"
"github.com/goplus/hdq/fetcher"
)

type Task struct {
Desc string `json:"desc"`
Done bool `json:"done"`
}

type Result struct {
Issue string `json:"issue"` // goplus/llgo#642
Tasks []Task `json:"tasks"`
}

// New creates a new Result from a html document.
func New(input any, doc hdq.NodeSet) Result {
issue := input.(string)
taskList := doc.any.ul.class("contains-task-list").one
tasks := [Task{li.text!, li.firstElementChild.hasAttr("checked")} for li <- taskList.child.li]
return {issue, tasks}
}

// URL returns the input URL for the given name.
func URL(input any) string {
issue := input.(string)
return "https://github.com/" + strings.Replace(issue, "#", "/issues/", 1)
}

func init() {
fetcher.Register("githubisstask", New, URL)
}
69 changes: 69 additions & 0 deletions fetcher/githubisstask/gop_autogen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions fetcher/gopkg/gop_autogen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions fetcher/gopkg/gopkg_imps.gop
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ func New(input any, doc hdq.NodeSet) Result {
return {path, importedBy}
}

// URL returns the input URL for the given name.
func URL(name any) string {
return "https://pkg.go.dev/" + name.(string)
// URL returns the input URL for the given input.
func URL(input any) string {
return "https://pkg.go.dev/" + input.(string)
}

func init() {
Expand Down
6 changes: 3 additions & 3 deletions fetcher/hrefs/gop_autogen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions fetcher/hrefs/hrefs.gop
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ func New(input any, doc hdq.NodeSet) Result {
return {input.(string), hrefs}
}

// URL returns the input URL for the given name.
func URL(name any) string {
return name.(string)
// URL returns the input URL for the given input.
func URL(input any) string {
return input.(string)
}

func init() {
Expand Down
6 changes: 3 additions & 3 deletions fetcher/torch/gop_autogen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions fetcher/torch/pysig_torch.gop
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ func New(input any, doc hdq.NodeSet) Result {
return {name, "", "", "<NULL>", url}
}

// URL returns the input URL for the given name.
func URL(name any) string {
return "https://pytorch.org/docs/stable/generated/torch." + name.(string) + ".html"
// URL returns the input URL for the given input.
func URL(input any) string {
return "https://pytorch.org/docs/stable/generated/torch." + input.(string) + ".html"
}

func init() {
Expand Down
7 changes: 7 additions & 0 deletions hdq_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,13 @@ func (p NodeSet) Href__2(exactlyOne bool) (text string, err error) {
return p.AttrVal("href", exactlyOne)
}

// HasAttr returns true if NodeSet has attribute k or not.
func (p NodeSet) HasAttr(k string, exactlyOne ...bool) bool {
_, e := p.AttrVal(k, exactlyOne...)
return e == nil
}

// Attr returns attribute value of NodeSet.
func (p NodeSet) Attr__0(k string, exactlyOne ...bool) (text string, err error) {
return p.AttrVal(k, exactlyOne...)
}
Expand Down
5 changes: 5 additions & 0 deletions hdq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"

"github.com/goplus/hdq"
"github.com/goplus/hdq/fetcher/githubisstask"
"github.com/goplus/hdq/fetcher/gopkg"
"github.com/goplus/hdq/fetcher/torch"
"github.com/goplus/hdq/hdqtest"
Expand Down Expand Up @@ -48,6 +49,10 @@ func TestGoPkg(t *testing.T) {
hdqtest.FromDir(t, "", "./fetcher/gopkg/_testdata", gopkg.New, "data.zip#index.htm", "zip")
}

func TestGithubIssueTask(t *testing.T) {
hdqtest.FromDir(t, "", "./fetcher/githubisstask/_testdata", githubisstask.New, "data.zip#index.htm", "zip")
}

func TestSource(t *testing.T) {
const data = "<html><body>hello</body></html>"
doc := hdq.Source([]byte(data))
Expand Down

0 comments on commit 7ef487a

Please sign in to comment.