Skip to content

Commit 93c51b3

Browse files
authored
Merge pull request #327 from masutaka/fix-deprecates
Fix deprecate warnings
2 parents 44fed4e + 3f104cb commit 93c51b3

7 files changed

Lines changed: 42 additions & 32 deletions

File tree

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ $ github-nippou
9999

100100
The following projects use github-nippou as a library:
101101

102-
* https://github.com/ryoppippi/gh-nippou
103-
* gh CLI extension for github-nippou
104102
* https://github.com/MH4GF/github-nippou-web
105103
* A web app version of github-nippou
106104
* https://github.com/NoritakaIkeda/GitJournal

README_ja.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ $ github-nippou
9999

100100
以下のプロジェクトが github-nippou をライブラリとして利用しています:
101101

102-
* https://github.com/ryoppippi/gh-nippou
103-
* github-nippou の gh CLI 拡張
104102
* https://github.com/MH4GF/github-nippou-web
105103
* github-nippou の Web アプリ版
106104
* https://github.com/NoritakaIkeda/GitJournal

lib/events.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,7 @@ func continueToRetrieve(response *github.Response, events []*github.Event, since
5959

6060
lastEvent := *events[len(events)-1]
6161

62-
if lastEvent.CreatedAt.Before(sinceTime.Add(-time.Nanosecond)) {
63-
return false
64-
}
65-
66-
return true
62+
return !lastEvent.CreatedAt.Before(sinceTime.Add(-time.Nanosecond))
6763
}
6864

6965
func selectEventsInRange(events []*github.Event, sinceTime, untilTime time.Time) []*github.Event {
@@ -89,7 +85,12 @@ func (e *Events) filter(events []*github.Event) []*github.Event {
8985
for _, event := range events {
9086
if e.debug {
9187
format := NewFormat(e.ctx, e.client, Settings{}, false)
92-
fmt.Printf("[Debug] %s: %v\n", *event.Type, format.Line(event, 999))
88+
line, err := format.Line(event, 999)
89+
if err != nil {
90+
fmt.Printf("[Debug] %s: parse error %v\n", *event.Type, err)
91+
} else {
92+
fmt.Printf("[Debug] %s: %v\n", *event.Type, line)
93+
}
9394
}
9495

9596
switch *event.Type {

lib/format.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,11 @@ func NewLineByDiscussion(repoName string, discussion github.Discussion) Line {
6868
}
6969

7070
// Line returns Issue/PR info retrieving from GitHub
71-
func (f *Format) Line(event *github.Event, i int) Line {
72-
payload := event.Payload()
71+
func (f *Format) Line(event *github.Event, i int) (Line, error) {
72+
payload, err := event.ParsePayload()
73+
if err != nil {
74+
return Line{}, err
75+
}
7376
var line Line
7477

7578
switch *event.Type {
@@ -139,7 +142,7 @@ func (f *Format) Line(event *github.Event, i int) Line {
139142
fmt.Printf("[Debug] %2d %s: %v\n", i, *event.Type, line)
140143
}
141144

142-
return line
145+
return line, nil
143146
}
144147

145148
func getIssue(ctx context.Context, client *github.Client, repoFullName string, number int) *github.Issue {

lib/format_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ import (
1010

1111
func TestFormatAll(t *testing.T) {
1212
issue := github.Issue{
13-
State: github.String("closed"),
14-
Title: github.String("イベントを取得できないことがある"),
15-
User: &github.User{Login: github.String("masutaka")},
16-
HTMLURL: github.String("https://github.com/masutaka/github-nippou/issues/1"),
13+
State: github.Ptr("closed"),
14+
Title: github.Ptr("イベントを取得できないことがある"),
15+
User: &github.User{Login: github.Ptr("masutaka")},
16+
HTMLURL: github.Ptr("https://github.com/masutaka/github-nippou/issues/1"),
1717
}
1818
pr := github.PullRequest{
19-
State: github.String("closed"),
20-
Title: github.String("Bundle Update on 2015-10-04"),
21-
User: &github.User{Login: github.String("deppbot")},
22-
HTMLURL: github.String("https://github.com/masutaka/github-nippou/pull/31"),
23-
Merged: github.Bool(true),
19+
State: github.Ptr("closed"),
20+
Title: github.Ptr("Bundle Update on 2015-10-04"),
21+
User: &github.User{Login: github.Ptr("deppbot")},
22+
HTMLURL: github.Ptr("https://github.com/masutaka/github-nippou/pull/31"),
23+
Merged: github.Ptr(true),
2424
}
2525
discussion := github.Discussion{
26-
State: github.String("closed"),
27-
Title: github.String("ロードマップ募集"),
28-
User: &github.User{Login: github.String("masutaka")},
29-
HTMLURL: github.String("https://github.com/masutaka/github-nippou/discussions/2"),
26+
State: github.Ptr("closed"),
27+
Title: github.Ptr("ロードマップ募集"),
28+
User: &github.User{Login: github.Ptr("masutaka")},
29+
HTMLURL: github.Ptr("https://github.com/masutaka/github-nippou/discussions/2"),
3030
}
3131
lines := lib.Lines{
3232
lib.NewLineByIssue("masutaka/github-nippou", issue),

lib/list.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,31 @@ func (l *List) Collect() (string, error) {
8686
var lines Lines
8787
var wg sync.WaitGroup
8888
var mu sync.Mutex
89+
var firstErr error
8990

9091
for i, event := range events {
9192
wg.Add(1)
9293
go func(event *github.Event, i int) {
9394
defer wg.Done()
9495
sem <- 1
95-
line := format.Line(event, i)
96+
line, lineErr := format.Line(event, i)
9697
<-sem
9798

9899
mu.Lock()
99100
defer mu.Unlock()
101+
if lineErr != nil {
102+
if firstErr == nil {
103+
firstErr = lineErr
104+
}
105+
return
106+
}
100107
lines = append(lines, line)
101108
}(event, i)
102109
}
103110
wg.Wait()
111+
if firstErr != nil {
112+
return "", firstErr
113+
}
104114

105115
allLines, err := format.All(lines)
106116
if err != nil {

lib/settings.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88
"os"
99
"os/exec"
1010
"strconv"
@@ -144,12 +144,12 @@ func createGist(ctx context.Context, client *github.Client) (*github.Gist, *gith
144144

145145
gistFiles := make(map[github.GistFilename]github.GistFile, 1)
146146
gistFiles["settings.yml"] = github.GistFile{
147-
Content: github.String(content),
147+
Content: github.Ptr(content),
148148
}
149149

150150
gist := &github.Gist{
151-
Description: github.String("github-nippou settings"),
152-
Public: github.Bool(true),
151+
Description: github.Ptr("github-nippou settings"),
152+
Public: github.Ptr(true),
153153
Files: gistFiles,
154154
}
155155

@@ -173,7 +173,7 @@ func getDefaultSettingsYml() (string, error) {
173173

174174
defer file.Close()
175175

176-
yml, err := ioutil.ReadAll(file)
176+
yml, err := io.ReadAll(file)
177177
if err != nil {
178178
return "", err
179179
}

0 commit comments

Comments
 (0)