Skip to content

Commit 712d96a

Browse files
committed
fix #90: github: contribution: lookup call throw panic; update go-github to v49
1 parent d6fff63 commit 712d96a

File tree

10 files changed

+2592
-3923
lines changed

10 files changed

+2592
-3923
lines changed

Taskfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ set -euo pipefail
1010
declare -A config
1111
config['dryrun']=false
1212

13+
function github() {
14+
_ mod upgrade -t "${1}" --mod-name=github.com/google/go-github/v"$(($1 - 1))"
15+
_ go mod tidy
16+
_ make format
17+
}
18+
1319
_() {
1420
if ${config['dryrun']}; then
1521
echo "${@}"

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/fatih/color v1.13.0
99
github.com/go-git/go-git/v5 v5.4.2
1010
github.com/golang/mock v1.6.0
11-
github.com/google/go-github/v48 v48.2.0
11+
github.com/google/go-github/v49 v49.0.0
1212
github.com/spf13/afero v1.9.3
1313
github.com/spf13/cobra v1.6.1
1414
github.com/spf13/pflag v1.0.5

go.sum

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/command/hub/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"os"
66
"sync"
77

8-
"github.com/google/go-github/v48/github"
8+
"github.com/google/go-github/v49/github"
99
"github.com/spf13/cobra"
1010
"go.octolab.org/async"
1111
"go.octolab.org/safe"

internal/service/github/contribution.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"net/http"
7+
"regexp"
78
"sort"
89
"strconv"
910
"sync"
@@ -102,20 +103,35 @@ func contributionRange(doc *goquery.Document) (int, int) {
102103
}
103104
}
104105

106+
var contributionCount = regexp.MustCompile(`^\d+`)
107+
105108
func contributionHeatMap(doc *goquery.Document) contribution.HeatMap {
106109
chm := make(contribution.HeatMap)
107110
doc.Find("svg.js-calendar-graph-svg rect.ContributionCalendar-day").
108111
Each(func(_ int, node *goquery.Selection) {
109-
count := node.AttrOr("data-count", "")
112+
// data-count="0"
113+
// data-count="2"
114+
count, has := node.Attr("data-count")
115+
if !has {
116+
// No contributions on January 2, 2006
117+
// 2 contributions on January 2, 2006
118+
count = contributionCount.FindString(node.Text())
119+
if count == "" {
120+
count = "0"
121+
}
122+
}
110123
c, err := strconv.Atoi(count)
111124
if err != nil {
112-
panic(fmt.Errorf("invalid count value: %s", count))
125+
html, _ := node.Html()
126+
panic(fmt.Errorf("invalid count value in `%s`: %w", html, err))
113127
}
114128

129+
// data-date="2006-01-02"
115130
date := node.AttrOr("data-date", "")
116131
d, err := time.Parse(xtime.RFC3339Day, date)
117132
if err != nil {
118-
panic(fmt.Errorf("invalid date value: %s", date))
133+
html, _ := node.Html()
134+
panic(fmt.Errorf("invalid date value in `%s`: %w", html, err))
119135
}
120136

121137
chm.SetCount(d, c)

internal/service/github/internal_test.go

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package github
22

33
import (
4+
"context"
5+
"flag"
46
"os"
57
"testing"
68
"time"
@@ -12,8 +14,23 @@ import (
1214
"go.octolab.org/unsafe"
1315
)
1416

17+
var update = flag.Bool("update", false, "update testdata")
18+
1519
func TestContributionRange(t *testing.T) {
16-
f, err := os.Open("testdata/github.kamilsk.1986.html")
20+
const name = "testdata/github.kamilsk.1986.html"
21+
22+
if *update {
23+
d, err := fetchContributions(context.TODO(), "kamilsk", 1986)
24+
require.NoError(t, err)
25+
26+
h, err := d.Html()
27+
require.NoError(t, err)
28+
29+
require.NoError(t, os.Truncate(name, 0))
30+
require.NoError(t, os.WriteFile(name, []byte(h), 0666))
31+
}
32+
33+
f, err := os.Open(name)
1734
require.NoError(t, err)
1835
defer safe.Close(f, unsafe.Ignore)
1936

@@ -22,11 +39,24 @@ func TestContributionRange(t *testing.T) {
2239

2340
min, max := contributionRange(doc)
2441
assert.Equal(t, 2011, min)
25-
assert.Equal(t, 2022, max)
42+
assert.Equal(t, 2023, max)
2643
}
2744

2845
func TestContributionHeatMap(t *testing.T) {
29-
f, err := os.Open("testdata/github.kamilsk.2013.html")
46+
const name = "testdata/github.kamilsk.2013.html"
47+
48+
if *update {
49+
d, err := fetchContributions(context.TODO(), "kamilsk", 2013)
50+
require.NoError(t, err)
51+
52+
h, err := d.Html()
53+
require.NoError(t, err)
54+
55+
require.NoError(t, os.Truncate(name, 0))
56+
require.NoError(t, os.WriteFile(name, []byte(h), 0666))
57+
}
58+
59+
f, err := os.Open(name)
3060
require.NoError(t, err)
3161
defer safe.Close(f, unsafe.Ignore)
3262

internal/service/github/labels.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"embed"
66
"path/filepath"
77

8-
"github.com/google/go-github/v48/github"
8+
"github.com/google/go-github/v49/github"
99
"go.octolab.org/pointer"
1010
"gopkg.in/yaml.v2"
1111

internal/service/github/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package github
33
import (
44
"net/http"
55

6-
"github.com/google/go-github/v48/github"
6+
"github.com/google/go-github/v49/github"
77
)
88

99
// New returns a new GitHub service.

0 commit comments

Comments
 (0)